Fundamentals of Data Structure MCQ's Set-1

 



1] Which of the following is NOT a valid variable name declaration? 

a) int _a3; 

b) int a_3; 

c) int 3_a; 

d) int _3a

ANSWER : C


2] Variable names beginning with underscore is not encouraged. Why? 

a) It is not standardized 

b) To avoid conflicts since assemblers and loaders use such names 

c) To avoid conflicts since library routines use such names 

d) To avoid conflicts with environment variables of an operating system 

ANSWER : C


3] All keywords in C are in 

a) LowerCase letters 

b) UpperCase letters 

c) CamelCase letters 

d) None

ANSWER : A


4] Variable name resolving (number of significant characters for uniqueness of variable) depends on 

a) Compiler and linker implementations 

b) Assemblers and loaders implementations 

c) C language 

d) None 

ANSWER : A


5] Which of the following is not a valid C variable name? 

a) int number; 

b) float rate; 

c) int variable_count; 

d) int $main;

ANSWER : D


6] Which of the following is true for variable names in C? 

a) They can contain alphanumeric characters as well as special characters 

b) It is not an error to declare a variable to be one of the keywords(like goto, static) 

c) Variable names cannot start with a digit 

d) Variable can be of any length 

ANSWER : C


7] What is the output of this C code?

#include <stdio.h>
int main() 
 {
         int c = 2 ^ 3; 
        printf("%d\n", c); 
 } 

a) 1 

b) 8 

c) 9 

d) 0

ANSWER : A


8] What is the output of this C code? 

#include <stdio.h>
int main() 
 { 
         unsigned int a = 10; 
         a = ~a; 
         printf("%d\n", a); 
 }
 

a) -9 

b) -10

c) -11

d) 10

ANSWER : C


9]. What is the output of this C code? 

#include <stdio.h> 
int main() 
 { 
         if (7 & 8) 
         printf("Honesty"); 
         if ((~7 & 0x000f) == 8) 
         printf("is the best policy\n"); 
 } 

a) Honesty is the best policy 

b) Honesty 

c) is the best policy 

d) No output

ANSWER : C


10] What is the output of this C code? 

#include <stdio.h>
int main() 
 { 
         int a = 2; 
         if (a >> 1) 
         printf("%d\n", a); 
 }

a) 0 

b) 1 

c) 2 

d) No Output. 

ANSWER : C


11] Comment on the output of this C code? 

#include <stdio.h>
int main() 
 { 
     int i, n, a = 4; 
     scanf("%d", &n); 
     for (i = 0; i < n; i++) 
     a = a * 2; 
 } 

a) Logical Shift left 

b) No output 

c) Arithmetic Shift right 

d) bitwise exclusive OR

ANSWER : B


12] What is the output of this C code? 

#include <stdio.h>
void main() 
 { 
     int x = 97; 
     int y = sizeof(x++); 
     printf("x is %d", x); 
 }

a) x is 97 

b) x is 98 

c) x is 99 

d) Run time error

ANSWER : A


13] What is the output of this C code? 

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

a) 3 2 3 

b) 2 2 3 

c) 3 2 2 

d) 2 3 3

ANSWER : D


14] What is the output of this C code? 

#include <stdio.h>
void main() 
    int x = 4; 
    int *p = &x; 
    int *k = p++; 
    int r = p - k; 
    printf("%d", r); 

a) 4 

b) 8 

c) 1 

d) Run time error

ANSWER : C


15] What is the output of this C code? 

#include <stdio.h> 
int main() 
 { 
     int x = 2, y = 0;
     int z = (y++) ? y == 1 && x : 0;
     printf("%d\n", z); 
     return 0; 
 } 

a) 0 
b) 1 
c) Undefined behaviour 
d) Compile time error

ANSWER : A


16] What is the output of this C code? 

#include <stdio.h> 
int main() 
 { 
     int x = 1;   
     int y = x == 1 ? getchar(): 2; 
     printf("%d\n", y); 
 } 

a) Compile time error 

b) Whatever character getchar function returns 

c) Ascii value of character getchar function returns 

d) 2

ANSWER : C


17] What is the output of this C code? 

#include <stdio.h> 
int main() 
 {
     int x = 1; 
     short int i = 2; 
     float f = 3; 
     if (sizeof((x == 2) ? f : i) == sizeof(float)) 
         printf("float\n"); 
     else if (sizeof((x == 2) ? f : i) == sizeof(short int)) 
         printf("short int\n"); 
 }

 a) float 

b) short int 

c) Undefined behaviour 

d) Compile time error

ANSWER : A


18]What is the output of this C code? 

#include <stdio.h> 
int main() 
     int a = 2; 
     int b = 0; 
     int y = (b == 0) ? a :(a > b) ? (b = 1): a; 
     printf("%d\n", y); 
 } 

a) Compile time error 

b) 1 

c) 2 

d) Undefined behaviour

ANSWER : C


19]What is the output of this C code? 

#include <stdio.h> 
int main() 
 { 
     int y = 1, x = 0;
     int l = (y++, x++) ? y : x; 
     printf("%d\n", l); 
 } 

a) 1 

b) 2 

c) Compile time error 

d) Undefined behaviour

ANSWER : A


20] The code snippet below produces 

#include <stdio.h> 
void main() 
 { 
     1 < 2 ? return 1 : return 2; 
 } 

a) returns 1 

b) returns 2 

c) Varies 

d) Compile time error

ANSWER : D








Popular Posts