• 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 below code snippet?

#include<stdio.h>

main() 
{ 
   int a = 5, b = 3, c = 4; 
   
   printf("a = %d, b = %d\n", a, b, c);
}

A - a=5, b=3

B - a=5, b=3, c=0

C - a=5, b=3, 0

D - compile error

Answer : A

Explanation

a=5,b=3 , as there are only two format specifiers for printing.

Q 2 - What is the value of ‘y’ for the following code snippet?

#include<stdio.h>

main()
{
   int x = 1;
   
   float y = x>>2;
   
   printf( "%f", y );
}

A - 4

B - 0.5

C - 0

D - 1

Answer : C

Explanation

0, data bits are lost for the above shift operation hence the value is 0.

Answer : B

Explanation

(b). Linker links the object code of your program and library code to produce executable.

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>

main()
{ 
   char *s = "Abc";
   
   while(*s)
      printf("%c", *s++);
}

A - Abc

B - bc

C - Compile error

D - Runtime error

Answer : A

Explanation

Loop continues until *s not equal to ‘\0’, hence printing “Abc” where character is fetched first and address is incremented later.

Q 6 - The binary equivalent of 50 is,

A - 110010

B - 1010110

C - 101

D - 101.011.00.00

Answer : A

Explanation

#include <stdio.h>

 int main()
{
   long int decimalNumber,remainder,quotient;
    int binaryNumber[100], i = 1, j;

    printf("Enter any decimal number: ");
    scanf("%ld",&decimalNumber);
    quotient = decimalNumber;
    while(quotient!=0){
           binaryNumber[i++]= quotient % 2;
    quotient = quotient / 2;
    }
    printf("Equivalent binary value of decimal number %d: ",decimalNumber);
    for(j = i -1 ;j> 0;j--)
    printf("%d",binaryNumber[j]);
    return 0;
}

Q 7 - Which library functions help users to dynamically allocate memory?

A - memalloc()and alloc() 

B - malloc() and memalloc()

C - malloc() and calloc()

D - memalloc() and calloc()

Answer : C

Explanation

malloc():Allocates an area of memory that is large enough to hold "n” number of bytes and initializes contents of memory to zeroes.

calloc(): Allocates "size" of bytes of memory and contains garbage values.

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 - 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 - extern int fun(); - The declaration indicates the presence of a global function defined outside the current module or in another file.

A - True

B - False

Answer : A

Explanation

Extern is used to resolve the scope of global identifier.

Advertisements