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 program?

#include<stdio.h>

main()
{	
    register int x = 5;

    int *p;
    p=&x;
    x++;
    printf("%d",*p);
}

A - Compile error

B - 5

C - 6

D - Garbage value

Answer : A

Explanation

Compile error, we cannot take the address of a register variable.

Q 2 - Which operator is used to continue the definition of macro in the next line?

A - #

B - ##

C - $

D - \

Answer : D

Explanation

\, the first two are stringize and token pasting operators respectively. There is no such operator called $.

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 : A

Explanation

stdout is the identifier declared in the header file stdio.h which is connected to standard output device (monitor).

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

#include<stdio.h>

main()
{ 
   struct student
   { 
       int num = 10;
   }var;

   printf("%d", var.num);
}

A - 10

B - Garbage

C - Runtime error

D - Compile error

Answer : D

Explanation

Structure elements cannot be initialized

Answer : B

Explanation

  • External Linkage-> A global, non-static variables and functions.
  • Internal Linkage-> A static variables and functions with file scope.
  • None Linkage-> A Local variables.

Q 8 - Which of the following statement can be used to free the allocated memory?

A - remove(var-name);

B - free(var-name);

C - vanish(var-name);

D - erase(var-name);

Answer : B

Explanation

The library functionfree()deallocates the memory allocated by calloc(), malloc(), or realloc().

Answer : A

Explanation

Preprocessing enlarges and boosts the C programming language by replacing preprocessing directive #include<stdio.h>with the content of the file stdio.h.

Q 10 - In the given below statement, what does the pf indicate?

   int (*pf)();

A - pfis a pointer of a function which returnint

B - pfis a pointer

C - pfis a function pointer

D - None of the above

Answer : A

Explanation

pf is a pointer as well holds some functions reference.

Advertisements