Fundamentals of Data Structure MCQ's Set-2

 



1] What is the difference between the following 2 codes? 

 //Program 1
#include <stdio.h> 
int main() 
 { 
         int d, a = 1, b = 2; 
         d = a++ + ++b; 
         printf("%d %d %d", d, a, b); 
 } 

 //Program 2
#include <stdio.h> 
int main() 
 { 
         int d, a = 1, b = 2;
         d = a++ + ++b; 
         printf("%d %d %d", d, a, b); 
 } 

a) No difference as space doesn’t make any difference, values of a, b, d are same in both the case

b) No difference as space doesn’t make any difference, values of a, b, d are different 

c) Program 1 has syntax error, program 2 is not 

d) Program 2 has syntax error, program 1 is not

ANSWER : A


2] What is the output of this C code? 

 #include <stdio.h>   
 int main() 
 { 
         int a = 1, b = 1, c; 
         c = a++ + b; 
         printf("%d, %d", a, b); 
 } 

a) a = 1, b = 1 

b) a = 2, b = 1 

c) a = 1, b = 2 

d) a = 2, b = 2

ANSWER : B


3] What is the output of this C code? 

#include <stdio.h>  
int main() 
 { 
     int a = 1, b = 1, d = 1;
     printf("%d, %d, %d", ++a + ++a+a++, a++ + ++b, ++d + d++ + a++); 
 } 

a) 15, 4, 5 

b) 9, 6, 9 

c) 9, 3, 5 

d) 6, 4, 6

ANSWER : A


4] For which of the following, “PI++;” code will fail? 

a) #define PI 3.14 

b) char *PI = “A”; 

c) float PI = 3.14; 

d) Both (A) and (B) 

ANSWER : A


5] What is the output of this C code? 

 #include <stdio.h> 
int main() 
 { 
     int a = 10, b = 10; 
     if (a = 5) b--; 
     printf("%d, %d", a, b--); 
 } 

a) a = 10, b = 9 

b) a = 10, b = 8 

c) a = 5, b = 9 

d) a = 5, b = 8

ANSWER : C


6] What is the output of this C code? 

#include <stdio.h> 
int main() 
 {
     int i = 0; 
     int j = i++ + i; 
     printf("%d\n", j); 
 } 

a) 0 

b) 1 

c) 2 

d) Compile time error

ANSWER : A


7] What is the output of this C code? 

 #include <stdio.h> 
int main() 
 {
     int i = 2; 
     int j = ++i + i; 
     printf("%d\n", j); 
 } 

a) 6 

b) 5 

c) 4 

d) Compile time error

ANSWER : A


8] Comment on the output of this C code? 

#include <stdio.h> 
int main() 
     int i = 2; 
     int i = i++ + i; 
     printf("%d\n", i); 
 } 

a) = operator is not a sequence point 

b) ++ operator may return value with or without side effects 

c) it can be evaluated as (i++)+i or i+(++i) 

d) Both a and b 

ANSWER : A


9] #include is also called as ______ 

a) Preprocessor directive

 b) Inclusion directive 

c) File inclusion directive 

d) None of the mentioned

ANSWER : A


10] C preprocessors can have compiler specific features. 

a) true 

b) false 

c) Depends on the standard 

d) Depends on the platform

ANSWER : A


11] C preprocessor is conceptually the first step during compilation 

a) true 

b) false 

c) Depends on the compiler 

d) Depends on the standard

ANSWER : A


12] Preprocessor feature that supply line numbers and filenames to compiler is called? 

a) Selective inclusion 

b) macro substitution 

c) Concatenation 

d) Line control

ANSWER : D


13] A preprocessor is a program 

a) That processes its input data to produce output that is used as input to another program 

b) That is nothing but a loader 

c) That links various source files 

d) All of the mentioned

ANSWER : A


14] The sequence of allocation and deletion of variables for the following code is. 

 #include <stdio.h>   
 int main() 
 { 
      int a; 
         
             int b; 
         
 } 

a) a->b, a->b 

b) a->b, b->a 

c) b->a, a->b 

d) b->a, b->a

ANSWER : B


15] What is the output of this C code?

#include <stdio.h> 
void main() 
 { 
     int x = 3; 
         
             x = 4; 
             printf("%d", x); 
         } 
 } 

a) 4 

b) 3 

c) 0 

d) Undefined

ANSWER : A


16] What is the output of this C code? 

 #include <stdio.h>   
 int x = 5; 
 void main() 
 { 
     int x = 3; 
     m(); 
     printf("%d", x); 
 } 
 void m() 
 { 
     x = 8; 
     n(); 
 } 
 void n() 
 { 
     printf("%d", x); 
 } 

a) 5 3 

b) 3 8 

c) 8 5 

d) 8 3 

ANSWER : D


17] What is the output of this C code? 

 #include<stdio.h>  
 int x; 
 void main() 
 { 
     m(); 
     printf("%d", x); 
 } 
 void m() 
 { 
     x = 4; 
 } 

a) 0 

b) 4 

c) Compile time error 

d) Undefined

ANSWER : B


18] What is the output of this C code? 

 #include<stdio.h>  
 static int x = 5; 
 void main() 
 { 
     int x = 9; 
         {
                x = 4; 
         
   printf("%d", x); 
 } 

a) 9 

b) 5 

c) 4 

d) 0

ANSWER : C


19] What is the output of this C code

 #include<stdio.h>   
void main() 
 { 
     {
         int x = 8; 
     } 
   printf("%d", x); 
 }

a) 8 

b) 0 

c) Undefined 

d) Compile time error

ANSWER : D


20] What is the output of this C code? 

#include<stdio.h> 
void main() 
 { 
     int x = 1, y = 0, z = 5;
     int a = x && y || z++; 
     printf("%d", z); 
 } 

a) 6 

b) 5 

c) 0 

d) Varies

ANSWER : A











Popular Posts