• C Programming Video Tutorials

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 program?

#include<stdio.h>

void f() 
{ 
   static int i;
   
   ++i; 
   printf("%d", i); 
}

main()
{ 
   f(); 
   f(); 
   f(); 
}

A - 1 1 1

B - 0 0 0

C - 3 2 1

D - 1 2 3

Answer : D

Explanation

1 2 3, A static local variables retains its value between the function calls and the default value is 0.

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

#include<stdio.h>

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

A - 1

B - 2

C - Compile error

D - Runtime error

Answer : B

Explanation

2, as ‘p’ holds the base address then we can access array using ‘p’ just like with ‘a’

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

#include<stdio.h>

main()
{	
   union abc {
      int x;
      char ch;
   }var;

   var.ch = 'A';
   printf("%d", var.x);
}

A - A

B - Garbage value

C - 65

D - 97

Answer : C

Explanation

65, as the union variables share common memory for all its elements, x gets ‘A’ whose ASCII value is 65 and is printed.

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

#include<stdio.h>

main()
{	
   int a[] = {10, 20, 30};
   
   printf("%d", *a+1);
}

A - 10

B - 20

C - 11

D - 21

Answer : C

Explanation

*a refers to 10 and adding a 1 to it gives 11.

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

#include<stdio.h>

main()
{ 
   int x;
   float y;
   
   y = x = 7.5;
   printf("x=%d y=%f", x, y);
}

A - 7 7.000000

B - 7 7.500000

C - 5 7.500000

D - 5 5.000000

Answer : A

Explanation

‘x’ gets the integral value from 7.5 which is 7 and the same is initialized to ‘y’.

Q 6 - In Windows & Linux, how many bytes exist for near, far and huge pointers?

A - Near: 1, far: 4, huge: 7

B - near: 4, far: 4, huge: 4

C - near: 0, far: 4, huge: 4

D - near: 4, far: 5, huge: 6

Answer : B

Explanation

In DOS, numbers of byte exist for near pointer = 2, far pointer = 4 and huge pointer = 4.

In Windows and Linux, numbers of byte exist for near pointer = 4, far pointer = 4 and huge pointer = 4.

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

Explanation

Explanation: with or without the brackets surrounding the *p, still the declaration says it’s an array of pointer to integers.

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 - Choose the function that is most appropriate for reading in a multi-word string?

A - strnset()

B - scanf()

C - strchr()

D - gets()

Answer : D

Explanation

gets (); = Collects a string of characters terminated by a new line from the standard input stream stdin

Advertisements