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()
{  
   float t = 2;

   switch(t)
   {
       case 2: printf("Hi");
       default: printf("Hello");
   }
}

A - Hi

B - HiHello

C - Hello

D - Error

Answer : D

Explanation

Error, switch expression cant be float value.

Q 3 - Identify the invalid constant used in fseek() function as whence reference.

A - SEEK_SET

B - SEEK_CUR

C - SEEK_BEG

D - SEEK_END

Answer : C

Explanation

SEEK_BEG, all the rest are valid constants defined in stdio.h

Q 4 - To store a word/sentence declare a variable of the type string.

A - true

B - false

Answer : B

Explanation

There is no such data type called string in C language.

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

#include<stdio.h>

main()
{ 
   printf("%d", !0<2);
}

A - 0

B - 1

C - False

D - True

Answer : B

Explanation

Priority of ! is greater than <. Relational operator returns 1 if relation between the expressions is true otherwise 0.

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.

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 - In the following code, what is 'P'?

   Typedef char *charp;
   
   const charp P;

A - P is a constant

B - P is a character type

C - P is a pointer

D - None of the above

Answer : A

Explanation

Const charp P;

Although, the code itself indicates the keyword "const", so that; P is a constant.

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 - Choose the function that is most appropriate for reading in a multi-word string?

A - strnset()

B - scanf()

C - strchr()

D - gets()

Answer : D

Explanation

gets (); = Collects a string of characters terminated by a new line from the standard input streamstdin

Advertisements