CS201 Grand Quizz File
CS201 Grand Quizz File
1
Arranged By Syed Muslim Abbas
00966583979675
[email protected]
Note: All the answers are not verified, it is only re-arranging effort from multiple files into 1 file just
to save the times of class mates. Please remember me in your prayers
1. In order to get 256 from the number 2568 we divide this number by 10 and take,
► Its remainder
► The number
► Its quotient
► Its divisor
6. Member function tellg() returns the current location of the _____________ pointer.
► tellptr()
► write()
► seekg()
► get() (Pg 215)
7. What does 5 | 6 , evaluate to in decimal where ‘|’ is bitwise OR operator?
►3
►4
►5
► 7
5|6=
0101
0110
--------
CS201 Grand Quizz Preparation Spring 2020
2
0 111=7
10. How many bytes are occupied by declaring following array of characters?
char str[] = “programming”;
► 10
► 11
► 12
► 13
11. What will be the correct syntax for initialization of pointer ptr with string "programming"?
► char ptr = ’programming’ ;
► char *ptr = “programming” ;
► char *ptr = ‘programming’ ;
► *ptr = “programming” ;
pg 166
array element in each array initialized with a single character enclosed in single
quote. pg 21
While assigning a character value to a char type variable single quotes are used around the
character as ‘a’.
12. What will be the result of expression x%= 2, if x = 7?
►x=1
►x=3
►x=7
►x=2
14. What will be the value of i and j in the following code segment?
int i, j ;
int x[5] = {2, 3, 4, 8, 9} ;
int *ptr =&x[2];
i = (*ptr)++ ;
CS201 Grand Quizz Preparation Spring 2020
3
j = *ptr++ ;
► i = 5, j = 5
► i = 5, j = 8
► i = 4, j = 8
► i = 5, j = 9
18. The condition in while loop may contain logical expression but not relational
expression.
► True
► False
21. 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
22. What will be the correct syntax to initialize all elements of two-dimensional array to value 0?
► int arr[2][3] = {0,0} ;
CS201 Grand Quizz Preparation Spring 2020
4
► int arr[2][3] = {{0},{0}} ;
► int arr[2][3] = {0},{0} ;
► int arr[2][3] = {0} ;
23. Which of the following function returns the size of a string variable?
► strlength()
► stringlen()
► strlen()
► strLength()
When applied to a character array, the strlen function returns the length of the string stored
there,
not its allocated size.
27. If the file is not properly closed in the program, the program ____________.
► Terminate normally
► Indicate Runtime error
► Indicate Compile time error
► Crashes
Eventually run out of file handles and/or memory space and crash.)
28. Which of the following header file include string conversion functions?
► stdlib.h
CS201 Grand Quizz Preparation Spring 2020 5
29. A precise sequence of steps to solve a problem is called
► Statement
► Program
► Utility
► Routine
31. Dealing with structures and functions passing by reference is the most economical method
► True
► False
32. Preprocessor program perform its function before ______ phase takes place.
► Editing
► Linking
► Compiling
► Loading
33. Which looping process is best, when the number of iterations is known?
► for
► while
► do-while
► all looping processes require that the iterations be known
34. Which character is inserted at the end of string to indicate the end of string?
► new line
► tab
► null
► carriage return
35. Which of the following header file defines the rand() function?
► iostream.h
► conio.h
► stdlib.h
► stdio.h
40. In C/C++ language the header file which is used to perform useful task and
manipulation of character data is
► cplext.h
► ctype.h (Pg 188)
► stdio.h
► delay.h
43. 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
Rational:
number += integer_value ………..above line decide the fate of loop so any thing other then
zero leads
to value of 3 which will quite the loop. Only zero is the value which keeps the loop infinite.
48. What is the correct syntax to declare an array of size 10 of int data type?
► int [10] name ;
► name[10] int ;
► int name[10] ;
► int name[] ;
49. Consider the following code segment. What will the following code segment
display? int main(){
int age[10] = {0};
cout << age ;
}
► Values of all elements of array
► Value of first element of array
► Starting address of array
► Address of last array element
50. 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
one int is 4 bytes so 4*3 = 12 bytes movement.
51. If there are 2(n+1) elements in an array then what would be the number of iterations required
to search a number using binary search algorithm?
► n elements
► (n+1) elements
► 2(n+1) elements
► 2(n+1) elements
52. Which of the following operator is used to access the value of variable pointed to by a
pointer?
► * operator
► -> operator
► && operator
► & operator
• System Software
• Application Software
59. In flow chart, the symbol used for decision making is,
►Rectangle
►Circle
►Arrow
►Diamond (Pg 51)
61. If the elements of an array are already sorted then the useful search
algorithm is, ►Linear search
►Binary search (Pg 188)
►Quick search
►Random search
In binary search algorithm, the ‘divide and conquer’ strategy is applied.
This plies only to sorted arrays in ascending or descending order.
CS201 Grand Quizz Preparation Spring 2020 9
62. The address operator (&) can be used with,
►Statement
►Expression
►Variable
►Constant
66. The return type of a function that do not return any value must be __________
►int
►void
►double
►float
69. When we declare a multidimensional array the compiler store the elements of
multidimensional array in the
form of,
►Columns
►Rows
►Contiguous memory location (Pg 174)
►Matrix
CS201 Grand Quizz Preparation Spring 2020 10
70. In C/C++ the string constant is enclosed
► In curly braces
► In small braces
► In single quotes
► In double quotes
73. 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
74. 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’;
75. How many total elements must be in two-dimensional array of 3 rows and 2 columns?
►4
►5
► 6 (3*2=6)
►7
76. 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
77. Consider the following code segment. What will be the output of this code segment?
int arr[6] = {2, 3, 7, 4, 5, 6} ;
int *ptr1 =&arr[1] ;
int *ptr2 = &arr[4] ;
cout << (ptr2-ptr1) ;
► 3
► 9
► 12
► 2
CS201 Grand Quizz Preparation Spring 2020 11
78. C is a/an ______ language
►low level
►object based
► object oriented
►function oriented (Pg 77)
78. The variables having a name, type and size are just like empty boxes.
► False
► True
79. Most efficient method of dealing with structure variables is to define the structure globally
► True
► False
82. If we want to store a string “abc” in an array str then the size of this array must be at least,
► 2
► 3
► 4
► 5
86. Carefully analyze the following lines of code and chose the correct option.
ch1=”a”;
ch2=’a’;
► ch1 and ch2 are strings
► ch1 is string and ch2 is character
► ch2 is string and ch1 is character
CS201 Grand Quizz Preparation Spring 2020 12
► ch1 and ch2 are characters
89. Compiler is a
► System software
► Application Software
► Driver
► Editor
91. For one byte there are _____ combinations of values that can be stored in computer.
►
26
► 27
►
28
► 24
95. 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
100 Which of the following values C++ use to represent true and false?
► and 0
► and -1
► and 00
► Any numerical value
102 If a variable is passed by value to a function and the function makes some
changes to that variable then it
► Does not affect the original variable pg 83
► affects the original variable
► causes syntax error
► None of the given options
104 _________is manipulator and it inserts new line character and flushes the
stream.
► Endl
110 Which of the following data type(s) can operate on modulus operator ‘%’?
► float, int
► float, double
► int Pg 22
► char
112 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
1.if statement is used when we have to check two conditions while switch is a
multi conditional control statement.
2. SWITCH statement can be executed with all cases if the “break”
statement is not used whereas IF statement has to be true to be executed
further.
117 What is wrong with following code and also give the reason of error?
int x , y ;
int *ptr1 = &x ;
int *ptr2 =&y ;
ptr1+ptr2 ;
Answer:
We need one more variable in which we put sum of ptr1 and ptr2 like
Int z;
z=ptr1+ptr2;
(Answer provided by Ferhat Qudsia)
119 What happened when we try to copy the array ‘arr1’ into the array ‘arr2’
in the following code segment, justify your answer?
main()
{
int arr1[3]={2,3,5};
int arr2[3];
arr2=arr1;
}
We can not copy array directly in this way (arr2=arr1;)
Each member of arr1 to be copied by each member of arr2.
We can use for loop to copy array 1 to array2
(Answer provided by Ferhat Qudsia)
121 When the logical operator AND (&&) combine two expressions exp1 and
exp2 then the result will be true only,
► When both exp1 and exp2 are true Pg 246
► When both exp1 and exp2 are false
► When exp1 is true and exp2 is false
► When exp1 is false and exp2 is true
ttp://vuzs.nt
122 Which of the following function(s) is/are included in ctype.h header file?
► isdigit(int c)
► isxdigit(int c )
► tolower(int c)
► All of the above Pg 188
124 Both compiler and interpreter are used to translate program into machine language
code.
► True
► False
128 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) ;
130 The object _______________may be used both for file input and file output
► fstream, Pg 199
► ifstream,
► ofstream,
► none of the given options.
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
Suppose the pointer yptr is pointing to the first element of the array y
and the size of array is 10. Can we increment the yptr up to 12 times?
And what will happen?
(i) An array day is declared as: int day[] = {1,
2, 3, 4, 5, 6, 7}; How many elements does
array 'day' has?
CS201 Grand Quizz Preparation Spring 2020 18
(ii) If the declaration is changed as: int day[7] = {1,
2, 3, 4, 5, 6, 7}; How many elements does array
'day' has?
In both the case array day has the 7 elements.
149.Let suppose
Union intorDouble{
Int ival;
Double charvar;
};
CS201 Grand Quizz Preparation Spring 2020 19
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
When number of iterations known we use for loop otherwise we will use while loop
152.Data Size of the file is always___________ the actual size of the file.
►Greater than
►Equal to
►Less than or equal to
►None of the above Pg 216
Similarly in case of files, the space occupied by a file (file size) can be more than
the actual data length of the file itself.
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
161.The compilers and interpreters also belong to the System Software category.
CS201 Grand Quizz Preparation Spring 2020 21
►True Pg 11
►False
When 50 divides any number, the remainder will always be less than 50.
► $
► &
► #
► _
168.The members of a class declared with the keyword struct are _____________by default.
► static
► private
► protected
► public
169.We cannot use ______________ pointer for storing and reading data from it.
► NULL
► integer
► double
► zero
181. Consider the following code segment. Which of the following will be called
while executing code at line 2? String s1 , s2; s1 = s2 ;
► Copy constructor
CS201 Grand Quizz Preparation Spring 2020 22
► Default constructor
► Assignment operator
► Parameterized constructor
184. From the following; which on is the correct syntax of an array declaration: array size
is 5 and it is of float data type?
188. When the if statement consists more than one statement then enclosing these
statement in curly braces is,
► Not required
► Good programming
► Relevant
► Must
189. __________ allow us to have a memory location and use it as int or char interchangeably
► structures
► union
► construct
CS201 Grand Quizz Preparation Spring 2020 23
► None of the given
191. _______________function give the position of the next character to be read from that
file.
► tellp()
► tellg()
► seekg()
► seekp()
193. In order to get the right most digit of a number, we divide this number by 10 and take its
► Remainder
► Quotient
► Divisor
► None of the given options
► 15
► 18
► 16
► 17
► ctype.h
► iostream.h
► string.h
► None of the given
197. ____________________ Returns true if c is a digit or a letter and false otherwise.
► Reference
► Value
► Type
► Data
► struc
► struct
► structure
► None of the given
► analysis phase
► design phase
► Implementation phase
► None of the given
204. While developing a program; should we think about the user interface?
► Yes
► No
205. What will be the result of arithmetic expression 5+25/5*5?
► 45
► 6
► 30
► 9
► Bit-wise OR
► Exclusive OR
► AND Operator
► NOT operator
208. C++ is a_________________ language.
► High level
► Low level
► Machine
► Fourth Generation
209. 12 & 8 = (1000) 2 =________. & is used to AND two numbers bit-wise
► 4
► 8
► 6
► 12
211. What will be the value of ‘a’ and ‘b’ after executing the following statements? int a
= 9; int b = a++; cout<<
► 10,9
► 9,10
► 9,9
► 10,10
212. 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
► *
► +
► –
► None of the given
215. ______________ transfers the executable code from main memory to hard disk.
CS201 Grand Quizz Preparation Spring 2020 26
► Loader
► Debugger
► Compiler
► Linker
216. When the logical operator OR (||) combine two expressions exp1 and exp2 then the
result will be false only,
217. 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
218. 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
226. Function implementation of friend function must be defined outside the class.
► True
► False
227. The default scope for members of structures is public whereas the default
visibility for class members is private.
► True
► False
228. The operator function of << and >> operators are always the member function of a class.
► True
► False
230. Which of the following array is the most suitable for storing a matrix structure
► Single-dimensional array
► Two-dimensional array
► Three-dimensional array
► Four-dimensional array
main(){
int x = 5 ;
{
int x = 4 ;
cout << x << “,” ;
}
cout << x ;
}
► 5, 5
► 4, 4
► 4, 5
► 5, 4
232. Single line comments explaining code would be preceded like in the following example.
► /*
► //
►/
► //*
233. Which of the following will be the correct function call for function prototype
given below?
int func (int &);
► func(int num);
► func(&num);
► func(num);
► func(*num);
CS201 Grand Quizz Preparation Spring 2020 28
234. 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
► Address of variable, value of variable
235. Which of the following operator the compiler overloads for objects by default?
► + operator
► operator
► = operator
► == operator
237. The operator function will be implemented as _____, if both objects (obj1, obj2) are
passed as arguments to - operator in the statement given below.
obj3 = obj1 - obj2;
► friend function
► member function
► non-member function
► either non-member or friend function
238. The input/output streams cin and cout are ________ therefore have _______.
► Structures, function
► Objects, member functions
► Functions, objects
► None of the given options
241. Which of the following is used for allocating space for static variables?
► Heap
► Static storage area
► Free store
► Stack
CS201 Grand Quizz Preparation Spring 2020 29
242. Templates provide way of abstracting ______________ information.
► type
► data
► method
► access
243. A pointer is a special type of variable that contain ___________
► Memory Address
► Data values
► Both Values and Memory
► None of given of options
246. Assignment operator is used to initialize a newly declared object from existing object
► True
► False
247. The operator function for << (stream insertion) >> and stream extraction must be
► Member function of class
► Non-member function of class
► Both member and non-member function
► None of the given options
250. Which of the following array is the most suitable for storing a matrix structure?
► Single-dimensional array
► Two-dimensional array
► Three-dimensional array
► Four-dimensional array
11 bytes for 11characters of word programming and 1 for '\n'
252. The prototype of friend functions must be written ____ the class and its definition must
be written ____
► inside, inside the class
► inside, outside the class
► outside, inside the class
► outside, outside the class
253. 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
1): when we specify the buffer size, normally the operating system or compiler does this
for us. A typical size of buffer is 512 bytes. When the information is of 512 byte size,
output will take place. But in the program, we may want at some point that whatever is in
the buffer, show them. For that purpose the normal mechanism is flush. Flush the stream.
The flush command forces the data from the buffer to go to its destination which is
normally a screen or file and make the buffer empty. Lec 34
257. 12 & 8 = (1000) 2 =________. & is used to AND two numbers bit-wise
Select correct option:
► 4
► 8
► 6
► 12
260. The reserved words public and private comes under the category
► :structures
► :strings
► :accessibility modifiers
► :types of functions
261. 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
► Constructor is called first before allocating memory
262. 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
264. The operator function of << and >> operators are always the member function
of a class.
► True
► False
265. A template function must have at least ---------- generic data type
► Zero
► One
► Two
► Three
266. If we do not mention any return_value_type with a function, it will return an _____
value.
► int
► void
► double
► float
267. Suppose a program contains an array declared as int arr[100]; what will be the
size of array?
►0
► 99
► 100
► 101
268. The name of an array represents address of first location of array element.
CS201 Grand Quizz Preparation Spring 2020 32
► True
► False
270. Which of the following option is true about new operator to dynamically
allocate memory to an object?
271. new and delete are _____ whereas malloc and free are _____.
► Functions, operators
► Classes, operators
► Operators, functions
► Operators, classes
272. Like member functions, ______ can also access the private data members of a class.
► Non-member functions
► Friend functions
► Any function outside class
► None of the given options
273. Which of the following statement is best regarding declaration of friend function?
► Friend function must be declared after public keyword.
► Friend function must be declared after private keyword.
► Friend function must be declared at the top within class definition.
► It can be declared anywhere in class as these are not affected by the public
and private keywords.
274. The operator function overloaded for an Assignment operator (=) must be
► Non-member function of class
► Member function of class
► Friend function of class
► None of the given options
275. 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
276. 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
► Non-member function
► Friend function
► None of the given options
CS201 Grand Quizz Preparation Spring 2020 33
277. 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 ++() ;
► Class-name operator ++(int) ;
284. We can change a Unary operator to Binary operator through operator overloading.
► False
► True
i. course[] = {‘p’, ’r’, ’o’, ’g’, ’r’, ’a’, ’m’, ’m’, ’i’, ’n’, ’g’};
ii. course[] = ‘programming’ ;
iii. course[12] = “programming” ;
iv. course = “programming” ;
288. 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
289. What will be the correct syntax to assign an array named arr of 5 elements to a
pointer ptr?
► *ptr = arr ; ptr = arr ;
► *ptr = arr[5]
► ptr = arr[5] ; ►
290. The variables having a name, type and size are just like empty boxes.
► False
► True
292. Like member functions, ______ can also access the private data members of a class.
► Non-member functions
► Friend functions
► Any function outside class
► None of the given options
► nested
► overloaded
► grouped
CS201 Grand Quizz Preparation Spring 2020 35
► none of them