• C Programming Video Tutorials

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

A - Infinite loop

B - Prints “Hello” once.

C - No output

D - Compile error

Answer : D

Explanation

Compiler error, semi colons need to appear though the expressions are optional for the ‘for’ loop.

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 - Following is the invalid inclusion of a file to the current program. Identify it.

A - #include <file>

B - #include “file”

C - #include < file

D - All of the above are invalid.

Answer : C

Explanation

option (a) & (b) are valid. There is no such syntax or provision as in option (c).

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

#include<stdio.h>

main() 
{
   char *p = NULL;
   
   printf("%c", *p);
}

A - NULL

B - 0

C - Compile error

D - Runtime error.

Answer : D

Explanation

It is invalid to access the NULL address hence giving run time error.

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

#include<stdio.h>

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

A - Hello

B - Helloellolloloo

C - ello

D - Compile error

Answer : A

Explanation

NULL is equivalent to ‘\0’ in value. Statement *s++ prints the character first and increments the address later.

Q 6 - The C library function rewind() reposition the file pointer at the beginning of the file.

A - True

B - False

Answer : A

Explanation

void rewind(FILE *stream): In C, the rewind function reposition the file position to the beginning of the file of the given stream. It also erases the error and end-of-file indicators for stream.

Q 7 - Which of the following is a logical NOT operator?

A - !

B - &&

C - &

D - All of the above

Answer : A

Explanation

Logical NOT operator will make false.

Q 8 - The return keyword used to transfer control from a function back to the calling function.

A - Yes

B - Switch

C - go back

D - goto

Answer : A

Explanation

In C, the return function stops the execution of a function and returns control with value to the calling function. Execution begins in the calling function by instantly following the call.

Q 9 - Which printf() statement will you use to print out a (float value) and b (double value)?

   Float a = 3.14;
   
   Double b = 3.14;

A - printf("%f %lf", a, b);

B - printf("%f %f", a, b);

C - printf("%Lf %Lf", a, b);

D - printf("%f %Lf", a, b);

Answer : A

Explanation

%f can be use to print out float value and %lf can be use to print out  double value.

Q 10 - extern int fun(); - The declaration indicates the presence of a global function defined outside the current module or in another file.

A - True

B - False

Answer : A

Explanation

Extern is used to resolve the scope of global identifier.

Advertisements