C Programming - Online Quiz


Advertisements

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 code snippet?

#include<stdio.h>

main() 
{
   int x = 5;
   
   if(x=5)
   {	
       if(x=5) break;
       printf("Hello");
   } 
   printf("Hi");
}

A - Compile error

B - Hi

C - HelloHi

D - Compiler warning

Answer : A

Explanation

compile error, keyword break can appear only within loop/switch statement.

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

#include<stdio.h>

main()
{   
   int r, x = 2;
   float y = 5;

   r = y%x;
   printf("%d", r); 
}

A - 1

B - 0

C - 2

D - Compile error

Answer : D

Explanation

Compile Error, It is invalid that either of the operands for the modulus operator (%) is a real number.

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

#include<stdio.h>

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

A - 0

B - 1

C - 2

D - 3

Answer : B

Explanation

1, The inner indirection evaluates to 1, and the value at index 1 for outer indirection is 1.

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

#include<stdio.h>

main() 
{
}

A - No output

B - Garbage

C - Compile error

D - Runtime error

Answer : A

Explanation

It is valid to have main() function empty, therefore producing no displayable output.

Q 5 - C is the successor of ___ programming language.

A - C++

B - B++

C - B

D - Mini C

Answer : C

Explanation

B is a programming language developed at Bell Labs in 1969. It is derived from BCPL (Basic Combined Programming Language). It is designed by Ken Thompson with Dennis Ritchie.

Q 6 - How to round-off a value “5.77” to 6.0?

A - ceil(5.77)

B - round-off(5.77)

C - round-up(5.77)

D - floor(5.77)

Answer : A

Explanation

ceil( ) function in C returns nearest integer value which is greater than or equal to the argument passed to thefunction.

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

 int main()
{
   float x=5.77;
   printf("ceil of  %f is  %f\n", x, ceil(x));
   return 0;
}

Q 7 - In Decimal system you can convert the binary number 1011011111000101 very easily.

A - Yes

B - Hexadecimal system

C - Octal system

D - Both, Octal & Decimal

Answer : B

Explanation

Hexadecimal is also known as hex or base 16. It is a system help in writing and presenting numerical values. Binary (base 2) is a popular numeral system (represent numbers by just two digit values “0 and 1”), used to present the language of computers. Hexadecimal system can easily convert those numbers.

Q 8 - Which of the following variable cannot be used by switch-case statement?

A - char

B - int

C - float

D - Double

Answer : C

Explanation

Switch Case only accepts integer values for case label, float values can’t be accepted in case of Switch Case.

#include<stdio.h>

int main ()
{
   i = 1.8
   
   switch ( i )
   {
      case 1.6:
               printf ("Case 1.6");
               break;
      case 1.7:
               printf ("Case 1.7");
               break;
      case 1.8:
               printf ("Case 1.8");
               break;
       default :
               printf ("Default Case ");
   }

}

Q 9 - To print a double value which format specifier can be used?

A - %L

B - %lf

C - %Lf

D - None of the above

Answer : B

Explanation

Double value can be printed using %lf format specifier.

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

   int (*pf)();

A - pf is a pointer of a function which return int

B - pf is a pointer

C - pf is a function pointer

D - None of the above

Answer : A

Explanation

pf is a pointer as well holds some functions reference.

Advertisements