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

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>

void f() 
{
    printf(“Hello\n”);
}
main() 
{
 ;
}

A - No output

B - Error, as the function is not called.

C - Error, as the function is defined without its declaration

D -Error, as the main() function is left empty

Answer : A

Explanation

No output, apart from the option (a) rest of the comments against the options are invalid.

Q 3 - Function fopen() with the mode "r+" tries to open the file for __

A - reading and writing

B - reading and adding new content

C - only for reading

D - it works only for directories

Answer : A

Explanation

Option (a), the file should exist and opens for both reading & writing.

Q 4 - The default executable generation on UNIX for a C program is ___

A - a.exe

B - a

C - a.out

D - out.a

Answer : C

Explanation

"a.out" is the default name of the executable generated on both the UNIX and Linux operating systems.

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 - 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 - 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.

Answer : A

Explanation

In C programming, the fflush() function writes any unwritten data in stream's buffer. If, stream is a null pointer, fflush() function will flush all streams with unwritten data in the buffer.

int fflush(FILE *stream);

Q 9 - What will be the output of the following program?

#include<stdio.h>

int main()
{
   const int x = 5;
   
   const int *ptrx;
   ptrx = &x;
   *ptrx = 10;
   printf("%d\n", x);
   return 0;
}

A - 10

B - 20

C - 0

D - The program will return error

Answer : D

Explanation

The above program will return error

#include<stdio.h>

int main()
{
   const int x = 5;
   
   const int *ptrx;
   ptrx = &x;
   *ptrx = 10;
   printf("%d\n", x);
   return 0;
}

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.

cprogramming_questions_answers.htm
Advertisements