• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

50 C Language MCQs with Answers

Question 11

Consider the following pseudocode: 
 

x:=1;
i:=1;
while (x ? 500)
begin
x:=2x ;
i:=i+1;
end


What is the value of i at the end of the pseudocode?
 

  • 4
     

  • 5
     

  • 6
     

  • 7
     

Question 12

In _______, the bodies of the two loops are merged together to form a single loop provided that they do not make any references to each other.
 

  • Loop unrolling
     

  • Strength reduction
     

  • Loop concatenation
     

  • Loop jamming
     

Question 13

How many lines of output does the following C code produce? 
 

C
#include<stdio.h>
float i=2.0;
float j=1.0;
float sum = 0.0;
main()
{
    while (i/j > 0.001)
    {
        j+=j;
        sum=sum+(i/j);
        printf(\"%f\\n\", sum);
    }
}
  • 8
     

  • 9
     

  • 10
     

  • 11
     

Question 14

C
#include <stdio.h>

int main()
{
    unsigned int i = 65000;
    while (i++ != 0);
    printf(\"%d\", i);
    return 0;
}
  • Infinite Loop
     

  • 0
     


  •  

  • Run Time Error
     

Question 15

Consider the C program below. 
 

C
#include <stdio.h>
int *A, stkTop;
int stkFunc (int opcode, int val)
{
    static int size=0, stkTop=0;
    switch (opcode)
    {
    case -1:
        size = val;
        break;
    case 0:
        if (stkTop < size ) A[stkTop++]=val;
        break;
    default:
        if (stkTop) return A[--stkTop];
    }
    return -1;
}
int main()
{
    int B[20];
    A=B;
    stkTop = -1;
    stkFunc (-1, 10);
    stkFunc (0, 5);
    stkFunc (0, 10);
    printf (\"%d\\n\", stkFunc(1, 0)+ stkFunc(1, 0));
}

The value printed by the above program is ___________
 

  • 9
     

  • 10
     

  • 15
     

  • 17
     

Question 16

Consider the following C declaration 
 

struct (
short s[5];
union {
float y;
long z;
}u;
}t;


Assume that the objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment consideration, is
 

  • 22 bytes
     

  • 18 bytes
     

  • 14 bytes
     

  • 10 bytes
     

Question 17

Consider the following C declaration 
 

C
struct { 
    short s[5];
    union { 
         float y; 
         long z; 
    }u; 
} t;

Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, is (GATE CS 2000)
 

  • 22 bytes
     

  • 14 bytes
     

  • 18 bytes
     

  • 10 bytes
     

Question 18

Which of the following operators can be applied on structure variables?
 

  • Equality comparison ( == )
     

  • Assignment ( = )
     

  • Both of the above
     

  • None of the above
     

Question 19

Pick the best statement for the below program snippet: 
 

C
struct {int a[2];} arr[] = {1,2};
  • No compile error and it’ll create array arr of 2 elements. Each of the element of arr contain a struct field of int array of 2 elements. arr[0]. a[0] would be 1 and arr[1].a[0] would be 2.
     

  • No compile error and it’ll create array arr of 2 elements. Each of the element of arr contain a struct field of int array of 2 elements. arr[0]. a[0] would be 1 and arr[0].a[1] would be 2. The second element arr[1] would be ZERO i.e. arr[1].a[0] and arr[1].a[1] would be 0.
     

  • No compile error and it’ll create array arr of 1 element. Each of the element of arr contain a struct field of int array of 2 elements. arr[0]. a[0] would be 1 and arr[0].a[1] would be 2.
     

  • None of the above

Question 20

The following C declarations 
 

C
struct node
{
   int i;
   float j;
};
struct node *s[10] ;

define s to be
 

  • An array, each element of which is a pointer to a structure of type node
     

  • A structure of 2 fields, each field being a pointer to an array of 10 elements
     

  • A structure of 3 fields: an integer, a float, and an array of 10 elements
     

  • An array, each element of which is a structure of type node.
     

There are 50 questions to complete.

Last Updated :
Take a part in the ongoing discussion