

MCQOPTIONS
Saved Bookmarks
This section includes 565 Mcqs, each offering curated multiple-choice questions to sharpen your Technical Programming knowledge and support exam preparation. Choose a topic below to get started.
101. |
Consider the following program fragmenti = 6720; j = 4;while ((i % j) == 0){i = i / j;j = j + 1;}on termination j will have the value |
A. | 4 |
B. | 8 |
C. | 9 |
D. | 6720 |
Answer» D. 6720 | |
102. |
Consider the functionint fun(x: integer){ If x > 100 then fun = x – 10; else fun = fun(fun(x + 11));}For the input x = 95, the function will return |
A. | 89 |
B. | 90 |
C. | 91 |
D. | 92 |
Answer» D. 92 | |
103. |
Match the following list : List – I List – II(a)DIMENSION(i)Operator(b)enum(ii)Macro(c)new(iii)Data type(d)# define(iv)Non - executableCorrect code are: |
A. | (a) – (iii), (b) – (i), (c) – (ii), (d) – (iv) |
B. | (a) – (i), (b) – (ii), (c) – (iv), (d) – (iii) |
C. | (a) – (iv), (b) – (iii), (c) – (i), (d) – (ii) |
D. | (a) – (ii), (b) – (iv), (c) – (iii), (d) – (i) |
Answer» D. (a) – (ii), (b) – (iv), (c) – (iii), (d) – (i) | |
104. |
Consider the following ANSI C program.#includeint main(){int arr[4][5];int i, j;for(i =0; i<4; i++){for (j =0; j<5; j++){arr [i][j] = 10*i + j;}}print("%d", *(arr[1] + 9));return 0;}What is the output of the above program? |
A. | 14 |
B. | 20 |
C. | 30 |
D. | 24 |
Answer» E. | |
105. |
In C programming body of a switch statement must consist of: |
A. | A case labeled statement |
B. | default labeled statement |
C. | A statement |
D. | A loop |
Answer» B. default labeled statement | |
106. |
Consider the following function:int unknown(int n) {int i, j, k=0;for (i = n/2; i <= n; i++) for (j = 2; j <= n; j = j*2)k = k + n/2;return (k);}The return value of the function is |
A. | Θ(n2) |
B. | Θ(n2log n) |
C. | Θ(n3) |
D. | Θ(n3logn) |
Answer» C. Θ(n3) | |
107. |
Assuming a 2-byte integer which of the following is the correct output for the program givenbelow?# include int main (){printf ( ”% x\n”, -1 << 3);return 0;} |
A. | 0 0 0 0 |
B. | f f f f |
C. | f f f 8 |
D. | 0 0 0 8 |
Answer» D. 0 0 0 8 | |
108. |
Match the following Lists if you execute a command-line program “test” in ‘C’ as below:test string 1 string 2.List-I List-II(a) argc(i) base address of ‘test’(b) argv[0](ii) number of arguments + 1(c) argv[1](iii) base address of string 2(d) argv[2](iv) base address of string 1 Correct code are: |
A. | a-ii, b-i, c-iv, d-iii |
B. | a-i, b-ii, c-iv, d-iii |
C. | a-ii, b-i, c-iii, d-iv |
D. | a-iv, b-iii, c-ii, d-i |
Answer» B. a-i, b-ii, c-iv, d-iii | |
109. |
If only one memory location is to be reserved for a class variable, no matter how many objects are instantiated, then the variable should be declared as _____. |
A. | extern |
B. | static |
C. | volatile |
D. | const |
Answer» C. volatile | |
110. |
Consider the following function implemented in C:void printxy(int x, int y) {int *ptr;x = 0;ptr = &x;y = *ptr;*ptr = 1;printf ("%d, %d", x, y) ;}The output of invoking printxy(1, 1) is |
A. | 0, 0 |
B. | 0, 1 |
C. | 1, 0 |
D. | 1, 1 |
Answer» D. 1, 1 | |
111. |
A program structure that permits repeated operation of a particular sequence of instructions is known as |
A. | subroutine |
B. | loop |
C. | module |
D. | microprogramming |
Answer» C. module | |
112. |
______ data type specifies an empty set of values. |
A. | Double |
B. | Void |
C. | Float |
D. | Char |
Answer» C. Float | |
113. |
Match the columns. 1. \a a. backslash 2. \b b. alarm 3. \n c. backspace 4. \\ d. New line |
A. | 1 - c, 2 - b, 3 - d, 4 - a |
B. | 1 - b, 2 - c, 3 - a, 4 - d |
C. | 1 - b, 2 - d, 3 - c, 4 - a |
D. | 1 - b, 2 - c, 3 - d, 4 - a |
Answer» E. | |
114. |
______ provides an alternative name for standard types. |
A. | Typestd |
B. | Typealt |
C. | All options are wrong |
D. | Typedef |
Answer» E. | |
115. |
In ______ insertion takes place at the rear end. |
A. | Queue |
B. | Stack |
C. | Sort |
D. | Link list |
Answer» B. Stack | |
116. |
Consider the following ‘C’ Program:# include int main (){int max, i;scanf (“%d”, & max);int a[max];for (i=1; i{scanf (“%d”, a[i]);printf(“%d \n”, a[i]);}return 0;} Which of the following statements are correct about the ‘C’ program given above ?(a) The code is correct and runs successfully(b) The code is erroneous since the statement declaring array is invalid(c) The code is erroneous since the subscript for array used in ‘for’ loop is in the range 1 to max - 1(d) The code is erroneous since the type declaration statement int a [max]; is done after scanf() |
A. | (a) and (c) |
B. | (b) and (c) |
C. | (b) and (d) |
D. | (c) and (d) |
Answer» D. (c) and (d) | |
117. |
Consider the following recursive C function. Void get (int n) { if (n<1) return; get (n-1) ; get (n-3) ; printf (‘’%d’’, n); }If get (6) function is being called in main() then how many times will the get ( ) function be invoked before returning to the main() ? |
A. | 15 |
B. | 25 |
C. | 35 |
D. | 45 |
Answer» C. 35 | |
118. |
Consider the following program fragmentif (a > b)if (b > c)s1;else s2;s2 will be executed if |
A. | a < = b |
B. | b > c |
C. | b > = c and a < = b |
D. | a > b and b < = c |
Answer» E. | |
119. |
______ in values processing of all elements in an array one by one. |
A. | Merging |
B. | Insertion |
C. | Searching |
D. | Traversal |
Answer» E. | |
120. |
Consider the following C function.void convert (int n) {if (n < 0)printf (“ % d”, n);else {convert(n / 2);printf (“ % d”, n % 2);}}Which one of the following will happen when the function convert is called with any positive integer n as argument? |
A. | It will print the binary representation of n and terminate |
B. | It will print the binary representation of n in the reverse order and terminate |
C. | It will print the binary representation of n but will not terminate |
D. | It will not print anything and will not terminate |
Answer» E. | |
121. |
Consider the following C code segmentint f (int x){if (x<1) return 1;else return ( f{x-1) + g(x) );}int g (int x){ if (x< 2) return 2;else return ( f(x-1) + g(x/2)); }Of the following, which best describes the growth of f(x) as a function of x ? |
A. | Linear |
B. | Exponential |
C. | Quadratic |
D. | Cubic |
Answer» C. Quadratic | |
122. |
Identify the output of the following C code snippet.#include#include#includeint main(){fork();printf ("Test 91!\n");return 0;} |
A. | Test 91! Test 91! |
B. | Test 91! |
C. | Hello 91! |
D. | Test 91!Test 91! |
Answer» E. | |
123. |
Consider the following recursive Java function f that takes two long arguments and returns a float value:public static float f (long m, long n) {float result = (float)m / (float)n;if(m < 0 | n < 0) return 0.of;else result - = f(m * 2,n * 3);return result ;}Which of the following real values best approximates the value of f (1, 3) ? |
A. | 0.2 |
B. | 0.4 |
C. | 0.6 |
D. | 0.8 |
Answer» B. 0.4 | |
124. |
Consider the following C code:#include int *assignval(int *x, int val) {*x = val;return x;}void main () {int *x = malloc(sizeof(int));if (NULL == x) return;x = assignval (x, 0);if (x) {x = (int *) malloc (sizeof(int));if(NULL == x) return;x = assignval (x, 10);}printf(“%d\n”, *x);free(x);}The code suffers from which one of the following problems: |
A. | Compiler error as the return of malloc is not typecast appropriately |
B. | Compiler error because the comparison should be made as x == NULL and not as shown |
C. | Compiles successfully but execution may result in dangling pointer |
D. | Compiles successfully but execution may result in memory leak |
Answer» E. | |
125. |
Consider the following code segment:int x=22, y=15;x = (x>y) ? (x + y) : (x-y);What will be the value of x after the code is executed? |
A. | 22 |
B. | 37 |
C. | 7 |
D. | 37 and 7 |
Answer» C. 7 | |
126. |
Determine the output of the given program.#include int main(){int i, a[4] = {3, 1, 2, 4}, result;result = a[0];for(i = 1; i < 4; i++){if(result > a[i])continue;result = a[i];}printf("%d", result);return 0;} |
A. | 1 |
B. | 4 |
C. | 3 |
D. | Error |
Answer» C. 3 | |
127. |
In which of the following looping constructs of the ‘C’ language, the body of the loop is executed at least once? |
A. | while construct |
B. | for construct |
C. | Both ‘for’ and ‘while’ constructs |
D. | do-while construct |
Answer» E. | |
128. |
In the context of while loop do while loop in C++, which of the following is not true? |
A. | Both the loops are repetitive in nature |
B. | Both are conditional loops |
C. | Both will be executed at least once |
D. | Both are terminated when the condition become false |
Answer» D. Both are terminated when the condition become false | |
129. |
Consider the code segment written below in C++ :if (count<10) // if#1if((count%4)==2) // if#2count<<”condition:white\n”;else //(Indentation is wrong)count<<”condition is:tan\n”;There are 2 if statements and one else.To which if, the else statement belong? |
A. | It belongs to if#1 |
B. | It belongs to if#2 |
C. | It belongs to both the if statements |
D. | It is independent |
Answer» C. It belongs to both the if statements | |
130. |
‘ptrdata’ is a pointer to a data type. The expression *ptrdata++ is evaluated as (in C++): |
A. | *(ptrdata++) |
B. | (*ptrdata)++ |
C. | *(ptrdata)++ |
D. | Depends on compiler |
Answer» B. (*ptrdata)++ | |
131. |
Consider the following program in C language:#include main(){ int i; int *pi = &i; scanf(“%d”,pi); printf(“%d\n”, i+5);}Which one of the following statements is TRUE? |
A. | Compilation fails |
B. | Execution results in a run-time error. |
C. | On execution, the value printed is 5 more than the address of variable i. |
D. | On execution, the value printed is 5 more than the integer value entered. |
Answer» E. | |
132. |
Consider the following C code. Assume that unsigned long int type length is 64 bits.unsigned long int fun (unsigned long int n) {unsigned long int i, j = 0, sum = 0 ;for (i = n; i > 1 ; i = i/2)j++ ;for ( ; j > 1 ; j = j/2)sum++ ;return (sum) ;}The value returned when we call fun with the input 240 is |
A. | 4 |
B. | 5 |
C. | 6 |
D. | 40 |
Answer» C. 6 | |
133. |
Determine the output of the following.#includeint main(){int a[6]={1,2,3,4,5,6};switch(sizeof(a)){case1:case2:case3:case4:case5:printf(“hello”);break;}printf(“HI”);return 0;} |
A. | Hello |
B. | HI |
C. | helloHI |
D. | helloHI |
Answer» C. helloHI | |
134. |
Assume X and Y are non-zero positive integers. consider the following pseudo code fragment:while X <> Y doif X > y thenX <- X - YelseY <- Y - Xendifendwhileprint (X)What is the code doing? |
A. | It computes the LCM of two numbers. |
B. | It divides the largest numbers by the smaller. |
C. | It finds the smallest of two numbers. |
D. | It computes the GCD of two numbers. |
Answer» E. | |
135. |
Consider the following C program.# includestruct Ournode { char x, y, z ;} ;int main ( ) { struct Ournode p = {‘1’, ‘0’, ‘a’ + 2} ; struct Ournode *q = &p; printf (“%c, %c”, *( (char*) q + 1) , *( (char*) q + 2) ) ; return 0 ;} The output of this program is: |
A. | 0, c |
B. | 0, a + 2 |
C. | ‘0’, ‘a + 2’ |
D. | ‘0’, ‘c’ |
Answer» B. 0, a + 2 | |
136. |
In ‘C programming’, when fopen () is not able to open a given file due to any reason, it retries |
A. | |
B. | EOF |
C. | Compiler dependent value |
D. | Runtime Error |
Answer» B. EOF | |
137. |
Consider the following statements# define hypotenuse (a, b) sqrt (a * a + b * b);The macro call hypotenuse (a + 2, b + 3); |
A. | Finds the hypotenuse of a triangle with sides a + 2 and b + 3 |
B. | Finds the square root of (a + 2)2 + (b + 3)2 |
C. | Is invalid |
D. | Find the square root of 3 * a + 4 * b + 5 |
Answer» E. | |
138. |
Consider the following C declarationstruct {short s[5];union {float y;long z;}u;}t;Assume that objects of type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, is |
A. | 22 bytes |
B. | 18 bytes |
C. | 14 bytes |
D. | 10 bytes |
Answer» C. 14 bytes | |
139. |
Predict the output of the following C code:#include int main(){enum ball {tennis, base, basket ,foot};enum sports {cricket, tennis};int a = 0;for(a = tennis; a <= foot; a++){printf("%d ", a);}return 0;} |
A. | cricket, tennis |
B. | compiler error |
C. | foot, basket, base, tennis |
D. | tennis, base, basket; foot |
Answer» C. foot, basket, base, tennis | |
140. |
______ of an element shows its position in an array. |
A. | Data type |
B. | Index |
C. | Value |
D. | Name |
Answer» C. Value | |
141. |
Consider the following programmain(){int x = 1;printf (“%d”, (*char(char *)&x)) ;}Assuming required header files are included and if the machine in which this program is executed is little-endian, then the output will be |
A. | 0 |
B. | 99999999 |
C. | 1 |
D. | unpredictable |
Answer» E. | |
142. |
Find the output of the following#includeint main(){int x=5, y=9;x=(x= x+y)-(y= x-y);printf("%d %d ", x, y);return 0;} |
A. | 14 5 |
B. | 9 5 |
C. | 5 9 |
D. | 5 14 |
Answer» C. 5 9 | |
143. |
Given the list of tasks in Col-A and list of data structure in Col-2) Identify the best match A B (a) Recursion (i) Binary tree (b) Scheduling (ii) stack (c) sorting (iii) Queue |
A. | a - (i), b - (iii), c - (ii) |
B. | a - (ii), b - (i), c - (iii) |
C. | a - (iii), b - (ii), c - (i) |
D. | a - (ii), b - (iii), c - (i) |
Answer» E. | |
144. |
Consider the following A NSI C program.#include int main( ){int i, j, count;count = 0;i = 0;for (j = -3; j <= 3; j++){if ((j >= 0) && (i++))count = count + j;}count = count + i;printf("%d", count);return 0;}Which one of the following options is correct? |
A. | The program will compile successfully and output 10 when executed. |
B. | The program will compile successfully and output 8 when executed. |
C. | The program will compile successfully and output 13 when executed. |
D. | The program will not compile successfully. |
Answer» B. The program will compile successfully and output 8 when executed. | |
145. |
Choose most appropriate option considering that gp and ip are declared as void * and int * respectively in C++: |
A. | gp - ip is a valid C++ statement |
B. | *ip - *gp is a valid C++ statement |
C. | Both A) and B) are valid statements |
D. | Neither A) nor B) are valid statements |
Answer» E. | |
146. |
Consider the ‘C’ statement printf (“%f”,(float) 7/5); It prints : |
A. | 1.0 |
B. | 1.4 |
C. | 2.0 |
D. | None of the above |
Answer» C. 2.0 | |
147. |
Assume the C++ definition : class circle : public point Which of the following is false.? |
A. | The colon (:) in the header of class definition indicates inheritance. |
B. | All the public and protected members of class 'circle' are inherited as public and protected members , respectively, into class 'point'. |
C. | the keyword 'public' indicates type of inheritance. |
D. | 'Point' is the base class and 'circle' is the derived class. |
Answer» C. the keyword 'public' indicates type of inheritance. | |
148. |
Consider the C program fragment below which is meant to divide x by y using repeated subtraction. The variables x, y, q and r are all unsigned int.While (r >= y) {r = r – y;q = q + 1;}Which of the following conditions on the variables x, y, q and r before the execution of the fragment will ensure that the loop terminates in a state satisfying the condition x == (y*q + r)? |
A. | (q == r) && (r == 0) |
B. | (x > 0) && (r == x) && (y > 0) |
C. | (q == 0) && (r == x) && (y > 0) |
D. | (q == 0) && (y > 0) |
Answer» D. (q == 0) && (y > 0) | |
149. |
Consider the following C program. void f(int, short);void main(){int i = 100;short s = 12;short *p = &s;__________ ; // call to f()}Which one of the following expressions, when placed in the blank above, will NOT result in a type checking error? |
A. | f(s,*s) |
B. | i = f(i, s) |
C. | f(i,*s) |
D. | f(i,*p) |
Answer» E. | |
150. |
Consider the following code segment:if (Y<0){X=-X;Y=-Y;}Z = 0; While (Y>0){Z=Z+X;Y=-1;}Assume that X,Y and Z are integer variables, and that X and Y have been initialized. which of the following best describes what this code segment does ? |
A. | Sets Z to be the sum X + Y |
B. | Sets Z to be the value of Y |
C. | Sets Z to be the absolute value of Y |
D. | Sets Z to be the product X*Y |
Answer» E. | |