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() 
{ 
   int a = 1; 
   float b = 1.3; 
   double c;
   
   c = a + b; 
   printf("%.2lf", c);
}

A - 2.30

B - 2.3

C - Compile error

D - 2.0

Answer : A

Explanation

2.30, addition is valid and after decimal with is specified for 2 places.

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

#include<stdio.h>

main()
{
   printf("\");
}

A - \

B - \"

C - "

D - Compile error

Answer : D

Explanation

Compile error, Format string of printf is not terminated.

Answer : B

Explanation

(b). Compilation is the process of translating high level language statements into equivalent machine code, which is object code.

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

#include<stdio.h>

int* f() 
{
   int x = 5;
   
   return &x;
}	
main() 
{
   printf("%d", *f());
}

A - 5

B - Address of x

C - Compile error

D - Runtime error

Answer : D

Explanation

It is invalid to return local variable address as the local variable gets removed after the functions execution is completed.

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 - In C, what are the various types of real data type (floating point data type)?

A - Float, long double

B - long double, short int

C - float, double, long double

D - short int, double, long int, float

Answer : C

Explanation

There are three types of floating point data type = 1) float with storage size 4 byte, 2) double with storage size 8 byte, and 3) long double with storage size 10 byte.

Q 7 - A bitwise operator & can turn-off a particular bit into a number.

A - Yes

B - &&

C - *

D - ||

Answer : A

Explanation

The bitwise AND operator & compares each bit of the first operand with the corresponding bit of the second operand. During comparison, if both operands bits are 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.

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