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
cprogramming_questions_answers.htm

Q 1 - What is the outpout of the following program?

#include<stdio.h>

main() 
{
      enum { india, is=7, GREAT };

      printf("%d %d", india, GREAT);
}

A - 0 1.

B - 0 2

C - 0 8

D - Compile error

Answer : C

Explanation

0 8, enums gives the sequence starting with 0. If assigned with a value the sequence continues from the assigned value.

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

#include<stdio.h>

main()
{
   int x = 65, *p = &x;
   
   void *q=p;
   char *r=q;
   printf("%c",*r);
}

A - Garbage character.

B - A

C - 65

D - Compile error

Answer : B

Explanation

A, void pointer is a generic pointer and can hold any variable’s address. ASCII character for the value 65 is ‘A’

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

#include<stdio.h>

main()
{ 
   int a[3] = {2,,1};
   
   printf("%d", a[a[0]]); 
}

A - 0

B - 1

C - 2

D - Compile error

Answer : D

Explanation

Compile error, invalid syntax in initializing the array.

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

#include<stdio.h>

main()
{	
   fprintf(stdout,"Hello, World!");
}

A - Hello, World!

B - No output

C - Compile error

D - Runtime error

Answer : C

Explanation

stdout is the identifier declared in the header file stdio.h, need to include the same.

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

#include<stdio.h>

main()
{ 
   printf("%d", !0<2);
}

A - 0

B - 1

C - False

D - True

Answer : B

Explanation

Priority of ! is greater than <. Relational operator returns 1 if relation between the expressions is true otherwise 0.

Answer : A

Explanation

In C programming, NULL indicates the value 0 of a pointer, which means; pointer that initializes with NULL value considered as NULL pointer.

Answer : B

Explanation

By passing the name of an array as a function argument; the name contains the base address of an array and the base address (array value) get updated in the main function.

Q 9 - To print a double value which format specifier can be used?

A - %L

B - %lf

C - %Lf

D - None of the above

Answer : B

Explanation

Double value can be printed using %lf format specifier.

Q 10 - What will be the output of the given below code?

#include<stdio.h>

int main()
{
   const int *ptr = &i;
   
   char str[] = "Welcome";
   s = str;
   while(*s)
   printf("%c", *s++);
   return 0;
}

A - Welcome

B - 0

C - Wel

D - Come

Answer : A

Explanation

Although, char str[] = "Welcome"; and s = str;, the program will print the value of s.

#include<stdio.h>

int main()
{
   const int *ptr = &i;
   
   char str[] = "Welcome";
   s = str;
   while(*s)
   printf("%c", *s++);
   return 0;
}

Advertisements