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() 
{
    char c = 'A'+255;
   
    printf("%c", c);
}

A - A

B - B

C - Overflow error at runtime

D - Compile error

Answer : A

Explanation

A, the range of ASCII values for the ASCII characters is 0-255. Hence the addition operation circulates back to ‘A’

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

#include<stdio.h>

main()
{  
   float t = 2;

   switch(t)
   {
       case 2: printf("Hi");
       default: printf("Hello");
   }
}

A - Hi

B - HiHello

C - Hello

D - Error

Answer : D

Explanation

Error, switch expression can’t be float value.

Q 3 - Identify the C compiler of UNIX.

A - gcc

B - cc

C - Borland

D - vc++

Answer : B

Explanation

‘cc’ full form is C Compiler and is the compiler for UNIX. gcc is GNU C compiler for linux. Borland and vc++ (Microsoft visual c++) for windows.

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

#include<stdio.h>

int x = 5;
int* f() 
{
   return &x;
}
main()
{	
   *f() = 10;
   
   printf("%d", x);
}

A - Compile error

B - Runtime error

C - 5

D - 10

Answer : D

Explanation

The returned address is global variables and 10 being stored in it. Therefore x is 10.

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

#include<stdio.h>

main()
{ 
   int x = 3;
   
   x += 2;
   x =+ 2;
   printf("%d", x); 
}

A - 2

B - 5

C - 7

D - Compile error

Answer : A

Explanation

+ in unary form is dummy operator, therefore ‘x’ is overwritten with the value +2 finally.

Q 6 - In normalized form, if the binary equivalent of 5.375 is “0100 0000 1010 1100 0000 0000 0000 0000” then what will be the output of the program in Intel core machine?

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

int main ()
{
   float a = 5.375;
   char *p;
   int i;
   
   p = (char*)&a;
   for(i=0; i <= 3; i++)
      printf("%02x\n", (unsigned char)p[i]);
   return 0;
}

A - 40 AC 00 00

B - 00 00 AC 40

C - 00 00 CA 04

D - None

Answer : B

Explanation

Depends upon the machine whether its big endian or small endian machine. Byte by byte is fetched from right end.

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

int main ()
{
   float a = 5.375;
   char *p;
   int i;
   
   p = (char*)&a;
   for(i=0; i <= 3; i++)
      printf("%02x\n", (unsigned char)p[i]);
   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

Q 8 - In DOS, how many bytes exist for near, far and huge pointers?

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

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

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

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

Answer : C

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.

Answer : B

Explanation

As per the operators preference.

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