• 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 following code snippet?

#include<stdio.h>

main() 
{
   int x = 5;
   
   if(x=5)
   {	
       if(x=5) break;
       printf("Hello");
   } 
   printf("Hi");
}

A - Compile error

B - Hi

C - HelloHi

D - Compiler warning

Answer : A

Explanation

compile error, keyword break can appear only within loop/switch statement.

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

#include<stdio.h>

main()
{
   printf("\");
}

A - \

B - \"

C - "

D - Compile error

Answer : D

Explanation

Compile error, Format string of printf is not terminated.

Q 3 - Choose the application option for the following program?

#include<stdio.h>

main()
{
   int *p, **q;
   
   printf("%u\n", sizeof(p));
   printf("%u\n", sizeof(q));
}

A - Both the printf() will print the same value

B - First printf() prints the value less than the second.

C - Second printf() prints the value less than the first.

D - Error in the code.

Answer : A

Explanation

Irrespective of any data type every type of pointer variable occupies same amount of memory.

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

#include<stdio.h>

main()
{	
   char *s = "Hello, "
   "World!";

   printf("%s", s);
}

A - Hello, World!

B - Hello,

World!

C - Hello

D - Compile error

Answer : A

Explanation

Two immediate string constant are considered as single string constant.

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

#include<stdio.h>

main()
{ 
   struct student
   { 
       int num = 10;
   }var;

   printf("%d", var.num);
}

A - 10

B - Garbage

C - Runtime error

D - Compile error

Answer : D

Explanation

Structure elements cannot be initialized

Answer : B

Explanation

In the C Programming Language, the fmod() function compute and returns the floating-point remainder when x is divided by y.

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

int main( void )
{
   double x = -10.0, y = 3.0, z;

   z = fmod( x, y );
   printf( "The remainder of %.2f / %.2f is %f\n", w, x, z );
}

Q 7 - Which of the following operator can be used to access value at address stored in a pointer variable?

A - *

B - #

C - &&

D - @

Answer : A

Explanation

Pointer operator,

* (Value Operator) = Gives Value stored at Particular address

& (Address Operator) = Gives Address of Variable

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 ");
   }

}

Answer : A

Explanation

Preprocessing enlarges and boosts the C programming language by replacing preprocessing directive “#include<stdio.h>” with the content of the file stdio.h.

Q 10 - Which statement can print \n on the screen?

A - printf("\\n");

B - printf("n\");

C - printf("n");

D - printf('\n');

Answer : A

Explanation

Option A is the correct answer. In C programming language, "\n" is the escape sequence for printing a new line character. In printf("\\n"); statement, "\\" symbol will be printed as "\" and “n” will be known as a common symbol.

Advertisements