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

#include<stdio.h>

main()
{ 
   int *p = 15; 
   printf("%d",*p);
}

A - 15

B - Garbage value

C - Runtime error

D - Compiler error

Answer : C

Explanation

Runtime error, as the pointer variable is not holding proper address, writing/reading the data from the same raises runtime error.

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 - First operating system designed using C programming language.

A - DOS

B - Windows

C - UNIX

D - Mac

Answer : C

Explanation

UNIX. C actually invented to write an operation system called UNIX. By 1973 the entire UNIX OS is designed using C.

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

#include<stdio.h>

main()
{	
   fprintf(stdout,"Hello, World!");
}

A - Hello, World!

B - No output

C - Compile error

D - Runtime error

Answer : A

Explanation

stdout is the identifier declared in the header file stdio.h which is connected to standard output device (monitor).

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 : D

Explanation

s refers to a constant address and cannot be incremented.

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 tothe 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 - Which of the following operator can be used to access value at address stored in a pointer variable?

A - *

B - #

C - &&

D - @

Answer : A

Explanation

Pointer operator,

* (Value Operator) = Gives Value stored at Particular address

& (Address Operator) = Gives Address of Variable

Answer : A

Explanation

In C library, NULL Macrois the value of a null pointer constant. It may be defined as((void*)0), 0or0Ldepending on the compiler merchant.

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

#include<stdio.h>

int main()
{
   const int i = 0;
    
   printf("%d\n", i++);
   return 0;
}

A - 100

B - Infinity

C - 0

D - Return error

Answer : D

Explanation

It is because ++needs a value and aconstvariable cant be modified.

#include<stdio.h>

int main()
{
   const int i = 0;
    
   printf("%d\n", i++);
   return 0;
}

Answer : D

Explanation

square parenthesis signify as array at declaration and type is char*, so array of character pointers.

Advertisements