C Programming and Problem Solving Questions and Answers 71 to 80

C Programming and Problem Solving

Questions 71 to 80



71.
Consider the following code in a   C program.
       struct   custom {
                                    int acct_no;
                                    float balance;
       } customer,*pc=&customer;
 customer’s acct_no  can be accessed by

(a)  customer.acct_no                            (b)  pc->acct_no
(c)  (*pc).acct_no                                   (d)  Both (a) and (b)                  (e)  (a),(b) and  (c).
72.
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.
73.
Which of the following is a not a keyword in C language.
(a)   void                 (b) volatile               (c) sizeof                 (d) getchar              (e) short.
74.
What is the following code’s output if choice = ‘R’?
      
switch(choice)
{
              case   ‘R’  : printf( “RED ”);
              case   ‘W’ : printf( “WHITE ”);
              case   ‘B’  : printf( “BLUE ”);
              default      : printf( “ERROR ”);
                             break;
       }
(a)  RED                                                (b)  RED WHITE BLUE ERROR
(c)  RED ERROR                                   (d)  RED WHITE BLUE
(e)  ERROR.
75.
The for statement which can precede a loop to be executed 50 times or till  a boolean variable “found” becomes false is given by ( let true, false are boolean constants )
(a)   for(  i=0;  i<= 50  && found==true;  i++ )
(b)   for(  i=0;  i<= 50  found==true;  i++ )
(c)   for(  i=0;  i<= 50  found==false;  i++ )
(d)   for(  i=0;  i<= 50  && found==false;  i++ )
(e)   for(  i=0;  ++i<= 50  found==false; 
76.
The function fprintf is used in the program
(a)   When too many printf calls have been used in the program
(b)   In place of printf, as it uses more memory
(c)   When the output is to be printed on to a file
(d)   When the type of the variables to be printed are not known
(e)   If mixed data type variables are required to be printed on to the memory.
77.
If ASCII value of ‘x’ is 120, then what is the value of the H, if
                              H = (‘x’ – ‘w’ ) / 3;
(a)  1                       (b)  2                       (c)  4                       (d)  0                       (e)  3.
78.
Consider the following program fragment
              for(  c = 1, sum=0;   c <= 10;  c++ )
              {
                     scanf(“%d”, &x );
                     if( x < 0 ) continue;
                            sum += x;
              }
What would be the value of sum for the input  1, -1, 2, -2, 3, -3, 4, -4, 5, -5
(a)  0                       (b)  30                     (c)  10                     (d)  1                       (e)  15.
79.
What is the value of u1 and u2 for the following piece of code
              int   u1, u2, v = 3, *pv;
              u1 = 2 *(v + 5);
              pv = &v;
              u2 = 2 *(*pv + 5 );

(a)  u1 = 16,    u2 = 16                            (b)  u1 = 8,      u2 = 16
(c)  u1 = 16,    u2 = 3                              (d)  u1 = 8,      u2 = 3
(e)  u1 = 16,    u2 = 8.
80.
What will be the output of the following program if ‘e’ is the input to the program
              main( )
              {
                     int   lower, upper;
                     upper = getchar( );
                     upper = toupper( lower );
                     putchar( upper );
              }
(a)  53                     (b)  Nothing             (c)  e                       (d)  E                      (e)  Error.



Answers



71.
Answer : (e)
Reason : As all are valid
72.
Answer : (e)
Reason : strcmp returns 0 if both the strings are equal.
73.
Answer : (d)
Reason : Because getchar [ getchar( )] is a function in C
74.
Answer : (b)
Reason : As the first option is matching, the cases are evaluated till the break statement is encountered or end of switch statement is encountered.
75.
Answer : (a)
Reason : Because b, c, e are invalid and d is not correct one
76.
Answer : (c)
Reason : According to the definition of fprintf( )
77.
Answer : (d)
Reason : Because  ‘x’-‘w’ = 120-119. And hence 1/3 results in 0( integer division)
78.
Answer : (e)
Reason : It is summation of 1+2+3+4+5 as continue statement is going to be executed for every input of -1, -2, -3, -4, -5.
79.
Answer : (a)
Reason : Because of the pointer assignment ( pv = &v causes *pv = 3 )
80.
Answer : (b)
Reason : Its equivalent to puchar(0)



<< Prev 1...  2...  3...  4...  5...  6...  7...  8...  9...  10...  11... 12...  13...  14...  15...  16...  17...  18...  19...  20...  21...  22...  23...  24...  25...  26...  27...  28...  29...  30...  31...  32...  33...  34...  35...  36...  Next >>


No comments :

What you think about these Questions and Answers ? Let me know in comments.

Post a Comment