• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

50 C Language MCQs with Answers

Question 1

C
#include <stdio.h>
// Assume base address of \"GeeksQuiz\" to be 1000
int main()
{
   printf(5 + \"GeeksQuiz\");
   return 0;
}
  • GeeksQuiz
     

  • Quiz
     

  • 1005
     

  • Compile-time error
     

Question 2

What does the following C statement mean? 
 

C
 scanf(\"%4s\", str);
  • Read exactly 4 characters from console.
     

  • Read maximum 4 characters from console.
     

  • Read a string str in multiples of 4
     

  • Nothing
     

Question 3

Consider the following ANSI C code segment: 

z=x + 3 + y->f1 + y->f2; 
for (i = 0; i < 200; i = i + 2) 

if (z > i) 

p = p + x + 3; 
q = q + y->f1; 
} else 

p = p + y->f2; 
q = q + x + 3; 


Assume that the variable y points to a struct (allocated on the heap) containing two fields f1 and f2, and the local variables x, y, z, p, q, and i are allotted registers. Common sub-expression elimination (CSE) optimization is applied on the code. The number of addition and the dereference operations (of the form y ->f1 or y ->f2) in the optimized code, respectively, are:
 

  • 403 and 102
     

  • 203 and 2
     

  • 303 and 102
     

  • 303 and 2
     

Question 4

Which of the following is true?
 

  • gets() doesn\'t do any array bound testing and should not be used. 
     

  • fgets() should be used in place of gets() only for files, otherwise gets() is fine
     

  • gets() cannot read strings with spaces
     

  • None of the above
     

Question 5

Predict the output?
C
int fun(char *str1){  char *str2 = str1;  while(*++str1);  return (str1-str2);}int main(){  char *str = \"GeeksQuiz\";  printf(\"%d\", fun(str));  return 0;}
  • 10
     

  • 9
     

  • 8
     

  • Random Number
     

Question 6

Given that x = 7.5, j = -1.0, n = 1.0, m = 2.0 the value of - - x + j == x>n> = m is: 
 

  • 0
     

  • 1
     

  • 2
     

  • 3
     

Question 7

If n has 3, then the statement a[++n]=n++;
 

  • assigns 3 to a[5]
     

  • assigns 4 to a[5]
     

  • assigns 4 to a[4]
     

  • what is assigned is compiler dependent
     

Question 8

#include "stdio.h"

int main() 

{ 

  int x, y = 5, z = 5; 

  x = y == z; 

  printf("%d", x); 

  

  getchar(); 

  return 0; 

}
  • 0
     

  • 1
     

  • 5
     

  • Compiler Error
     

Question 9

C
#include <stdio.h>
int main()
{
    int i = 3;
    printf(\"%d\", (++i)++);
    return 0;
}

What is the output of the above program?
 

  • 3
     

  • 4
     

  • 5
     

  • Compile-time error
     

Question 10

Which of the following is not a logical operator?
 

  • && 
     


  •  

  • || 
     


  •  

There are 50 questions to complete.

Last Updated :
Take a part in the ongoing discussion