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() 
{
   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()
{
   int i = 1;
   
   while(++i <= 5)
      printf("%d ",i++);
}

A - 1 3 5

B - 2 4

C - 2 4 6

D - 2

Answer : B

Explanation

2 4, at while first incremented and later compared and in printf printed first and incremented later

Q 3 - A single line comment in C language source code can begin with _____

A - ;

B - :

C - /*

D - //

Answer : D

Explanation

Two immediate forward slashes are used to comment a single line. A single can be commented by beginning with /* and should be terminated with */ , in general used for multi-line comments.

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 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’.

Q 6 - int fun(); - The declaration indicates the presence of a function defined inside the current module or in the same file.

A - True

B - False

Answer : A

Explanation

The function definition can even appear in another source code and can be linked from library while linking.

Answer : B

Explanation

A structure, union and enumeration all of them can define a new data type.

Answer : A

Explanation

randomize() picks the current time value as the SEED number to generate random numbers.

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


cprogramming_questions_answers.htm

Advertisements