C Programming Online Quiz


Advertisements


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

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 is the output of the following program?

#include<stdio.h>

{ 
   int x = 1;
   switch(x) 
   {
      default: printf("Hello");
      case 1: printf("hi"); break;
   }
}

A - Hello

B - Hi

C - HelloHi

D - Compile error

Answer : B

Explanation

Hi, control reaches default-case after comparing the rest of case constants.

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 - 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()
{ 
   int x;
   float y;
   
   y = x = 7.5;
   printf("x=%d y=%f", x, y);
}

A - 7 7.000000

B - 7 7.500000

C - 5 7.500000

D - 5 5.000000

Answer : A

Explanation

‘x’ gets the integral value from 7.5 which is 7 and the same is initialized to ‘y’.

Answer : A

Explanation

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

 int main()
{
   float x = 3.6;	
   
   int y = (int)(x + 0.5);
   
   printf ("Result = %d\n", y );
   return 0; 

}

Q 7 - A bitwise operator “&” can turn-off a particular bit into a number.

A - Yes

B - &&

C - *

D - ||

Answer : A

Explanation

The bitwise AND operator “&” compares each bit of the first operand with the corresponding bit of the second operand. During comparison, if both operands bits are 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.

Q 8 - How many times the given below program will print "India"?

#include<stdio.h>

int main ()
{
   int x;
   
   for(x=-1; x<=20; x++)int i;
   {
   if(x < 10)
      continue;
   else
      break;
   printf("India");
}

A - Unlimited times

B - 21 times

C - 0 times

D - 20 times

Answer : C

Explanation

Following for loop there is only one statement, that is int i; break & continue are appearing out side for block which is compile error

#include<stdio.h>

int main ()
{
   int x;
   
   for(x=-1; x<=20; x++)int i;
   {
   if(x < 10)
      continue;
   else
      break;
   printf("India");
}

Answer : B

Explanation

As per the operators preference.

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.


cprogramming_questions_answers.htm

Advertisements