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) printf("Hello");
   } 
   printf("Hi");
}

A - HelloHi

B - Hi

C - Hello

D - Compiler error

Answer : A

Explanation

HelloHi, both the if statements expression evaluates to be true.

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

#include<stdio.h>

void f() 
{
    printf(Hello\n);
}
main() 
{
 ;
}

A - No output

B - Error, as the function is not called.

C - Error, as the function is defined without its declaration

D -Error, as the main() function is left empty

Answer : A

Explanation

No output, apart from the option (a) rest of the comments against the options are invalid.

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

#include<stdio.h>

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

A - 0

B - 1

C - 2

D - 3

Answer : B

Explanation

1, The inner indirection evaluates to 1, and the value at index 1 for outer indirection is 1.

Answer : C

Explanation

The text associated with the macro name gets expanded at the line of call. The expanded text is by default a double constant whereas no type is associated with PI.

Q 5 - Which of the following functions disconnects the stream from the file pointer.

A - fremove()

B - fclose()

C - remove()

D - file pointer to be set to NULL

Answer : B

Explanation

fclose(), it flushes the buffers associated with the stream and disconnects the stream with the file.

Q 6 - Choose the correct statement that can retrieve the remainder of the division 5.5 by 1.3?

A - rem = modf(5.5 % 1.3)

B - rem = modf(5.5, 1.3)

C - rem = fmod(5.5, 1.3)

D - rem = f(5.5, 1.3)

Answer : C

Explanation

A floating-point constant without anf,F,l, orLsuffix has typedouble. If the letterforFis the suffix, the constant has typefloat. If suffixed by the letterlorL, it has typelong double.

Q 7 - For a structure, if a variable behave as a pointer then from the given below operators which operator can be used to access data of the structure via the variable pointer?

A - .

B - %

C - ->

D - #

Answer : C

Explanation

For a structure, Dot(.) operator can be used to access the data using normal structure variable and arrow (->)can be used to access the data using pointer variable.

Q 8 - fgets() function is safer than gets() because in fgets() function you can specify the size of the buffer into which the supplied string will be stored.

A - True

D - False

Answer : A

Explanation

Both functions retrive and store a string from console or file, but fgets() functions are more safer to use then gets() because gets()doesn't facilitate to detail the length of the buffer to store the string in and fgets() facilitates to specify a maximum string length.

   char *fgets(char *s, int size, FILE *stream);
   char *gets(char *s);

Q 9 - Choose the correct order from given below options for the calling function of the code a = f1(23, 14) * f2(12/4) + f3();?

A - f1, f2, f3

B - f3, f2, f1

C - f2, f1, f3

D - Order may vary from one compiler to another

Answer : D

Explanation

Evaluation order is implementation dependent.

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