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 = 5, b = 3, c = 4; 
   
   printf("a = %d, b = %d\n", a, b, c);
}

A - a=5, b=3

B - a=5, b=3, c=0

C - a=5, b=3, 0

D - compile error

Answer : A

Explanation

a=5,b=3 , as there are only two format specifiers for printing.

Q 2 - The type name/reserved word ‘short’ is ___

A - short long

B - short char

C - short float

D - short int

Answer : D

Explanation

short is used as an alternative of short int.

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

#include<stdio.h>

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

A - 0

B - 1

C - 2

D - Compile error

Answer : D

Explanation

Compile error, invalid syntax in initializing the array.

Q 4 - What is the output of the below code snippet.

#include<stdio.h>

main()
{
   printf("%d", -11%2);
}

A - 1

B - -1

C - 5.5

D - -5.5

Answer : B

Explanation

Modulus (%) operator is meant to give reminder for integer division.

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

#include<stdio.h>

void main()
{
   char *s = "C++";
   
   printf("%s ", s);
   s++;
   printf("%s", s);
}

A - C++ C++

B - C++ ++

C - ++ ++

D - Compile error

Answer : B

Explanation

After s++, s points the string “++”.

Q 6 - Which header statement is missing in the given below program to get the desired output?

#include<stdio.h>
#include<math.h>

int main ()
{
   double x = 1234321;
  
   double result = sqrt(x);
  
   printf("The square root of %.2lf is %.2lf\n", x, result);
   return 0;
}

A - #include<defs.h>

B - #include<math.h>

C - #include<stdlib.h>

D - Above program is absolutely correct to give desired result

Answer : B

Explanation

In C programming, math.h is a header file in the standard library designed for basic mathematical operations.

   Output of above code: The square root of 1234321.00 is 1111.00
#include<stdio.h>
#include<math.h>

int main ()
{
   double x = 1234321;
  
   double result = sqrt(x);
  
   printf("The square root of %.2lf is %.2lf\n", x, result);
   return 0;
}

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 - Which library function can convert an unsigned long to a string?

A - ltoa() 

B - ultoa()

C - system() 

D - unsigned long can’t be converted to a string

Answer : B

Explanation

ultoa() - Convert an unsigned long integer into a string.

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 - The maximum combined length of the command-line arguments as well as the spaces between adjacent arguments is – a) 120 characters, b) 56 characters, c) Vary from one OS to another

A - a

B - a, b

C - a, b, c

D - c

Answer : D

Explanation

The maximum combined length of the command-line arguments and the spaces between adjacent arguments vary from one OS to another.

Advertisements