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 x = 65, *p = &x;
   
   void *q=p;
   char *r=q;
   printf("%c",*r);
}

A - Garbage character.

B - A

C - 65

D - Compile error

Answer : B

Explanation

A, void pointer is a generic pointer and can hold any variable’s address. ASCII character for the value 65 is ‘A’

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>

void f() 
{
   static int i = 3;
   
   printf("%d ", i);
   if(--i) f();
}
main() 
{
   f();
}

A - 3 2 1 0

B - 3 2 1

C - 3 3 3

D - Compile error

Answer : B

Explanation

As the static variable retains its value from the function calls, the recursion happens thrice.

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.

Answer : B

Explanation

The double constant 3.14 can be converted into long double by adding “L” after the constant value, i.e; 3.14L.

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.

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 - Choose the correct unary operators in C – a) !, b) ~, c) ^&, d) ++

A - a, b, d

B - a, b, c

C - b, c, d

D - c, d, a

Answer : A

Explanation

In C, these are the unary operators,

   Logical NOT = !
   Address-of = &
   Cast Operator = ( )
   Pointer dereference = *
   Unary Plus = +
   Increment = ++
   Unary negation = –

Q 10 - In the given below code, what will be the value of a variable x?

#include<stdio.h>

int main()
{
    int y = 100;
    const int x = y;
    
    printf("%d\n", x);
    return 0;
}

A - 100

B - 0

C - Print x

D - Return Error

Answer : A

Explanation

Although, integer y = 100; and constant integer x is equal to y. here in the given above program we have to print the x value, so that it will be 100.

Advertisements