• C Programming Video Tutorials

C Programming - Online Quiz



Following quiz provides Multiple Choice Questions (MCQs) related to C Programming Framework. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers
cprogramming_questions_answers.htm

Q 1 - What is the output of the below code snippet?

#include<stdio.h>

main() 
{ 
   int a = 5, b = 3, c = 4; 
   
   printf("a = %d, b = %d\n", a, b, c);
}

A - a=5, b=3

B - a=5, b=3, c=0

C - a=5, b=3, 0

D - compile error

Answer : A

Explanation

a=5,b=3 , as there are only two format specifiers for printing.

Q 2 - What will be printed for the below statement?

#include<stdio.h>

main()
{
   printf("%d",strcmp("strcmp()","strcmp()"));
}

A - 0

B - 1

C - -1

D - Invalid use of strcmp() function

Answer : A

Explanation

0, strcmp return 0 if both the strings are equal

Q 3 - Identify the invalid constant used in fseek() function as ‘whence’ reference.

A - SEEK_SET

B - SEEK_CUR

C - SEEK_BEG

D - SEEK_END

Answer : C

Explanation

SEEK_BEG, all the rest are valid constants defined in ‘stdio.h’

Q 4 - Choose the invalid predefined macro as per ANSI C.

A - __FILE__

B - __DATE__

C - __TIME__

D - __C++__

Answer : D

Explanation

There is no macro define with the name __C++__, but __cplusplus is defined by ANSI)

Q 5 - What is the output of the following program?

#include<stdio.h>

int main();
void main()
{
   printf("Okay"); 
}

A - Okay

B - No output

C - Compile error. We cannot declare main() function.

D - Compile error. Mismatch in declaration & definition.

Answer : D

Explanation

It’s compile error as the declaration of main() mismatches with the definition.

Q 6 - In normalized form, if the binary equivalent of 5.375 is “0100 0000 1010 1100 0000 0000 0000 0000” then what will be the output of the program in Intel core machine?

#include<stdio.h>
#include<math.h>

int main ()
{
   float a = 5.375;
   char *p;
   int i;
   
   p = (char*)&a;
   for(i=0; i <= 3; i++)
      printf("%02x\n", (unsigned char)p[i]);
   return 0;
}

A - 40 AC 00 00

B - 00 00 AC 40

C - 00 00 CA 04

D - None

Answer : B

Explanation

Depends upon the machine whether its big endian or small endian machine. Byte by byte is fetched from right end.

#include<stdio.h>
#include<math.h>

int main ()
{
   float a = 5.375;
   char *p;
   int i;
   
   p = (char*)&a;
   for(i=0; i <= 3; i++)
      printf("%02x\n", (unsigned char)p[i]);
   return 0;
}

Answer : B

Explanation

It is BODMAS.

Q 8 - Which of the following variable cannot be used by switch-case statement?

A - char

B - int

C - float

D - Double

Answer : C

Explanation

Switch Case only accepts integer values for case label, float values can’t be accepted in case of Switch Case.

#include<stdio.h>

int main ()
{
   i = 1.8
   
   switch ( i )
   {
      case 1.6:
               printf ("Case 1.6");
               break;
      case 1.7:
               printf ("Case 1.7");
               break;
      case 1.8:
               printf ("Case 1.8");
               break;
       default :
               printf ("Default Case ");
   }

}

Q 9 - Choose the correct order from given below options for the calling function of the code “a = f1(23, 14) * f2(12/4) + f3();”?

A - f1, f2, f3

B - f3, f2, f1

C - f2, f1, f3

D - Order may vary from one compiler to another

Answer : D

Explanation

Evaluation order is implementation dependent.

Q 10 - According to ANSI specification, how to declare main () function with command-line arguments?

A - int main(int argc, char *argv[])

B - int char main(int argc, *argv)

C -

int main()
{
   Int char (*argv argc);
)

D - None of the above

Answer : A

Explanation

Some time, it becomes necessary to deliver command line values to the C programming to execute the particular code when the code of the program is controlled from outside. Those command line values are called command line arguments. The command line arguments are handled by the main() function.

Declaration of main () with command-line argument is,

int main(int argc, char *argv[])

Where, argc refers to the number of arguments passed, and argv[] is a pointer array which points to each argument passed to the program.

Advertisements