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() 
{
   for(1;2;3)
      printf("Hello");
}

A - Infinite loop

B - Prints Hello once.

C - No output

D - Compile error

Answer : A

Explanation

infinite loop, as the second expression is non-0, hence the condition is always true.

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 - First operating system designed using C programming language.

A - DOS

B - Windows

C - UNIX

D - Mac

Answer : C

Explanation

UNIX. C actually invented to write an operation system called UNIX. By 1973 the entire UNIX OS is designed using C.

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

#include<stdio.h>

main() 
{
}

A - No output

B - Garbage

C - Compile error

D - Runtime error

Answer : A

Explanation

It is valid to have main() function empty, therefore producing no displayable output.

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

#include<stdio.h>

main()
{ 
   char *s = "Abc";
   
   while(*s)
      printf("%c", *s++);
}

A - Abc

B - bc

C - Compile error

D - Runtime error

Answer : A

Explanation

Loop continues until *s not equal to \0, hence printing Abc where character is fetched first and address is incremented later.

Q 6 - The binary equivalent of 50 is,

A - 110010

B - 1010110

C - 101

D - 101.011.00.00

Answer : A

Explanation

#include <stdio.h>

 int main()
{
   longintdecimalNumber,remainder,quotient;
intbinaryNumber[100], i = 1, j;

 printf("Enter any decimal number: ");
 scanf("%ld",&decimalNumber);
 quotient = decimalNumber;
while(quotient!=0){
           binaryNumber[i++]= quotient % 2;
quotient = quotient / 2;
 }
 printf("Equivalent binary value of decimal number %d: ",decimalNumber);
for(j = i -1 ;j> 0;j--)
printf("%d",binaryNumber[j]);
return0;
}

Q 7 - The equivalent pointer expression by using the array elementa[i][j][k][2],

A - ((((a+m)+n)+o)+p)

B - *(*(*(*(a+i)+j)+k)+2)

C - *( (((a+m)+n)+o+p)

D - *( ((a+m)+n+o+p)

Answer : B

Explanation

If, the array elementis a[i][j] = *(*(a+i)+j)

If, the array elementis a[i][j][k]= *(*(*(a+i)+j)+k)

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

#include<stdio.h>

int main ()
{
   printf("IndiaPIN");
   main();
   return 0;

}

A - Unlimited times

B - 0 times

C - 100 times

D - Till stack run over

Answer : D

Explanation

Astack over flowcomes when over loaded memory is used by the call stack. Here, main()functionis called repeatedly and its return address stores in the stack. When stack memory get filled, it displays the error stack overflow.

#include<stdio.h>

int main ()
{
   printf("IndiaPIN");
   main();
   return 0;

}

Q 9 - What will be the output of the following program?

#include<stdio.h>

int main()
{
   const int x = 5;
   
   const int *ptrx;
   ptrx = &x;
   *ptrx = 10;
   printf("%d\n", x);
   return 0;
}

A - 10

B - 20

C - 0

D - The program will return error

Answer : D

Explanation

The above program will return error

#include<stdio.h>

int main()
{
   const int x = 5;
   
   const int *ptrx;
   ptrx = &x;
   *ptrx = 10;
   printf("%d\n", x);
   return 0;
}

Q 10 - The maximum combined length of the command-line arguments as well as the spaces between adjacent arguments is a) 120 characters, b) 56 characters, c) Vary from one OS to another

A - a

B - a, b

C - a, b, c

D - c

Answer : D

Explanation

The maximum combined length of the command-line arguments and the spaces between adjacent arguments vary from one OS to another.

Advertisements