cs201 Mid Term
cs201 Mid Term
MID-Term
Best Collection
0331-7273691
The second parameter of operator function for >> operator must always be passed
► By reference
► By value
► Stack
► Heap
► System Cache
► Certain overloaded operators can change the number of arguments they take. P# 372
►5
► 48
► error
► Pointers
► Array index
Which of the following syntax will be used to initialize an array of size 5 of int data type to value 0?
► arr[5] = {0} ;
► int arr[5]= 0 ;
► int arr[] = 0 ;
The default scope for members of structures is public whereas the default visibility for class members is private.
► True (P 490)
►False
Which of the following is the only operator that the compiler overloads for user define data type?
► Plus (+)
► Minus (-)
► Equal (= =)
► Assignment (=)
If a friend function outside the class declare itself friend of the class, this will neglect concept of ___________.
► include
► Directive
► Macro
► Define
► functions
► datatypes (p 228)
► Arithmetic operations
When we do dynamic memory allocation in the constructor of a class, then it is necessary to provide a
destructor.
►True
►False
Overloaded new operator function takes parameter of type size_t and returns
► void (nothing)
► void pointer (Page 415)
► object pointer
► int pointer
The second parameter of operator functions for << and >> are objects of the class for which we are
overloading these operators.
► True (page 453)
► False
To include code from the library in the program, such as iostream, a directive would be called up using this
command.
► #include “iostream.h”
► include <iostream.h>
► include <iostream.h>
► #include <iostream.h> (sure)
A template function must have only generic data types.
► True
► False (Page 501)
What will be the correct syntax to assign an array named arr of 5 elements to a pointer ptr? (CHECK)
►*ptr = arr ;
►ptr = arr ;
►ptr = arr[5] ;
►*ptr = arr[5] ;
What will be the correct syntax to access the value of fourth element of an array using pointer ptr?
► ptr[3]
► (ptr+3)
► *(ptr+3)
► Both 1and 3
If there is a symbol (& sign) used with the variable name followed by data type then it refers to _____ and if
& is being used with variable name then it refers to _____.
► Address of variable, reference variable
► Reference variable, value of variable
► Reference variable, address of variable (Page 367)
► Address of variable, value of variable
The default value of a parameter can be provided inside the ________________ CHECK
► function prototype
► function definition (page 249)
► both function prototype or function definition (Page 294)
► none of the given options.
new operator is used to allocate memory from the free store during
►Compile Time
►Run Time
►Link Time
►None of the given options
New and Delete are also used with ___________ and data types as well.
► Class, Objects (Page 342)
► Structures, Pointers
► Both Class and structures
► None of above
With New keyword, data types and class members are initialized with meaningful values instead of garbage.
► True (Page 334)
► False
If we write a statement like s2 = s1; ___ will be the calling object and ____ will be passed to the = operator as
an argument.
► s1, s1
► s1, s2
► s2, s1
► s2, s2
If we write a statement like s2 = s1; s2 will be the calling object and s1 will be passed to the = operator as an
argument. P# 397
cout << setfill(‘0’) << setw(7) << 128 ;
► 0000128
► 0128128
► 1280000
► 0012800
We can also define a variable of user define data type (object) as static.
► True
► False
When 6 divides any number, the remainder will always be less than 6. Ther result will be between therefore
we will add 1. 1 + rand ( ) % 6; Which of the following is the correct function call having array named student
of 10 elements as a parameter.
► addRecord(student[]) ;
► addRecord(student) ;
► addRecord(student[10]) ;
► addRecord(*student) ;
If a class A declares itself a friend of class B and a class B declares itself a friend of class C then
► Class A is also a friend of class C.
► Class B is also a friend of class A.
► Class A is also a friend of class C if A declares C as its friend.
► Class A is also a friend of class C if C declares A as its friend.
When memory for a program is allocated at run time then it is called ________
► static memory allocation
► dynamic memory allocation
► stack memory allocation
► virtual memory allocation
Dealing with structures and functions passing by reference is the most economical method
► True
► False
When new operator is overloaded at global level then corresponding built-in new operator will not be visible
to whole of the program.
► True (Page 413)
► False
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?
► parentheses ( )
► braces { } (Page 37)
► brackets [ ]
► arrows < >
The return type of a function that do not return any value must be ________
► float
► int
► void (Page 79)
► double
Like member functions, ______ can also access the private data members of a class.
► Non-member functions
► Friend functions (Page 346)
► Any function outside class
► None of the given options
Which of the following function call is correct for the function prototype?
defaultParameters ( int a, int b = 7, char z = ‘*’ );
► defaultParameters (5);
► defaultParameters (5, ‘8’);
► defaultParameters (6, ‘#’);
► defaultParameters (0, 0, ‘*’, 0);
When an operator function is defined as member function for a binary Plus (+) operator then the number of
argument it take is/are.
► Zero
► One
► Two (Page 371)
► N arguments
The appropriate data type to store the number of rows and colums of the matrix is____________.
► float
► int
► char
► none of the given options.
NULL value has been defined in ______ and _________ header files.
► strings.h and iostream.h
► ctype.h and conio.c
► conio.c and conio.h
► stdlib.h and stddef.h (Page 281)
A Matrix can be composed of ints, floats or doubles as their elements. Best way is to handle this
_______________
► Write a separate class to handle each
► Use templates (Page 527)
► Use strings to store all types
► None of the given options
When x = 7; then the expression x%= 2; will calculate the value of x as,
►1 ►3 ►7 ►2
delete operator is used to return memory to free store which is allocated by the new operator
►True
►False
What is the sequence of event(s) when allocating memory using new operator?
► Only block of memory is allocated for objects
► Only constructor is called for objects
► Memory is allocated first before calling constructor (Page 414)
► Constructor is called first before allocating memory
Deleting an array of objects without specifying [] brackets may lead to memory leak (check)
►True (MOST)
►False
Which of the following data type will be assumed if no data type is specified with constant?
short
float
int
double
There is an array of characters having name „course‟ that has to be initialized by string „programming‟ of the
following is the correct way to do this
(i) course[] = {„p‟, ‟r‟, ‟o‟, ‟g‟, ‟r‟, ‟a‟, ‟m‟, ‟m‟, ‟i‟, ‟n‟, ‟g‟};
(ii)course[] = „programming‟ ;
(iii)course[12] = “programming” ;
(iv)course = “programming” ;
Choose the correct options.
► (i) and (ii) only
► (i) and (iv) only
► (i) and (iii) only
► (ii) and (iii) only
Loader loads the executable code from hard disk to main memory.
True
False
Which of the following is the correct C++ syntax to allocate space dynamically for an array of 10 int?
► new int(10) ;
► new int[10] ;
► int new(10) ;
► int new[10];
The prototype of friend functions must be written ____ the class and its definition must be written ____
► inside, inside the class
► inside, outside the class (Page 346)
► outside, inside the class
► outside, outside the class
When the compiler overloads the assignment (=) operator by default then __________
► compiler does member wise assignment.
► compiler does not allow default overload of assignment (=) operator
► member of the class are not assigned properly
► None of the given options
If text is a pointer of class String then what is meant by the following statement?
text = new String [5];
► Creates an array of 5 string objects statically
► creates an array of 5 string objects dynamically
► Creates an array of pointers to string
► Creates a string Object
Copy constructor becomes necessary while dealing with _______allocation in the class.
► Dynamic memory
► Static memory
► Both Dynamic and Static memory
► None of the given options
Which one of the following is the declaration of overloaded pre-increment operator implemented as member
function?
► Class-name operator +() ;
► Class-name operator +(int) ;
► Class-name operator ++() ; (Page 389)
► Class-name operator ++(int) ;
How many bytes will the pointer intPtr of type int move in the following statement? intPtr += 3 ;
► 3 bytes
► 6 bytes
► 12 bytes
► 24 bytes
A Pointer is a special variable that contain
► Data values
► Memory Address (Page 267)
► Both data and values
► None of the given option
Reference Value Type Data The code is written to __________ the program.
► implement (Page 520)
► design
► analysis
► none of the given options.
Which of the following function is used to increase the size of already allocated memory chunk?
► malloc
► calloc
► realloc (Page 285)
► free
The stream objects cin and cout are included in which header file?
► iostream.h (Page 15)
► fstream.h
► istream.h
► ostream.h
Overloaded delete operator function takes the same parameter as an argument returned by new operator
function.
► True (Page 414)
► False
When an array of object is created dynamically then there is no way to provide parameterized constructors for
array of objects.
► True (Page 414)
► False
What will be the value of ‘a’ and ‘b’ after executing the following statements?
A = 3;
b = a++;
► 3, 4
► 4, 4
► 3, 3
► 4, 3
_______ is used to trace the logic of the program and correct the logical errors.
► Compiler
► Editor
► Linker
► Debugger (Page 13)
new and delete are _____ whereas malloc and free are _____.
► Functions, operators
► Classes, operators
► Operators, functions (Page 342-285)
► Operators, classes
The stream insertion and stream extraction operators are already overloaded for ______.
► User-defined data types
► Built-in data types
► User-defined and built-in data types
► None of the given options
The stream insertion and extraction operators are not already overloaded for _______
► Built-in data types
► User-defined data types
► Both built-in and user-defined types
► None of the given options
If we define an identifier with the statement #define PI 3.1415926 then during the execution of the program
the value of PI __________.
► can not be replaced
► None of the given options
► Remain constant. (Page 271)
► can be changed by some operation
Assignment operator is -------------------------associative.
► right
► left
► binary
► unary
Which of the following function do NOT initialize the chunk of memory to all zero?
► calloc() function
► Both malloc() and calloc()
► None of the above
► malloc() function (Page 283)
The function free() returns back the allocated memory got thorough calloc and malloc to _____ .
► stack
► heap
► stack and heap
► None of the given options
Header file: fstream.h includes the definition of the stream classes __________.
► ifstream, fstream, cout
► ifstream, fstream, ofstream (Page 199)
► fstream, cin, cout
► None of the above
Function implementation of friend function must be defined outside the class. (Check)
► True
► False (Page 346)
Which of the following is correct way to initialize a variable x of int type with value 10?
► int x ; x = 10;
► int x = 10;
► int x, x = 10;
► x = 10;
With template function, the compiler automatically detects the passed data and generates a new copy of
function using passed data.
► True Page 510
► False
What will be the correct syntax to declare two-dimensional array of float data type?
► float arr{2}{2} ;
► float arr[2][2] ;
► float arr[2,2] ;
► float[2][2] arr ;
While calling function, the arguments are assigned to the parameters from _____________.
► left to right. (Page 295)
► right to left
► no specific order is followed
► none of the given options.
When a call to a user-defined function finishes, the variable defined inside the function is still in existence.
► True
► False (Page 460)
"delete" operator is used to return memory to free store, which is allocated by the "new" operator.
► True (page 332)
► False
Within the statement obj1=obj2; obj1 will call the assignment operator function and obj2 will be passed as an
argument to function.
► True
► False
What is the sequence of event(s) when deallocating memory using delete operator?
► Only block of memory is deallocated for objects
► Only destructor is called for objects
► Memory is deallocated first before calling destructor
► Destructor is called first before deallocating memory (Page 414)
Unary operator implemented as member function takes ____ arguments whereas non-member function takes
_____ arguments.
► One, zero
► Zero, one
► One, two
► Two, one
The first parameter of overloaded stream insertion operator is _________ where second parameter is
_______
► input stream, object of class
► object of class, output stream
► output stream, object of class
► object of class, input stream
The return type of the operator function for << operator is __________.
► class for which we overload operator
► reference of ostream class (ostream&)
► reference of istream class (istream&)
► void
Memory allocated at run time is a system resource and it is the responsibility of _____ to de-allocate the
memory.
► System
► Programmer (Page 331)
► User of program
► None of given options
In C/C++ if we define an array of size eight (8) i.e. int Arr [8]; then the last element of this array will be
stored at,
► Arr[0]
► Arr[8]
► Arr[7]
► Arr[-1]
When an array is passed to a function then default way of passing this array is,
► By data
► By reference (Page 154)
► By value
► By data type
We can delete an array of objects without specifying [] brackets if a class is not doing dynamic memory
allocation internally.
Ø True
Ø False
Default mechanism of function calling in case of array is _____ and in case of variable is ___.
► Call by value, call by reference
► Call by referene, call by reference
► Call by reference, call by value (Page 119)
► Call by value, call by value
For which array, the size of the array should be one more than the number of elements in an array?
► int
► double
► float
► char (Page 113)
If overloaded plus operator is implemented as non-member function then which of the following statement
will be true for the statement given below? (Check)
obj3 = obj1 + obj2 ;
► obj2 will be passed as an argument to + operator whereas obj2 will drive the + operator
► obj1 will drive the + operator whereas obj2 will be passed as an argument to + operator
► Both objects (obj1, obj2) will be passed as arguments to the + operator (not sure)
► Any of the objects (obj1, obj2) can drive the + operator
For cin, the source is normally a ________ and destination can be ______.
► File, native data type
► Disk, user-define type
► Keyboard, variable (Page 424)
► File, user-define type
With user-defined data type variables (Objects), self assignment can produce __________. (Check)
► Syntax error
► Logical error
► Link error
► Non of the given options (not sure)
Assignment operator is used to initialize a newly declared object from existing object.
► True (Page 479)
► False
new operator allocates memory from free store and return _____________.
► A pointer
► A reference
► An integer
► A float
Which character is inserted at the end of string to indicate the end of string?
► new line
► tab
► null (Page 113)
► carriage return
The object _______________may be used both for file input and file output
► fstream, (Page 199)
► ifstream,
► ofstream,
► none of the given options.
Which of the following function calling mechanism is true for the function prototype given below?
float func(float &);
► Call by value
► Call by reference using pointer
► Call by reference using reference variable
► None of the given options
Overloaded delete operator function takes parameter of void pointer and returns ________.
► void
► void pointer
► pointer to an object
► pointer of type int
It is a way of reusing the code when we contain objects of our already written classes into a new class,
► True
► False
The functions used for dynamic memory allocation return pointer of type ______
► int
► float
► void
► double
The compiler does not provide a copy constructor if we do not provide it.
► True
► False (Page 476)
What is the functionality of the following syntax to delete an array of 5 objects named arr allocated using new
operator?
delete arr ;
► Deletes all the objects of array
► Deletes one object of array (Page 411)
► Do not delete any object
► Results into syntax error
The operator function of << and >> operators are always the member function of a class.
► True
► False (Page 446)
If we do not mention any return_value_type with a function, it will return an _____ value.
► int (Page 79)
► void
► double
► float
Suppose a program contains an array declared as int arr[100]; what will be the size of array?
►0
► 99
► 100 (Page 103)
► 101
Which of the following option is true about new operator to dynamically allocate memory to an object?
► The new operator determines the size of an object
► Allocates memory to object and returns pointer of valid type
► Creates an object and calls the constructor to initialize the object
► All of the given options
For non-member operator function, object on left side of the operator may be
► Object of operator class
► Object of different class
► Built-in data type
► All of the given options (Page 375)
The operator function will be implemented as _____, if obj1 drive the - operator whereas obj2 is passed as
arguments to - operator in the statement given below.
obj3 = obj1 - obj2;
► Member function (Page 373)
► Non-member function
► Friend function
► None of the given options
Which looping process checks the test condition at the end of the loop?
Ø for
Ø while
Ø do while
Ø no looping process checks the test condition at the end
In a group of nested loops, which loop is executed the most number of times?
Ø the outermost loop
Ø the innermost loop
Ø all loops are executed the same number of times
Ø cannot be determined without knowing the size of the loops
Which of the following option(s) are correct to initialize a two-dimensional array with 3 rows and 2
columns?
Ø (ii) only
Ø (iii) only
Ø (ii) and (iii)
Ø and (iii)
There is a pointer variable named ptr of type int then address of which type of variable the ptr will store in it?
Ø variable of type char
Ø variable of type short
Ø variable of type int
Ø variable of type double
The member functions of a class occupy _____ region in memory for ____ object(s) of class.
Ø separate, each
Ø common, all (Page 334)
Ø different, each
Ø different, all
While developing a program; sould we think about the user interface? //handouts main reusability hay..us ki
yahan option hi nahi hay
Yes No
These functions seekg() and seekp() requires an argument of type ____________to let them how many bytes
to move forward or backward.
int
short
long
double
______________ transfers the executable code from main memory to hard disk.
Loader
Debugger
Compiler
Linker
When the logical operator OR (||) combine two expressions exp1 and exp2 then the result will be false only,
//bitwise “or” applies here….
When both exp1 and exp2 are true
When both exp1 and exp2 are false
When exp1 is true and exp2 is false
When exp1 is false and exp2 is true
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
We have opened a file stream myfile for reading (getting), myfile.tellg () gives us the current get position of
the file pointer. It returns a whole number of type___________
long
int
short
double
When we are using const keyword with a variable x then initializing it at the time of declaration is,
► Must
► Optional
► Not necessary
► A syntax error
Which of the following is the correct way to assign an integer value 5 to element of a matrix say ‘m’ at second
row and third column?
► m[2][3] = 5 ;
► m[3][2] = 5 ;
► m[1][2] = 5 ;
► m[2][3] = ‘5’;
How many total elements must be in two-dimensional array of 3 rows and 2 columns?
►4
►5
►6
►7
Which of the following is the correct statement for the following declaration?
const int *ptr.
►ptr is a constant pointer
►ptr is constant integer pointer
►ptr is a constant pointer to int
►ptr is a pointer to const int
The variables having a name, type and size are just like empty boxes.
►False
►True
Compiler is a
► System software
► Application Software
► Driver
► Editor
Operating System is
► An application software
► System Software
► Computer Language
► Interpreter
Which one is the correct syntax for defining an identifier PI with preprocessor directive?
► #define PI 3.1415926;
► #define PI 3.1415926
► #define PI = 3.1415926 ;
► #define PI = 3.1415926
What will be the correct syntax for initialization of pointer ptr of type int with variable x?
► int ptr = &x ;
► int ptr = x ;
► int *ptr = &x ;
► int ptr* = &x ;
Which of the following function calling mechanism is true for the function prototype given below?
float func(float &);
► Call by value
► Call by reference using pointer
► Call by reference using reference variable
► None of the given options
Which of the following object(s) will call the member operator function within the statement given below?
obj1=obj2+obj3;
► Object obj1
► Object obj2
► Object obj3
► Any of the object
The region of memory, available for allocation at run time in C language is called ________ memory whereas
in C++ language is called as ________________.
► Heap, Stack
► Stack, Free Store
► Heap, Free Store
► None of above
To avoid dangling reference, always return the reference of a local variable from a function.
► True
► False
"delete" operator is used to return memory to free store, which is allocated by the "new" operator.
► True
► False
What does 5 ^ 6 , evaluate to in decimal where ‘^’ is Exclusive OR operator?
►1
►2
►3
►4
If constructor contains a return statement in its body then compiler will give __________ check
► No error
► Syntax error
► Logical error
► Run time error
As the constructor does not return any thing, so it has no return type. It means that the body of the
construct function cannot have any return statement. Otherwise, the compiler will give a syntax error. P
# 322
Which of the following data type(s) can operate on modulus operator ‘%’?
► float, int
► float, double
► int
► char
What will be the correct syntax to initialize all elements of two-dimensional array to value 0?
►int arr[2][3] = {0,0} ;
►int arr[2][3] = {{0},{0}} ;
►int arr[2][3] = {0},{0} ;
►int arr[2][3] = {0} ;
When an operator function is define as member function then operand on the left side of operator must be an
object.
►True
►False
When an operator function is define as member function for a Unary operator then the number of argument it take is/are,
►Zero
►One
►Two
►N arguments
Every data member or function inside the structure is ___ by default whereas everything declared inside a
class is ____ by default.
►private, public
►public, private
►private, protected
►public, protected
Which of the following is true for the C++ statement given below?
int &ref = val ;
►It creates a synonym for variable ‘val’
►It creates an alias for variable ‘val’
►It’s a new name for variable ‘val’
►All of the given options
The input/output streams cin and cout are ________ therefore have _______.
► Structures, function
► Objects, member functions
► Functions, objects
► None of the given options
A constructor that will create a new object with a full copy of the other object, is copy is known as
___________
►deep copy
►shallow copy
►constructor copy
►none of the options
Consider the following code segment. What will be the output of this code segment?As
arrays starts from 0 index………at 1st position is 3………n at position 4th is 5…
……5-3=2
int arr[6] = {2, 3, 7, 4, 5, 6} ;
int *ptr1 =&arr[1] ;
int *ptr2 = &arr[4] ;
cout << (ptr2-ptr1) ;
►3
►9
► 12
►2
Let assume if p and q are class objects then function is implemented as _______
► Member function
► Non-member function
► Friend function
► None of the given options
Consider the following code segment. What will be the output of following code?
Int addValue (int *a){
int b = (*a) + 2;
return b ;
}
main () {
int x =6 ;
cout << x << “,” ;
cout << addValue(&x) << “,” ;
cout << x ;
}
► 6,8,6
► 6,6,8
► 6,8,8
► 6,6,6
For which values of the integer _value will the following code becomes an infinite loop?
int number=1;
while (true) {
cout << number;
if (number == 3) break;
number += integer_value; }
► any number other than 1 or 2
► only 0
► only 1
► only 2
Let suppose
Union intorDouble{
Int ival;
Double charvar;
};
main(){
intorDouble VAZ;
int size ;
size = sizeof(VAZ);
}
What will be the value of variable "size", if int occupies 4 bytes and double occupies 8 bytes?
Ø2
Ø4
Ø8
Ø 12