• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

50 C Language MCQs with Answers

Question 21

The translator which performs macro calls expansion is called: 
 

  • Macro processor
     

  • Micro pre - processor
     

  • Macro pre - processor
     

  • Dynamic Linker
     

Question 22

What is the use of "#pragma once"?
 

  • Used in a header file to avoid its inclusion more than once.
     

  • Used to avoid multiple declarations of same variable.
     

  • Used in a c file to include a header file at least once.
     

  • Used to avoid assertions
     

Question 23

Which file is generated after pre-processing of a C program?
 

  • .p
     

  • .i
     

  • .o
     

  • .m
     

Question 24

Typically, library header files in C (e.g. stdio.h) contain not only declaration of functions and macro definitions but they contain definition of user defined data types (e.g. struct, union etc), typedefs and definition of global variables as well. So if we include the same header file more than once in a C program, it would result in compile issue because re-definition of many of the constructs of the header file would happen. So it means the following program will give compile error. 
 

C
#include “stdio.h”
#include “stdio.h”
#include “stdio.h”

int main()
{
 printf(Whether this statement would be printed?)
 return 0;
}
  • TRUE
     

  • FALSE
     

Question 25

C
#include <stdio.h>
#if X == 3
    #define Y 3
#else
    #define Y 5
#endif

int main()
{
    printf(\"%d\", Y);
    return 0;
}

What is the output of the above program?
 

  • 3
     

  • 5
     

  • 3 or 5 depending on value of X
     

  • Compile time error
     

Question 26

A one dimensional array A has indices 1....75. Each element is a string and takes up three memory words. The array is stored at location 1120 decimal. The starting address of A[49] is
 

  • 1267
     

  • 1164
     

  • 1264
     

  • 1169
     

Question 27

Which of the following is true about arrays in C?
 

  • For every type T, there can be an array of T.

  • For every type T except void and function type, there can be an array of T.

  • When an array is passed to a function, C compiler creates a copy of array.

  • 2D arrays are stored in column major form

Question 28

For the following declaration of a function in C, pick the best statement 
 

C
int [] fun(void (*fptr)(int *));
  • It will result in compile error.
     

  • No compile error. fun is a function which takes a function pointer fptr as argument and return an array of int.
     

  • No compile error. fun is a function which takes a function pointer fptr as argument and returns an array of int. Also, fptr is a function pointer which takes int pointer as argument and returns void.
     

  • No compile error. fun is a function which takes a function pointer fptr as argument and returns an array of int. The array of int depends on the body of fun i.e. what size array is returned. Also, fptr is a function pointer which takes int pointer as argument and returns void.
     

Question 29

In C, 1D array of int can be defined as follows and both are correct. 
 

C
int array1D[4] = {1,2,3,4};
int array1D[] = {1,2,3,4};

But given the following definitions (along-with initialization) of 2D arrays 
 

C
int array2D[2][4] = {1,2,3,4,5,6,7,8}; /* (i) */
int array2D[][4] = {1,2,3,4,5,6,7,8}; /* (ii) */
int array2D[2][] = {1,2,3,4,5,6,7,8}; /* (iii) */
int array2D[][] = {1,2,3,4,5,6,7,8}; /* (iv) */

Pick the correct statements.
 

  • Only (i) is correct.
     

  • Only (i) and (ii) are correct.
     

  • Only (i), (ii) and (iii) are correct.
     

  • All (i), (ii), (iii) and (iv) are correct.
     

Question 30

The following function computes the maximum value contained in an integer array p[] of size n (n >= 1) 
 

C
int max(int *p, int n)
{
    int a=0, b=n-1;
    while (__________)
    {
        if (p[a] <= p[b])
        {
            a = a+1;
        }
        else
        {
            b = b-1;
        }
    }
    return p[a];
}

The missing loop condition is
 

  • a != n
     

  • b != 0
     

  • b > (a + 1)
     

  • b != a
     

There are 50 questions to complete.

Last Updated :
Take a part in the ongoing discussion