Create New Post

C MCQs - 12

  1. What will be the output of the following code snippet?
 #include <stdio.h>
int main() {
    int x = 5;
    printf("%d\n", x++);
    printf("%d\n", ++x);
    return 0;
}
 

a) 5, 7  
b) 5, 6  
c) 6, 7  
d) 6, 6  

**Answer: b) 5, 6**

112. In C, what is the purpose of the free() function?

a) It deallocates memory.  
b) It fills a block of memory with a particular value.  
c) It copies a block of memory to another block.  
d) It concatenates two strings.  

**Answer: a) It deallocates memory.**
 

113. What will be the output of the following code?

 
#include <stdio.h>
int main() {
    char str[10] = "Hello";
    printf("%s\n", str);
    return 0;
}
 

a) Hello  
b) Compiler error  
c) Undefined behavior  
d) No output  

**Answer: a) Hello**
 

114. Which of the following functions is used to convert a string to an integer in C?

a) atoi()  
b) itoa()  
c) atof()  
d) stoi()  

**Answer: a) atoi()**
 

115. What will be the output of the following code?

 
#include <stdio.h>
int main() {
    int x = 5, y = 10;
    printf("%d\n", (x < y) ? x : (y < x) ? y : (x = y));
    return 0;
}


a) 5  
b) 10  
c) 15  
d) Compiler error  

**Answer: a) 5**

116. In C, what is the purpose of the fgets() function?

a) To read a line from a file  
b) To read a character from a file  
c) To read a line from the console  
d) To read a character from the console  

**Answer: a) To read a line from a file**
 

117. What will be the output of the following code?

 
#include <stdio.h>
int main() {
    int x = 5;
    printf("%f\n", (float)x);
    return 0;
}
 

a) 5.000000  
b) 5  
c) Compiler error  
d) Undefined behavior  

**Answer: a) 5.000000**
 

118. Which of the following is the correct syntax to declare a structure in C?

a) struct { int x; };  
b) structure { int x; };  
c) struct x { int x; };  
d) struct { int x; } x;  

**Answer: c) struct x { int x; };**
 

119. What will be the output of the following code?

 
#include <stdio.h>
int main() {
    int x = 5;
    printf("%p\n", &x);
    return 0;
}
 

a) Address of x  
b) Value of x  
c) Address of ptr  
d) Compiler error  

**Answer: a) Address of x**
 

120. Which of the following functions is used to compare two strings in C?

a) strcmp()  
b) strcat()  
c) strlen()  
d) strcpy()  

**Answer: a) strcmp()**

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

14112