Monday 1 June 2020

C Programming and Problem Solving MCQ

C Programming and Problem Solving

Questions 1 To 10









1.
What number will z in the sample code given below?
        int z, x=5, y= -10, a=4, b=2;
        z=x++ - --y *b/a;
(a)  5                       
(b)  6                       
(c)  10                     
(d)  11                    
(e)  12.

2.
Every C program consists  of __________ function(s).
(a)  Only one                                          
(b)  Only two                                    
(c)  One or two
(d)  One or many                                    
(e)  None of the above.

3.
What is the correct value to return to the operating system upon the successful completion of a program?

(a)  1                                                                                   
(b)  1                       
(c)  0                            
(d)  Programs do not return a value                                       
(e)  2.

4.
What is the only function all C programs must contain?

(a)  Start()                
(b)  System()                                         
(c)  Main()
(d)  Program()          
(e)  None of the above.

5.
Which of the following is not a correct variable type?

(a)  Float                 
(b)  Real                  
(c)  Int                     
(d)  Double              
(e)  Char.

6.
Which of the following correctly accesses the seventh element stored in foo, an array with 100 elements?

(a)  Foo[6];              (b)  Foo[7];              (c)  Foo(7);              (d)  Foo;                 (e)  Foo{ };

7.
Which of the following is a complete function?

(a)  Int funct();                                                                      
(b)  Int funct(int x) {return x=x+1;}
(c)  Void funct(int) {printf(“Hello");}                                        
(d)  Void funct(x) {printf(“Hello");}
(e)  None of the above.

8.
Which of the following is a not a keyword in C language?

(a)  Void                  
(b)  Volatile            
(c)  Sizeof               
(d)  Getchar             
(e)  Short.

9.
What is the return value of the following statement if it is placed in C program?

strcmp (“ABC”,”ABC”);

(a)  33                     
(b)  –1                     
(c)  1                       
(d)  Compilation error                              
(e)  0.

10.
Suppose the return type of function f is void. Which one of the following statements is true?

(a)   Function f does not contain a return statement
(b)   Function f does not have parameters
(c)   Function f returns a generic value
(d)   Function f does not work correctly
(e)   None of the above.




Answers

1.
Answer : (a)
Reason:  According to precedence of operators.
2.
Answer : (d)
Reason: 
3.
Answer : (c)
Reason:  After successful completion of a program  0 is returned to the operating system.
4.
Answer : (c)
Reason:  Since main() is the starting of a program execution.
5.
Answer : (b)
Reason:  real is not a variable type in C language.
6.
Answer : (a)
Reason:  Since array index starts with 0 in c language.
7.
Answer : (b)
Reason:  Since return type for the function is int and  in the function definition return statement is used by returning an integer value of x.
8.
Answer : (d)
Reason:  Getchar() is not a keyword in C language.
9.
Answer : (e)
Reason:  If the same statement is used in a C program  compilation error will occur.
10.
Answer : (c)
Reason:  Function returns a generic value.



C PROGRAMMING AND PROBLEM SOLVING QUESTIONS AND ANSWERS 11 TO 20

C Programming and Problem Solving

Questions 11 To 20


11.
Which command is used to skip the rest of a loop and carry on from the top of the loop again?
(a)  Break;               
(b)  Resume;                                          
(c)  Continue;          
(d)  Skip                  
(e)  None of the above.

12.
How would you declare a constant of 5 called "MYCONST"?
(a)  constant MYCONST = 5;                  
(b)  int myconst = 5;
(c)  #define MYCONST 5                        
(d)  constant = 5
(e)  #define MYCONST=5.

13.
Which of the following is not a storage class in C?
(a)  Auto                  
(b)  Struct                
(c)  Extern               
(d)  Static                
(e) Register.

14.
What is the fifth element of the array int a[3][4]={1,2,3,4,5,6,7,8,9,10,11}; ?
(a)  4                       
(b)  6                       
(c)  5                       
(d)  7                       
(e)  3.

15.
What is the output of the following program?   
#include<stdio.h>
int c [10]={1,2,3,4,5,6,7,8,9,10};  
       main ()
      { int a,b=0;
        for(a=0;a<10;++a)
if(c[a]%2= =1)
 b+=c[a];
 printf (‘%d”, b);}

(a)  20                     
(b)  24                                                   
(c)  25                    
(d)  30                     
(e)  None of the above.

16.
int a [5]={1,2,3}  what is the value of  a[4]?
(a)  3                       
(b)  1                       
(c)  Garbage value  
 (d)  0               
(e)  2.

17.
Information will be passed to the function via special identifier is called
(a)  Arguments                                       
(b)  Parameters        
(c)  Both (a) and (b) above                    
(d)  Elements                                         
(e)  Characters.

18.
Which of the following function returns multiple values?
(a)  Printf( )              
(b)  Scanf( )                                           
(c)  Printf( ) & scanf( )
(d)  Getch( )            
(e)  None of the above
.
19.
What is the associatively of the conditional operator?
(a)  Left to Right                                    
(b)  Right to Left                          
(c) Top to Bottom
(d)  Bottom to Top                                 
(e)  None of the above.

20.
What is the output of the following statement?
Printf(“%v”, 12);
(a)  12                                                   
(b)  12.0                                                
(c)  %v                         
(d)  Garbage value                                 
(e)  None of the above.

Answers


11.
Answer : (c)
Reason:  Continue statement is used to skip the rest of the statements in a loop and carry from the top of the loop again.
12.
Answer : (c)
Reason:  #define statement is used.
13.
Answer : (b)
Reason:  Struct is not a storage class in C language.
14.
Answer : (c)
Reason:  In the two dimensional array representation there will be 3 rows and 4 columns. The elements are stored in row wise first. Hence the fifth element is 5.
15.
Answer : (c)
Reason:  The remainder is 1 for only 1, 3, 5, 7, 9 numbers and the sum of these four numbers is 25.
16.
Answer : (c)
Reason:  In the fourth location of an array contains garbage value since we are storing only three elements in the first three locations.
17.
Answer : (c)
Reason:  We can call them as function arguments or parameters.
18.
Answer : (b)
Reason:  Scanf() function returns multiple values.
19.
Answer : (b)
Reason:  Right to left is the operator associativity  for the conditional operator.
20.
Answer : (c)
Reason:  The control string %v is printed.




C PROGRAMMING AND PROBLEM SOLVING QUESTIONS AND ANSWERS 21 TO 30

C Programming and Problem Solving

Questions 21 To 30



21.
What is the output of the following statements?
int I = 0;
printf(“%d %d ”, I, I++);

(a)  01                     (b)  10                     (c)  00                     (d)  11                  (e)  Junk value.
22.
What is the output of the following statements?
for(I = 10; I++; I<15)
 printf(“%d”, I);
(a)  1011121314                                     (b)  101112131415
(c)  910111213                                       (d)  It will go to infinite loop
(e)  None of the above.
23.
The size of an int must be greater than or equal to that of a _________
(a)  Long int             (b)  Short int            (c)  Float                 (d)  Double              (e)  Char.
24.
Which of the following is a LOOP statement of a C language?
(a)  Repeat-Until                                     (b)  For                                         (c)  While-Do                
(d)  Do-while                                          (e)  Both (b) and (d) above.
25.
What is the output of the following statements?
int b = 5, c = 15, d = 8, e = 8,a;
a = b>c?c>d?12:d>e?13:14:15;
printf(“%d”, a);
(a)  13                     
(b)  14                     
(c)  15                     
(d)  Garbage value              
(e)  12.
26.
What is the output of the following piece of code?
for (i = 0; i<10; i++);
printf(“%d”,i);
(a)  10                     (b)  0123456789       (c)  Syntax error       (d)  0               (e)  Infinite loop.
27.
What value does srarray [5][4][0] in the sample code below contain?
         int srarray[2][2][2] = {1,2,3,4,5,6,7,8,9,10,11,12};
(a)  3                       (b)  5                                                     (c)  7                      
(d)  9                       (e)  Garbage value.
28.
What number would be shown on the screen after the following statements of C are executed?
char ch; int I; ch=’G’; I=ch-‘A’;
pirntf(“%d”, I);
(a)  6                       (b)  7                       (c)  8                       (d)  5                      
(e)  9.
29.
Which of following is not a valid name for a C variable?
(a)  Hairaj                                               (b)  Hello_raj                                         
(c)  Hello raj
(d)  Both (a) and (b) above                     (e)  None of the above.
30.
What value would be stored in an integer variable “i” as a result of the following expression?
int i, j = 3; i = 4 + 2 * j/(j-1);
(a)  1                       (b)  7                       (c)  9                       (d)  8                      
(e)  2.



Answers


21.
Answer : (b)
Reason:  Since the evaluation is from right to left.
22.
Answer : (d)
Reason:  Since the condition is always true it will go to infinite loop.
23.
Answer : (b)
Reason:  The size of int is grater than or equal to short int.
24.
Answer : (e)
Reason: 
25.
Answer : (c)
Reason: 
26.
Answer : (a)
Reason:  After 10 iterations for loop terminated and the result is 10.
27.
Answer : (e)
Reason:  Since that many number  of rows and columns are not actually represented the garbage value is printed.
28.
Answer : (a)
Reason:  Since the ASCII value of G is 71 and the garbage value if A is 65 and hence the difference is 6.
29.
Answer : (c)
Reason:  No spaces are allowed in the variable  names.
30.
Answer : (b)
Reason:  According to operator precedence rule the output is 7.

No comments:

Post a Comment

MCQ Question Bank Microsoft PowerPoint