CS201 Introduction to Programming Current Solved MCQs

CS201 Introduction to Programming Solved MCQs

VU HELP CENTER : 03478749900

Question # 1 of 10 ( Start time: 06:31:50 PM )  Total Marks: 1
if (a>b && a>c) then the condition will be true only if 
Both a>b and a>c are true
 a>b is false and a>c is true
a>b is true and a>c is false
Both a>b and a>c are false

Question # 2 of 10 ( Start time: 06:32:48 PM )  Total Marks: 1
In while loop the loop counter must be initialized, 
With in the loop
 Before entering the loop
 At the end of the loop
None of the given options

Question # 3 of 10 ( Start time: 06:33:15 PM )  Total Marks: 1
__________ of a variable means the locations within a program from where it can be accessed. 
Data type
Visibility
Value
 Reference

Question # 4 of 10 ( Start time: 06:33:49 PM )  Total Marks: 1
Switch support_______________ data.
Integer
Character
Float
Both integer and character

Question # 5 of 10 ( Start time: 06:34:31 PM )  Total Marks: 1
A function is a block of statements that can be defined once and used ________ in the program. 
One time
Two times
Three times
As many times as user wants

Question # 6 of 10 ( Start time: 06:35:13 PM )  Total Marks: 1
_________statement is used to terminate the processing of a particular case and exit from switch structure. 
if
goto
 break
 continue
http://msdn.microsoft.com/en-us/library/wt88dxx6(v=vs.80).aspx

Question # 7 of 10 ( Start time: 06:35:32 PM )  Total Marks: 1
The most suitable data type for number 325.25 is ______. 
char
int
short
 float 

Question # 8 of 10 ( Start time: 06:35:51 PM )  Total Marks: 1
X is an integer variable; what does X++ means, 
Add 1 two times in X value
Add 1 in X value
 Add 2 in X value
None of these

Question # 9 of 10 ( Start time: 06:36:12 PM )  Total Marks: 1
The operators ++ and –- are used to increment or decrement the value of a variable by ________ 
1
 2
3
4

Question # 10 of 10 ( Start time: 06:36:34 PM )  Total Marks: 1
Which of the following loops checks the test condition at the end of the loop?
While
 Do-While
 For
Nested Loop

CS201 Introduction to Programming Solved MCQs

VU HELP CENTER : 03478749900

Question # 1 of 10 ( Start time: 12:31:13 PM )  Total Marks: 1
The result of 4%3 will be 
2
1.5
 1
 1.33

Question # 2 of 10 ( Start time: 12:31:34 PM )  Total Marks: 1
While developing a program; should we think about the user interface? 
 Yes
 No

Question # 3 of 10 ( Start time: 12:32:03 PM )  Total Marks: 1
Which of the following is the right syntax to declare a variable in C++? 
VariableName  Datatype;
DataType = VariableName;
DataType  VariableName;
 (DataType)  VariableName;

Question # 4 of 10 ( Start time: 12:32:30 PM )  Total Marks: 1
What will be the resultant value of this expression x =17%3 ?   
1
2

3
4

Question # 5 of 10 ( Start time: 12:32:50 PM )  Total Marks: 1
What will be the result of the expression k = ++m; if initially k = 0 and m = 5? 
0
5
 6
 4

Question # 6 of 10 ( Start time: 12:33:08 PM )  Total Marks: 1
Function prototype is written, 
Within main function
After the return statement in main
Before the return statement in main
 Before call of that function

Question # 7 of 10 ( Start time: 12:34:02 PM )  Total Marks: 1
Switch statement can be used in place of _________ statement. 
break
continue
 Multiple if
 goto

Question # 8 of 10 ( Start time: 12:34:46 PM )  Total Marks: 1
In while loop the loop counter must be initialized, 
With in the loop
 Before entering the loop
 At the end of the loop
None of the given options

Question # 9 of 10 ( Start time: 12:35:28 PM )  Total Marks: 1
What logical error exists in the following arithmetic expression? X = 50 / ( 2 % 2 ) + 9 
( ) parenthesis are not allowed in expressions
 Division by zero will occur in this expression
 Order of the expression is not according to rules
We can not use % operator in expressions

Question # 10 of 10 ( Start time: 12:36:06 PM )  Total Marks: 1
Loops are _______________ Structure. 
Decision
Sequential
 Repetition pg 560
None of the given options

CS201 Introduction to Programming Solved MCQs

VU HELP CENTER : 03478749900

Question # 1 of 10           Total Marks: 1
< and > both are _________ operators.
Arithmetic
Relational
Logical PG 258
Mathematical

Question # 2 of 10           Total Marks: 1
Find out the logical error in following lines of code. If (x = 10) cout << “x is 10”;
10 should be enclosed in quotations
There is no semicolon at the end of if condition
Assignment operator should not be used for comparison
Variable x should not be inside parenthesis

Question # 3 of 10           Total Marks: 1
What will be the result of the expression j = i++; if initially j = 0 and i = 5?
0
5
6
4

Question # 4 of 10           Total Marks: 1
Default mechanism of calling a function by passing it array is call by ________ and in case of passing variable is call by ________.
Reference, Reference
Reference, value PG154, 119
Value, Reference
Value, Value

Question # 5 of 10           Total Marks: 1
When the break statement is encountered in a loop’s body, it transfers the control ________from the current loop.
Inside
Outside
To break statement
To continue statement

Question # 6 of 10           Total Marks: 1
________statement is used to terminate the processing of a particular case and exit from switch structure.
If
Goto
Break
Continue
http://msdn.microsoft.com/en-us/library/wt88dxx6(v=vs.80).aspx

Question # 7 of 10      Total Marks: 1
When the if statement consists of more than one statement then enclosing these statement in braces is _________.
 Compulsory
 Optional
Not required
Relevant

Question # 8 of 10    Total Marks: 1
What will be the value of the variable output in the given piece of code? double output = 0; output = (2 + 2) * 4 + 2 / (4 – 2);
15
 17
 12
1

Question # 9 of 10   Total Marks: 1
If we assign 2.06721 to an integer variable x, what will be the output if we print x using cout<< statement?
2
2.1
2.06
2.07

Question # 10 of 10      Total Marks: 1
__________ will be used for clarity and to force the order of evaluation in an expression.
 ” ”
 () PG32
 ‘ ‘
[]

CS201 Introduction to Programming Solved MCQs

VU HELP CENTER : 03478749900

The statement cout << yptr will show the __________the yptr points to.
Value
Memory Address
Variabvle
None of given
char **argv can be read as__________________.
Pointer to Pimter
Pointer to Char
Pointer to Pointer to Char  (page 177)
None of given
_______________are conventional names of the command line parameters of the ‘main()’ function.
‘argb’ and ‘argv’
‘argc’ and ‘argv’
‘argc’ and ‘argu’
None of Given
___________ Returns true if c is a digit and false otherwise.
int isalpha( int c )
int isalnum( int c )
int isxdigit( int c )
int isdigit( int c )
In the case of pointer to pointer or _______________, the first pointer contains the address of the second pointer, which contains the address of the variable, which contains the desired value.
double dereference (page 175)
Single dereference
dereference
None of the given
_______________________ contains functions for manipulations of character data.
ctype.h
iostream.h
string.h
None of the given
dereferencing operator is represented by _______
*
+

None of the given
http://www.vuzs.info/

In_________, we try to have a precise problem statement
Analysis
Design
Coding
None of the given

CS201 Introduction to Programming Solved MCQs

VU HELP CENTER : 03478749900

Section 5.2 Essentials of Counter-Controlled Repetition
5.2 Q1: Which of the following does counter-controlled repetition require?
            A condition that tests for the final value.
            Counter-controlled repetition requires all of the above.
            An increment or decrement by which the control variable is modified each time through the loop.
            An initial value.
5.2 Q2: The statement
while ( –counter >= 1 )
counter % 2 ? cout << “A” : cout << “B”;
cannot be rewritten as:
while ( –counter >= 1 )
             if ( counter % 2 )
                                    cout << “A”;
             else
                                    cout << “B”;.
while ( counter >= 1 )
             if ( counter % 2 )
                                    cout << “A”;
             else
                                    cout << “B”;.
             –counter;
while ( –counter >= 1 )
             counter % 2 == 0 ? cout << “B” : cout << “A”;.
while ( counter > 1 )
{
             –counter;
             if ( counter % 2 )
                                    cout << “A”;
             else
                                    cout << “B”;
}.
5.2 Q3: Which of the following is a bad programming practice?
            Using floating-point values for counters in counter-controlled repetition.
            Indenting the statements in the body of each control structure.
            Nesting multiple repetition structures one within another.
            Placing vertical spacing above and below control structures.
Section 5.3 for Repetition Statement
5.3 Q1: If a variable is declared in the initialization expression of a for structure, then:
            It can not be used in any structures that are nested in that for structure.
            It retains its final value after the loop is finished.
            The scope of the variable is restricted to that particular for loop.
            It is automatically reinitialized to zero once the loop is finished.
5.3 Q2: Which of the following is not true?
            The initialization and increment expressions can be comma-separated lists.
            You must declare the control variable outside of the for loop.
            The three expressions in the for structure are optional.
            A for loop can always be used to replace a while loop, and vice versa.
5.3 Q3: Consider the execution of the following for loop
for (int x = 1; x < 5; increment )
             cout << x + 1 << endl;
If the last value printed is 5, which of the following might have been used for increment?
            Any of the above.
            x += 1.
            a. x++.
            ++x.
Section 5.4 Examples Using the for Statement
5.4 Q1: Which of the following for headers is not valid?
            for ( int i = 0; i < 10; i++ ).
            int i = 0;
for ( ; i < 10; i++ ).
            for ( int i = 0; int j = 5; ; i++ ).
            for ( int i = 0: i < 10; ).
A Caution about Using Type double for Monetary Amounts
5.4 Q2: float and double variables should be used:
            To perform monetary calculations.
            To store true/false values.
            As imprecise representations of decimal numbers.
            As counters.
Using Stream Manipulators to Format Numeric Output
5.4 Q3: Which of the following is a parameterized stream manipulator used to format output?
            setw.
            right.
            left.
            fixed.
Section 5.5 do…while Repetition Statement
5.5 Q1: If a do…while structure is used:
            Counter-controlled repetition is not possible.
            The body of the loop will execute at least once.
            An infinite loop will not take place.
            An off-by-one error will not occur.
5.5 Q2: What will the following program segment do?
int counter = 1;
do {
             cout << counter << ” “;
} while ( ++counter <= 10 );
            Cause a syntax error.
            Print the numbers 1 through 11.
            Print the numbers 1 through 9.
            Print the numbers 1 through 10.
Section 5.6 switch Multiple-Selection Statement
5.6 Q1: A switch statement should be used:
            As a multiple-selection structure.
            As a single-selection structure.
            To replace all if and if…else statements.
            As a double-selection structure.
5.6 Q2: In a switch structure:
            A default case is required.
            A break is required after each case.
            A break is required after the default case.
            Multiple actions do not need to be enclosed in braces.
5.6 Q3: Which of the following is correct when labeling cases in a switch structure?
            Case1.
            Case 1.
            case1.
            case 1.
5.6 Q4: switch can be used to test:
            all types of constants.
             int constants.
            string constants.
            float constants.
5.6 Q5: Which of the following data types can be used to represent integers?
            long.
            short.
            char.
            All of the above.
Section 5.7 break and continue Statements
5.7 Q1: Which of the following is          False?
            break statements exit from the loop in which they are embedded.
            continue statements skip the remaining statements in current iteration of the body of the loop in which they are embedded.
            continue and break statements may be embedded within all C++ structures.
            break and continue statements alter the flow of control.
5.7 Q2: Which of the following is          False?
            Many programmers feel that break and continue violate structured programming.
            The effects of break and continue statements can be achieved by structured programming techniques.
            You should always try to write the fastest, smallest code possible before attempting to make it simple and correct.
            break and continue statements can perform faster than their corresponding structured techniques.
Section 5.8 Logical Operators
5.8 Q1: In C++, the condition ( 4 > y > 1 ):
            Evaluates correctly and could be replaced by ( 4 > y && y > 1 ).
            Does not evaluate correctly and should not be replaced by ( 4 > y && y > 1 ).
            Does not evaluate correctly and should be replaced by ( 4 > y && y > 1 ).
            Evaluates correctly and could not be replaced by ( 4 > y && y > 1 ).
5.8 Q2: The OR (||) operator:
            Stops evaluation upon finding one condition to be true.
            Associates from right to left.
            Has higher precedence than the AND (&&) operator.
            Is a ternary operator.
5.8 Q3: An operator that associates from right to left is:
            ().
            !=.
            ?:.
            ,.
5.8 Q4: The expression if ( num != 65 ) cannot be replaced by:
            if ( !( num == 65 ) ).
            if ( num > 65 || num < 65 ).
            d. if ( !( num – 65 ) ).
            if ( num – 65 ).
5.8 Q5: An example of a unary operator is:
            The < relational operator.
            The = assignment operator.
            The % arithmetic operator.
            The ! logical operator.
Section 5.9 Confusing Equality (==) and Assignment (=) Operators
5.9 Q1: Variables are also known as:
            rvalues, and cannot be used as lvalues.
            lvalues, but can be used as rvalues.
            Constant variables.
            lvalues, and cannot be used as rvalues.
5.9 Q2: Consider the following code, assuming that x is an int with an initial value of 12
if( x = 6 )
             cout << x;
What is the output?
            12.
            6.
            A syntax error is produced.
            Nothing.
5.9 Q3: Of the following, which is not a logic error?
             Failing to initialize counter and total variables before the body of a loop.
            Not placing curly braces around the body of an if that contains two statements.
            Using commas instead of the two required semicolons in a for header.
            Using == to assign a value to a variable.

CS201 Introduction to Programming Solved MCQs

VU HELP CENTER : 03478749900

Section 5.10 Structured Programming Summary
5.10 Q1: The ____________, __________ and ____________ are the only three forms of control necessary.
            break, continue, if…else.
            sequence, selection, repetition.
            switch, if, else.
            for, while, do…while.
5.10 Q2: Which of the following is not one of the C++ control structures?
            if.
            switch.
            do…while.
            main.
5.10 Q3: Which of the following is not one the rules for forming structured programs?
            Any action state can be replaced by any control statement.
            Any transition arrow can be reversed.
            Begin with the “simplest activity diagram.”
            Any action state can be replaced by two action states in sequence
Section 5.11 (Optional) Software Engineering Case Study: Identifying Objects’ States and Activities in the ATM System
5.11 Q1: Which of the following is not a part of a UML state diagram?
            A solid circle indicating the initial state.
            Arrows with accompanying event description text representing transitions.
            Rounded rectangles representing states.
            Fractions beside each state indicating the likelihood of entering that state.
5.11 Q2: An activity diagram for modeling the actions involved in executing a balance inquiry transaction using the BalanceInquiry object should not include:
            Retrieving the user’s balance information from the database of accounts.
            All of the above actions should be modeled in this activity diagram.
            Receiving the user’s main menu input indicating a desire to inquire the amount of his or her balance.
            Displaying the user’s balance information on the screen.
Section 10.2 const (Constant) Objects and const Member Functions

10.2 Q1: Which of the following statements will not produce a syntax error?

Defining a const member function that modifies a data member of the object.
Declaring an object to be const.
Declaring a constructor to be const.
Invoking a non-const member function on a const object.
10.2 Q2: The code fragment:
Increment::Increment( int c, int i )
 : increment ( i )
{
 count = c;
}
does not cause any compilation errors. This tells you that:
increment must be a const variable.
count must be a const variable.
increment must be a non-const variable.
count must be a non-const variable.
Section 10.3 Composition: Objects as Members of Classes
10.3 Q1: When composition (one object having another object as a member) is used:
 Member objects are destructed last, in the order they are declared in the host’s class.
 The host object is constructed first and then the member objects are placed into it.
 Member objects are constructed first, in the order they are declared in the host’s class.
 Member objects are constructed first, in the order they appear in the host constructor’s initializer list.
10.3 Q2: An error occurs if:
 A non-reference, non-const, primitive data member is initialized in the member initialization list.
 An object data member is not initialized in the member initialization list and does not have a default constructor.
 An object data member is not initialized in the member initialization list.
 An object data member does not have a default constructor.
Section 10.4 friend Functions and friend Classes
10.4 Q1:
If the line:
friend class A;
appears in class B,and the line:
friend class B;
appears in class C,then:
Class A can access private variables of class B.
Class A is a friend of class C.
Class B can access class A’s private variables.
Class C can call class A’s private member functions.
10.4 Q2: Which of the following is not true about friend functions and friend classes?
 A class can either grant friendship to or take friendship from another class using the friend keyword.
 The friendship relationship is neither symmetric nor transitive.
 A friend of a class can access all of its private data member and member functions.
 A friend declaration can appear anywhere in a class definition.
Section 10.5 Using the this Pointer
10.5 Q1: For a non-constant member function of class Test, the this pointer has type:
const Test *.
Test * const.
const Test * const.
Test const *.
10.5 Q2: Inside a function definition for a member function of an object with data element x, which of the following is not equivalent to this->x:
(* (& (*this) ) ).x.
(*this).x.
*this.x.
 x.
10.5 Q3: Assume that t is an object of class Test, which has member functions a(), b(), c() and d(). If the functions a(), b() and c() all return references to an object of class Test (using the dereferenced this pointer) and function d() is declared void, which of the following statements will not produce a syntax error:
t.a().b().d();.
t.d().c();.
t.a().t.d();.
a().b().t;.

CS201 Introduction to Programming Solved MCQs

VU HELP CENTER : 03478749900

Section 10.6 Dynamic Memory Management with Operators new and delete
10.6 Q1: Which of the following isFalse about the new operator and the object for which it allocates memory?
It automatically destroys the object after main is exited.
It returns a pointer.
It calls the object’s constructor.
It does not require the size of the object to be explicitly specified in the new expression.
10.6 Q2: The delete operator:
Is called implicitly at the end of a program.
Must be told which destructor to call when destroying an object.
Can delete an entire array of objects declared using new.
Can terminate the program.
Section 10.7 static Class Members
10.7 Q1: If Americans are objects of the same class, which of the following attributes would most likely be represented by a static variable of that class?
Age.
Favorite food.
Place of birth.
The President.
10.7 Q2: static data members of a certain class:
Cannot be changed, even by objects of the same that class.
Can be accessed only if an object of that class exists.
Have class scope.
Can only be changed by static member functions.
10.7 Q3: static member functions:
Can be declared const as well.
Can use the this pointer.
Cannot be called until an object of their class is instantiated.
Can only access other static member functions and static data members.
Section 10.8 Data Abstraction and Information Hiding
10.8 Q1: Which of the following is not an abstract data type?
An ASCII character.
A for loop.
An int.
A used-defined class.
10.8 Q2: Which of the following are true about an abstract data type?
I.Captures a data representation.
II.Defines the operations that are allowed on its data.
III.Replaces structured programming.
I and II.
I and III.
I, II and III.
II and III.
Section 10.8.1 Example: Array Abstract Data Type
10.8.1 Q1: Which of the following capabilities do “raw” C++ arrays not provide?
Dynamic size expansion to accommodate more elements.
Array comparison.
Subscript range checking.
“Raw” arrays do not provide any of the above capabilities.
Section 10.8.2 Example: String Abstract Data Type

CS201 Introduction to Programming Solved MCQs

VU HELP CENTER : 03478749900

10.8.2 Q1: Instead of including a string data type among C++’s built-in data types, C++: Was designed to include mechanisms for creating and implementing string abstract data types through classes.

 

 Was designed to include mechanisms for creating and implementing string abstract data types through classes.
 Forces the programmer to make do with char array strings.
 Chose to ignore the need for a string data type.
 None of the above.
Section 10.8.3 Example: Queue Abstract Data Type
10.8.3 Q1: The numbers 3, 2, 5, 7 are enqueued in a queue in that order, then three numbers are dequeued, and finally 3, 7, 9, 4 are enqueued in that order. What is the first number in the queue (the next number to be dequeued)?
3.
7.
9.
4.
Section 10.9 Container Classes and Iterators
10.9 Q1: Which of the following is not a type of container (collection) class?
floats.
Stacks.
Arrays.
Linked lists.
Section 10.10 Proxy Classes
10.10 Q1: Proxy classes are best described as an example of:
Structured programming.
Object-oriented programming (as used in the text).
Information hiding.
Utility functions.
10.10 Q2: In addition to hiding the implementation details that the ordinary method of “separating implementation from interface” would hide, using a proxy class also hides:
The definition of access functions.
The definition of inline functions.
The definition of constructors and the destructor.
The names of private data members.

Section 11.1 Introduction

11.1 Q1: Which of the following is not an operator overloaded by the C++ language?
   www.vuzs.info
            pow.
            >>.
            +.
            <<.

Which of the following is true about streams?

 

A.    It is a sequence of bytes

B.    It is an ordered sequence

C.        All bytes can go through the stream simultaneously

D.    Bytes that enters first into the stream will go out at last

A only

C only

A and B

A and D

Stream is a sequence of bytes. It is an ordered sequence. Let’s compare it with the door example. The person who enters first will go out of the door first. The person who enters behind someone will go out behind that person. Similarly streams are also ordered sequence. The thing that enters first into the stream will go out first. You should think streams as ordered sequence of bytes. Byte is a unit of measure. A byte can store one character, so you can think of an ordered sequence of characters.

Section 11.2 Fundamentals of Operator Overloading
11.2 Q1: To use an operator on user-defined class objects, operator overloading:
            Must never be used, with three exceptions.
            Must never be used.
            Must always be used.
            Must always be used, with three exceptions.
11.2 Q2: The correct function name for overloading the addition (+) operator is:
            operator_+.
            operator:+.
            operator+.
            operator(+).
   www.vuzs.info
Section 11.3 Restrictions on Operator Overloading
11.3 Q1: Which of the following operators cannot be overloaded?
            The . operator.
            The -> operator.
            The [ ] operator.
            The & operator.
11.3 Q2: Which statement about operator overloading is           False?
            New operators can never be created.
            Certain overloaded operators can change the number of arguments they take.
            The precedence of an operator cannot be changed by overloading.
            Overloading cannot change how an operator works on built-in types.
11.3 Q3: To implicitly overload the += operator:
            Only the = operator needs to be overloaded.
            Only the + operator needs to be overloaded.
            The += operator cannot be overloaded implicitly.
            Both the + and = operators need to be overloaded.
   www.vuzs.info
Section 11.4 Operator Functions as Class Members vs. Global Functions
11.4 Q1: Which of the following operators can be overloaded as a global function?
            ().
            ==.
            +=.
            [].
11.4 Q2: Which situation would require the operator to be overloaded as a global function?
            The left most operand must be a class object (or a reference to a class object).
            The left operand is an int.
            The operator returns a reference.
            The overloaded operator is =.
11.4 Q3: An overloaded + operator takes a class object and a double as operands. For it to be commutative (i.e., a + b and b + a both work):
 The + operator cannot be overloaded to be commutative.
 operator+ must be a non-member function.
 operator+ must be a member function of the class from which the objects are instantiated.
 It must be overloaded twice; the operator+ function that takes the object as the left operand must be a member function, and the other operator+ function must be a global function.
   www.vuzs.info
Section 11.5 Overloading Stream Insertion and Stream Extraction Operators
11.5 Q1: Suppose you have a programmer-defined data type Data and want to overload the << operator to output your data type to the screen in the form cout << dataToPrint; and allow cascaded function calls. The first line of the function definition would be:
            ostream &operator<<( const Data &dataToPrint, ostream &output ).
            ostream &operator<<( ostream &output, const Data &dataToPrint ).
            ostream operator<<( ostream &output, const Data &dataToPrint ).
            ostream operator<<( const Data &dataToPrint, ostream &output ).
Section 11.6 Overloading Unary Operators
11.6 Q1: Suppose the unary ! operator is an overloaded member function of class String. For a String object s, which function call is generated by the compiler when it finds the expression !s?
            A compiler error results because no arguments are given.
            operator!( s ).
            s.operator!( default_value1, default_value2,…).
            s.operator!().
Section 11.7 Overloading Binary Operators
11.7 Q1: y and z are user-defined objects and the += operator is an overloaded member function. The operator is overloaded such that y += z adds z and y, then stores the result in y. Which of the following expressions is always equivalent to y += z?
            y.operator+=( z ).
            y = y + z.
            y = y operator+= z.
            y operator+=( y + z ).
11.7 Q2: For operators overloaded as non-static member functions:
            Both binary and unary operators take one argument.
            Neither binary nor unary operators can have arguments.
            Binary operators can have two arguments and unary operators can have one.
            Binary operators can have one argument, and unary operators cannot have any.
Section 11.8 Case Study: Array Class
11.8 Q1: Which of the following is        False?
            Two arrays cannot be meaningfully compared with equality or relational operators.
            C++ ensures that you cannot “walk off” either end of an array.
            An entire non-char array cannot be input or output at once.
            Arrays cannot be assigned to one another (i.e., array1 = array2;).
11.8 Q2: The array subscript operator [], when overloaded, cannot:
            Take multiple values inside (e.g., [4 8]).
            Take a float as an operand.
            Take user-defined objects as operands.
            Be used with linked list classes.
   www.vuzs.info
11.8 Q3: A copy constructor:
            None of the above.
            Is a constructor that takes no arguments.
            Is a constructor with only default arguments.
            Is a constructor that initializes a newly declared object to the value of an existing object of the same class.
11.8 Q4: Copy constructors must receive its argument by reference because:
            The pointer needs to know the address of the original data, not a temporary copy of it.
            The copy of the argument passed by value has function scope.
            Otherwise the constructor will only make a copy of a pointer to an object.
            Otherwise infinite recursion occurs.
11.8 Q5: To prevent class objects from being copied:
            Make the copy constructor private.
            None of the above.
            Make the overloaded assignment operator private.
Both (a) and (b).
Section 11.9 Converting between Types
11.9 Q1: Conversion constructors:
            Can convert between user-defined types.
            Are implicitly defined by the compiler if not explicitly written by the programmer.
            Cannot convert built-in types to user defined types.
            Can have multiple arguments.
11.9 Q2: The prototypes of overloaded cast operator functions do not:
            Specify the type they convert to.
            Need to be defined inside the class whose objects are being converted.
            Specify the type that is being converted.
            Specify a return type.
11.9 Q3: Which of the following lines would be the prototype for an overloaded cast operator function that converts an object of user-defined type Time into a double?
            Time::operator_cast(double) const;.
            Time::static_cast double() const;.
            Time::operator double() const;.
            d. Time::double() const;.
   www.vuzs.info
Section 11.10 Case Study: String Class
11.10 Q1: Conversion constructors cannot:
            Be used to convert the arguments for overloaded operators to the types needed by those overloaded operators.
            Take exactly one argument.
            Be used implicitly in series to match the needs of an overloaded operator.
            Be applied implicitly.
11.10 Q2: Which of the following is not a disadvantage of default memberwise copy with objects containing pointers?
            Having the possibility of leaving a dangling pointer.
            Allowing both objects to point to the same dynamically allocated storage.
            Requiring the explicit overloading of the assignment operator.
            Allowing the destructor of one object to be called while leaving the second pointer, to the same memory location, intact.
11.10 Q3: Assume that the function call operator() is overloaded for data type String in the usual sense of selecting a substring from a larger string. For a String object string1 with the character string “ABCDEFGHI”, what string does string1( 4 , 2 ) return?
            “CDEF”.
            “EF”.
            “CD”.
            “EFGHI”.
Section 11.11 Overloading ++ and —
11.11 Q1: The conventional way to distinguish between the overloaded preincrement and postincrement operators (++) is:
            To assign a dummy value to preincrement.
            To make the argument list of postincrement include an int.
            To have the postincrement operator call the preincrement operator.
            Implicitly done by the compiler.
11.11 Q2: Because the postfix increment operator returns objects by value and the prefix increment operator returns objects by reference:
 The postfix increment operator returns the actual incremented object with its new value.
 The postfix increment operator typically returns a temporary object that contains the original value of the object before the increment occurred.
 Prefix increment has slightly more overhead than postfix increment.
 Objects returned by postfix increment cannot be used in larger expressions.
   www.vuzs.info
Section 11.12 Case Study: A Date Class
11.12 Q1: There exists a data type Date with member function Increment that increments the current Date object by one. The ++ operator is being overloaded to postincrement an object of type Date. Select the correct implementation:
Date Date::operator++( int )
{
             Date temp = *this;
             Increment();
             return *temp;
}.
Date Date::operator++( int )
{
             Increment();
             Date temp = *this;
             return temp;
}.
Date Date::operator++( int )
{
             Date temp = *this;
             return this;
             temp.Increment();
}.
Date Date::operator++( int )
{
             Date temp = *this;
             Increment();
             return temp;
}.
Section 11.13 Standard Library Class string
11.13 Q1: Which of the following is      False?
            b. Class string provides bounds checking in its member function at.
            d. An exception is thrown. if the argument to string’s at member function is an invalid subscript.
            Class string’s overloaded [] operator returns a vector element as an rvalue or an lvalue, depending on the context.
            A string can be defined to store any data type.
 vuzs
Section 11.14 explicit Constructors
11.14 Q1: An explicit constructor:
            Cannot be called outside of the class it is declared in.
            Does not initialize its class’s data members.
            Can be implicitly called by the compiler to perform a data type conversion.
            Must take exactly one argument.

CS201 Introduction to Programming Solved MCQs

VU HELP CENTER : 03478749900

1- Memory allocated from heap or free store _____________________.

Select correct option:

can be returned back to the system automatically

can be allocated to classes only

cannot be returned back unless freed explicitly using malloc and realloc

cannot be returned back unless freed explicitly using free and delete operators

 

 

2- Once the _______________ are created, they exist for the life time of the program

Select correct option:

local variables

non static variables

static variables

automatic variables

 

Once the static variables are created, they exist for the life of the program. They do not die. So returning their reference is all right.3- The members of a class declared with the keyword struct are _____________by default.

Select correct option:

static

private

protected

public.

 

The members of a class declared with the keyword struct are public by default. A structure is inherited publicly by default.

www.vuzs.info

4- If the memory in the free store is not sufficient ____________________.

Select correct option:

malloc function returns 1

malloc function returns 0

malloc functions returns NULL pointer

malloc function returns free space

 

if the memory in the free store is not sufficient enough to fulfill the request. malloc() function returns NULL pointer if the memory is not enough. In C++, is returned instead of NULL pointer.

5. This reference to a variable can be obtained by preceding the identifier of a variable with ________________.

Select correct option:

dot operator

ampersand sign &

^ sign

  • operator

 

6- Once an object is declared as a friend, _________________________.

Select correct option:

it has access to all non-public members as if they were public

it has access to public members only

it has no access to data members of the class

it has to protected data members only

  • Friend declarations introduce extra coupling between classes
  • Once an object is declared as a friend, it has access to all non-public members as if they were public
  • Access is unidirectionalIf B is designated as friend of A, B can access A’s non-public members; A cannot access B’s
  • A friend function of a class is defined outsideof that class’s scope

 

7- Reference variables must _________________.

Select correct option:

not be initialized after they are declared

be initialized after they are declared

contain integer value

contain zero value

 

8- If the request of new operator is not fulfilled due to insufficient memory in the heap ____________________.

Select correct option:

the new operator returns 2

the new operator returns 1

malloc functions returns NULL pointer

malloc function returns free space

 

 

9- Reference is not really an address it is ______________.

Select correct option:

a synonym

an antonym

a value

a number

 

10- If the request of new operator is not fulfilled due to insufficient memory in the heap ____________________.

Select correct option:

the new operator returns 2

the new operator returns 1

the operator returns 0

free operator returns nothing

 

11- Functions declared with the _______________ specifier in a class member list are called friend functions of that class. 
Select correct option: 

protected 
private

Public

friend

Functions declared with the friend specifier in a class member list are called friend functions of that class. Classes declared with the friend specifier in the member list of another class are called friend classes of that class.

 

12- public or private keywords can be ____________ 
Select correct option: 

written only for once in the class or structure declaration 
written multiple times in the class or structure declaration 
written only twice in the class declaration 
written outside the class

good practice is to write public or private keywords only once in the class or structure declaration, though there is no syntactical or logical problem in writing them multiple times.

 

13-The friend keyword provides access _____________. 
Select correct option: 

in one direction only 
in two directions 
to all classes 
to the data members of the friend class only

The friend keyword provides access in one direction only. This means that while OtherClass is a friend of ClassOne, the reverse is not true.

14- References cannot be uninitialized. Because it is impossible to _______________ 
Select correct option:

reinitialize a pointer 
reinitialize a reference 
initialize a NULL pointer 
cast a pointer

http://en.wikipedia.org/wiki/Reference_(C%2B%2B)

 

References cannot be uninitialized. Because it is impossible to reinitialize a reference,

15- new operator can be used for ______________.

Select correct option:

only integer data type

only char and integer data types

integer , float, char and double data types

dot operator

Similarly, new operator can be used for other data types like char, float and double etc.

 

16- The destructor is used to ______________.

Select correct option:

allocate memory

deallocate memory

create objects

allocate static memory

16- If we want to allocate memory to an array of 5 integers dynamically, the syntax will be _____________.

Select correct option:

int *iptr ; iptr = new int[5] ;

integer iptr** ; iptr= new int[5]

int iptr ; iptr= int [5]

iptr= new[5]

17- Memory allocated from heap or free store _____________________.

Select correct option:

can be returned back to the system automatically

can be allocated to classes only

cannot be returned back unless freed explicitly using malloc and realloc

cannot be returned back unless freed explicitly using free and delete operators 

18- Operator overloading is to allow the same operator to be bound to more than one implementation, depending on the types of the _________.

Select correct option:

Compilers

Operands

Function names

Applications

Operator overloading is to allow the same operator to be bound to more than one

implementation, depending on the types of the operands.

 

19- The operator to free the allocated memory using new operator is ________________.

Select correct option:

free

del

delete

remove

The operator to free the allocated memory using new operator is delete. So whenever,

we use new to allocate memory, it will be necessary to make use of ‘delete’ to deallocate

the allocated memory.

20- The concept of friend function negates the concept of _________________.

Select correct option:

inheritance

polymorphism

persistence

encapsulation

CS201 Introduction to Programming Solved MCQs

VU HELP CENTER : 03478749900

Functions declared with the _______________ specifier in a class member list are called friend functions of that class. 
protected 
private
public
friend

Functions declared with the friend specifier in a class member list are called friend functions of that class. Classes declared with the friend specifier in the member list of another class are called friend classes of that class.

Public or private keywords can be ____________ 

written only for once in the class or structure declaration 
written multiple times in the class or structure declaration 
written only twice in the class declaration 
written outside the class

good practice is to write public or private keywords only once in the class or structure declaration, though there is no syntactical or logical problem in writing them multiple times.

The friend keyword provides access _____________. 
in one direction only 
in two directions 
to all classes 
to the data members of the friend class only

The friend keyword provides access in one direction only. This means that while OtherClass is a friend of ClassOne, the reverse is not true.

References cannot be uninitialized. Because it is impossible to _______________ 

reinitialize a pointer 
reinitialize a reference 
initialize a NULL pointer 
cast a pointer
http://en.wikipedia.org/wiki/Reference_(C%2B%2B)
References cannot be uninitialized. Because it is impossible to reinitialize a reference,

new operator can be used for ______________.
only integer data type
only char and integer data types
integer , float, char and double data types
dot operator
Similarly, new operator can be used for other data types like char, float and double etc.

The destructor is used to ______________.

allocate memory
deallocate memory
create objects
allocate static memory

Reference is not really an address it is ______________.

a synonym
an antonym
a value
a number
Difference Between References and Pointers
The reference in a way keeps the address of the data entity. But it is not really an address it is a synonym,

If we want to allocate memory to an array of 5 integers dynamically, the syntax will be _____________.

int *iptr ; iptr = new int[5] ;

integer iptr** ; iptr= new int[5]

int iptr ; iptr= int [5]

iptr= new[5]

Memory allocated from heap or free store _____________________.

can be returned back to the system automatically

can be allocated to classes only

cannot be returned back unless freed explicitly using malloc and realloc

cannot be returned back unless freed explicitly using free and delete operators

The memory allocated from free store or heap is a system resource and is not returned back to the system unless explicitly freed using delete or free operators.

Operator overloading is to allow the same operator to be bound to more than one implementation, depending on the types of the _________.

Compilers
Operands
Function names
Applications

Operator overloading is to allow the same operator to be bound to more than one implementation, depending on the types of the operands.

The operator to free the allocated memory using new operator is ________________.

free
del
delete
remove

The operator to free the allocated memory using new operator is delete. So whenever, we use new to allocate memory, it will be necessary to make use of ‘delete’ to deallocate the allocated memory.

suppose we have int y[10]; To access the 4th element of the array we write_______

y[4];
y[3];
y[2];
none of given

From the following; which one is the range of Random number generator function rand()?

0 – 32768
1 – 32768
0 – 32767
1 – 32767

From following; which one is the correct syntax of an array initialize: Array size is 10 and it is of double data type to value 0?

arr[10] = {0.0};
double arr[10]= 0.0;
double arr[10] = {0.0};
double arr[] = 0.0;

The string in the array is terminated by a_____

zero
nil
null
one

CS201 Introduction to Programming Solved MCQs

VU HELP CENTER : 03478749900

In C/C++; by default arguments are passed by_____to a function.

Reference
Value
Type
Data

1
char name [] = “Hello World” ; In the above statement, a memory of_______characters will be allocated

13
11

12
10

_______Keyword is used to return some value from a function.

break
return
continue
goto

Which of the function call is call by value for the following function prototype? float add(int);

add(&x);
add(x);
add(int x);
add(*x);

The increment of a pointer depends on its_________.

variable

value
data type
None of the given

The ASCHI code of null character is_________

000
010
111
110

 

Pointers are a special type of __________in which a memory address is stored
variables
Location
Characters
None of the given

just for copy paste

 

CS201 Introduction to Programming Solved MCQs

VU HELP CENTER : 03478749900

 

Transpose of a matrix means that when we interchange rows and columns_____________

the first row becomes the Last column
the first row becomes the first column
the Last row becomes the first column
the first column becomes the first row

 


Pointers store the ____________________

value of a variable
memory address
characters
None of the given

 

Which of the following function call is “call by reference” for the following function prototype? int add (int *);

add(&x);
add(int x);
add(x);
add(*x);

 

The name of the array is a constant pointer which contains the memory address of the ____________of the array.

first element
Last element
second element
None of the given

 

array name always contains the memory address of the ___________of the array

entire elements
last element
first element
None of the given

At the___________, we try to break up the problem into functional units

analysis phase
design phase
Implementation phase
None of the given

1.  Each pass through a loop is called a/an
[a] enumeration
      [b] iteration
      [c] culmination
[d] pass through

2.  Which looping process checks the test condition at the end of the loop?
[a] for
[b] while
 [c] do-while
[d] no looping process checks the test condition at the end

3.  A continue statement causes execution to skip to
[a] the return 0; statement
[b] the first statement after the loop
[c] the statement following the continue statement
      [d] the next iteration of the loop

 4.  In a group of nested loops, which loop is executed the most number of times?
[a] the outermost loop
      [b] the innermost loop
      [c] all loops are executed the same number of times
[d] cannot be determined without knowing the size of the loops

 5.  The statement  i++;  is equivalent to
[a] i = i + i;
      [b] i = i + 1;
      [c] i = i – 1;
[d] i –;

 6.  Which looping process is best used when the number of iterations is known?
      [a] for
      [b] while
[c] do-while
[d] all looping processes require that the iterations be known

 7.  What’s wrong?  for (int k = 2, k <=12, k++)
[a] the increment should always be ++k
[b] the variable must always be the letter i when using a for loop
[c] there should be a semicolon at the end of the statement
[d] the commas should be semicolons

 8.  What’s wrong?  while( (i < 10) && (i > 24))
[a] the logical operator && cannot be used in a test condition
[b] the while loop is an exit-condition loop
      [c] the test condition is always false
      [d] the test condition is always true

 9.  If there is more than one statement in the block of a for loop, which of the following must be placed at the beginning and the ending of the loop block?
[a] parentheses ( )
      [b] braces { }
      [c] brackets [ ]
[d] arrows < >

 10.  What’s wrong?  (x = 4 && y = 5) ? (a = 5) ; (b = 6);
[a] the question mark should be an equal sign
      [b] the first semicolon should be a colon
      [c] there are too many variables in the statement
[d] the conditional operator is only used with apstrings