50 C Language MCQs with Answers

  • Last Updated : 22 Feb, 2022


Question 1
#include "stdio.h"

int main() 

{ 

  int x, y = 5, z = 5; 

  x = y == z; 

  printf("%d", x); 

  

  getchar(); 

  return 0; 

}
A

0
 

B

1
 

C

5
 

D

Compiler Error
 

C Operators    50 C Language MCQs with Answers    
Discuss it


Question 1 Explanation: 

The crux of the question lies in the statement x = y==z. The operator == is executed before = because precedence of comparison operators (<=, >= and ==) is higher than assignment operator =. 
The result of a comparison operator is either 0 or 1 based on the comparison result. Since y is equal to z, value of the expression y == z becomes 1 and the value is assigned to x via the assignment operator.
 

Question 2

C

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

GeeksQuiz
 

B

Quiz
 

C

1005
 

D

Compile-time error
 

C Input and Output    50 C Language MCQs with Answers    
Discuss it


Question 2 Explanation: 

printf is a library function defined under stdio.h header file. The compiler adds 5 to the base address of the string through the expression 5 + "GeeksQuiz" . Then the string "Quiz" gets passed to the standard library function as an argument.

Question 3

C

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

What is the output of the above program?
 

A

3
 

B

4
 

C

5
 

D

Compile-time error
 

C Operators    50 C Language MCQs with Answers    
Discuss it


Question 3 Explanation: 

In C, prefix and postfix operators need l-value to perform operation and return r-value. The expression (++i)++ when executed increments the value of variable i(i is a l-value) and returns r-value. The compiler generates the error(l-value required) when it tries to post-incremeny the value of a r-value.
 

Question 4

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?
 

A

3
 

B

5
 

C

3 or 5 depending on value of X
 

D

Compile time error
 

C Macro & Preprocessor    50 C Language MCQs with Answers    
Discuss it


Question 4 Explanation: 

In the first look, the output seems to be compile-time error because macro X has not been defined. In C, if a macro is not defined, the pre-processor assigns 0 to it by default. Hence, the control goes to the conditional else part and 5 is printed. See the next question for better understanding.
 

Question 5

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)
 

A

22 bytes
 

B

14 bytes
 

C

18 bytes
 

D

10 bytes
 

C Structure & Union    50 C Language MCQs with Answers    
Discuss it


Question 5 Explanation: 

Short array s[5] will take 10 bytes as size of short is 2 bytes. 

When we declare a union, memory allocated for the union is equal to memory needed for the largest member of it, and all members share this same memory space. Since u is a union, memory allocated to u will be max of float y(4 bytes) and long z(8 bytes). So, total size will be 18 bytes (10 + 8).
 

Question 6

In C, parameters are always 
 

A

Passed by value
 

B

Passed by reference
 

C

Non-pointer variables are passed by value and pointers are passed by reference
 

D

Passed by value result
 

C Functions    50 C Language MCQs with Answers    
Discuss it


Question 6 Explanation: 

In C, function parameters are always passed by value. Pass-by-reference is simulated in C by explicitly passing pointer values.
 

Question 7

Which of the following is true about return type of functions in C?
 

A

Functions can return any type
 

B

Functions can return any type except array and functions
 

C

Functions can return any type except array, functions and union
 

D

Functions can return any type except array, functions, function pointer and union
 

C Functions    50 C Language MCQs with Answers    
Discuss it


Question 7 Explanation: 

In C, functions can return any type except arrays and functions. We can get around this limitation by returning pointer to array or pointer to function.
 

Question 8

Which of the following is not a storage class specifier in C?
 

A

auto
 

B

register
 

C

static
 

D

extern
 

E

volatile
 

C Storage Classes and Type Qualifiers    50 C Language MCQs with Answers    
Discuss it


Question 8 Explanation: 

volatile is not a storage class specifier. volatile and const are type qualifiers.

Question 9

Which of the following is not a logical operator?
 

A

&& 
 

B


 

C

|| 
 

D


 

C Operators    50 C Language MCQs with Answers    
Discuss it


Question 9 Explanation: 

&&- Logical AND 
!- Logical NOT 
||- Logical OR 
|- Bitwise OR(used in bitwise manipulations)
 

Question 10

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

A

.p
 

B

.i
 

C

.o
 

D

.m
 

C Macro & Preprocessor    50 C Language MCQs with Answers    
Discuss it


Question 10 Explanation: 

After the pre-processing of a C program, a .i file is generated which is passed to the compiler for compilation. 
 

There are 50 questions to complete.
My Personal Notes arrow_drop_up