C is a general-purpose, procedural computer programming language, C language supports structured programming, lexical variable scope, and recursion, with a static type system. C language is used to develop software like operating systems, databases, compilers, and so on.
C language MCQs: This section contains multiple-choice questions and answers on the C programming language. It will help the students to test their skills and prepare well for their exams.
1. C language was developed by ___.
- Dennis Rechard
- Dennis M. Ritchie
- Bjarne Stroustrup
- Anders Hejlsberg
Answer: B) Dennis M. Ritchie
Explanation:
C programming language was developed by an American computer scientist Dennis M. Ritchie at Bell Laboratories (formerly AT&T Bell Laboratories).
2. In which year was C language developed?
- 1962
- 1978
- 1979
- 1972
Answer: D) 1972
Explanation:
C programming language was developed by Dennis Ritchie at Bell Laboratories in 1972.
3. C language is a successor to which language?
- Basic
- Cobol
- C++
- B
Answer: D) B
Explanation:
C programming language is a successor to the programming language B.
4. C is a ___.
- Low level language
- High level language
- Medium level language
- None of the above
Answer: C) Medium level language
Explanation:
C is a medium-level language because it contains the features of low-level language as well as high-level language.
5. How many keywords are there in C language?
- 32
- 33
- 64
- 18
Answer: A) 32
Explanation:
C language has only 32 keywords.
6. C language is a ___.
- Procedural oriented programming language
- General purpose programming language
- Structured programming
- All of the above
Answer: D) All of the above
Explanation:
C programming language is a general-purpose, procedural computer programming language that supports structured programming also.
7. Which is not a valid keyword in C language?
- for
- while
- do-while
- switch
Answer: C) do-while
Explanation:
do-while is not a valid keyword in the C programming language. It’s a control statement. ‘do’ and ‘while’ are the separate keywords. The rest of all ‘for’, ‘while’, and ‘switch’ are the valid keywords in C.
8. What is an identifier in C language?
- An identifier is a combination of alphanumeric characters used for conditional and control statements
- An identifier is a combination of alphanumeric characters used for any variable, function, label name
- Both A and B
- None of the above
Answer: B) An identifier is a combination of alphanumeric characters used for any variable, function, label name
Explanation:
An identifier is a combination of alphanumeric characters used for any variable, function, label name. An identifier is a name that is used to identify the variables/ constants, functions, arrays, label name, and user-defined data.
9. A C-style comment, simply surround the text with ___.
- /* and */
- // and //
- //
- /** and **/
Answer: A) /* and */
Explanation:
A C-style comment, simply surround the text with /* and */.
10. Can we place comments between the statement to comments a part of the code?
- Yes
- No
Answer: A) Yes
Explanation:
Yes, we can place comments between the statement to comments a part of the code.
Example:
printf(/*”Hello World”*/ “Hey, how are you?”);
11. ___ is an informal name for ISO/IEC 9899:1999, a past version of the C programming language standard?
- C
- C++
- C89
- C99
Answer: D) C99
Explanation:
C99 is an informal name for ISO/IEC 9899:1999, a past version of the C programming language standard.
12. In which version of C language, the C++ Style comment (//) are introduced?
- C17
- C18
- C89
- C99
Answer: D) C99
Explanation:
C language version C99 introduced C++ style comment (//), they can be used to comment a single line.
13. The C source file is processed by the ___.
- Interpreter
- Compiler
- Both Interpreter and Compiler
- Assembler
Answer: B) Compiler
Explanation:
The C source file is processed by the compiler.
14. How many whitespace characters are allowed in C language?
- 2
- 3
- 4
- 5
Answer: D) 5
Explanation:
There are 5 whitespace characters are allowed in C language, they are:
- Space
- Horizontal tab
- Vertical tab
- Form feed
- New-line
15. How many punctuation characters are allowed in C language?
- 29
- 30
- 31
- 32
Answer: A) 29
Explanation:
There are 29 punctuation characters are allowed in C language, they are:
_ { } [ ] # ( ) < > % : ; . ? * + – / ^ & | ~ ! = , \ ” ‘
16. What is the extension of a C language source file?
- .c
- .cpp
- .c99
- .h
Answer: A) .c
Explanation:
The extension of a C language source file is “.c”.
17. What is the extension of a C language header file?
- .c
- .cpp
- .c99
- .h
Answer: D) .h
Explanation:
The extension of a C language source file is “.h”.
18. To develop which operating, C language was invented?
- Linux
- Unix
- Android
- Mac
Answer: B) Unix
Explanation:
C language was invented to develop Unix operating system.
19. Does C language support object-oriented approach?
- Yes
- No
Answer: B) No
Explanation:
C language does not support object-oriented approach.
20. Which is/are the disadvantage(s) of C language?
- No Garbage Collection
- Inefficient Memory Management
- Low level of abstraction
- Lack of Object Orientation
- All of the above
Answer: E) All of the above
Explanation:
The main disadvantages of C language are:
- No Garbage Collection
- Inefficient Memory Management
- Low level of abstraction
- Lack of Object Orientation
2) C Data Types, Operators and Expressions MCQs
21. Which are the fundamental data types in C?
- char
- int
- float
- All of the above
Answer: D) All of the above
Explanation:
The fundamental / basic data types in C language:
- char
- int
- float
22. How many byte(s) does a char type take in C?
- 1
- 2
- 3
- 4
Answer: A) 1
Explanation:
The char data type takes one byte in the memory.
23. For which type, the format specifier “%i” is used?
- int
- char
- float
- double
Answer: A) int
Explanation:
In C programming language, both of the format specifier %d and %i are used for int type, where %d specifies the type of variable as decimal and %i specifies the type as integer.
24. What is the difference between float and double in C?
- both are used for the same purpose
- double can store just double value as compare to float value
- double is an enhanced version of float and was introduced in C99
- double is more precise than float and can store 64 bits
Answer: D) double is more precise than float and can store 64 bits
Explanation:
In C programming language, the double is more precise than float and can store 64 bits.
25. Which is the correct format specifier for double type value in C?
- %d
- %f
- %lf
- %LF
Answer: C) %lf
Explanation:
The %lf is used to represent a double type value in C programming language.
26. The short type represents ___.
- int
- float
- unsigned int
- short int
Answer: C) unsigned int
Explanation:
The short type represents short int in C language.
27. How many byte(s) does a short type take in C?
- 1
- 2
- 3
- 4
Answer: B) 2
Explanation:
In C programming language, the short or short int takes 2 bytes (16 bits) in memory.
28. What is the correct syntax to declare a variable in C?
- data_type variable_name;
- data_type as variable_name;
- variable_name data_type;
- variable_name as data_type;
Answer: A) data_type variable_name;
Explanation:
In C language, the correct syntax to declare a variable is:
data_type variable_name;
Where, data_type is the type of data (such as int, char, float, etc) and variable_name is a valid identifier. For example: int age;
29. How many types of qualifiers are there in C language?
- 2
- 3
- 4
- 5
Answer: B) 3
Explanation:
There are 3 types of qualifiers in C language, they are:
- Size qualifiers
- Sign qualifiers
- Type qualifiers
30. Which is/are the size qualifier(s) in C language?
- short
- long
- double
- Both A. and B
Answer: D) Both A. and B.
Explanation:
The size qualifiers are short and long.
31. Which is/are the sign qualifier(s) in C language?
- signed
- unsigned
- long
- Both A. and B
Answer: D) Both A. and B.
Explanation:
The sign qualifiers are used to specify the signed nature of an integer type. The sign qualifiers are signed and unsigned.
32. Which is/are the type qualifier(s) in C language?
- const
- volatile
- static
- Both A. and B
Answer: D) Both A. and B.
Explanation:
The type qualifiers are const and “volatile”.
33. Which is correct with respect to the size of the data types in C?
- char > int > float
- char < int < float
- int < char < float
- int < chat > float
Answer: B) char < int < float
Explanation:
The correct order of the data types as per the size is: char < int > float.
34. Which operator is used to find the remainder of two numbers in C?
- /
- \
- %
- //
Answer: C) %
Explanation:
The % operator is known as “Modulus Operator” and it is used to find the remainder of two numbers.
35. Which of the following is not an arithmetic expression?
- x = 10
- x /= 10
- x %= 10
- x != 10
Answer: D) x != 10
Explanation:
x != 10 is not a valid arithmetic expression.
36. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int x = 20;
x %= 3;
printf(“%d”,x);
return 0;
}
- 2
- 2.5
- Error
- Warning
Answer: A) 2
Explanation:
In the above code, the value of x is 20 and then in the next statement, the expression is x %= 3. That will be evaluate as:
x %= 3;
x = x % 3;
x = 20 %3;
x = 2
37. What will be the output of the following C code?
#include <stdio.h>
int main()
{
float x = 21.0;
x %= 3.0;
printf(“%f”,x);
return 0;
}
- 7
- 7.00
- 7.000000
- Error
Answer: D) Error
Explanation:
In the above code, we are performing modulus operation with float values. Modulus operator doesn’t work with float and double operands. Thus, the output will be:
error: invalid operands to binary % (have ‘float’ and ‘double’)
38. What will be the output of the following C code?
#include <stdio.h>
int main()
{
float x = 23.456;
printf(“%.2f”,x);
return 0;
}
- 23.45600
- 23.456
- 23.45
- 23.46
Answer: D) 23.46
Explanation:
In the above code, the value of x is 23.456 and we are printing the value of x using the %.2f format specifier. %.2f rounds the value and prints the 2 digits after the decimal point.
39. What will be the output of the following C code?
#include <stdio.h>
void main()
{
int x = 10;
int y = x++ + 20;
printf(“%d,%d”,x,y);
return 0;
}
- 11,30
- 11,31
- 10,30
- 10,31
Answer: A) 11,30
Explanation:
In the above code, we are using a post-increment statement (x++), post-increment increases the value after evaluating the current expression. Thus, the value of y will be 30 and then x will be 11.
40. Increment (++) and decrement (–) are the ___ operators in C?
- Unary
- Binary
- Ternary
- None of the above
Answer: A) Unary
Explanation:
Increment (++) and decrement (–) are the unary operators. They need one operand to perform the operation.
41. What will be the output of the following C code?
#include <stdio.h>
int main()
{
unsigned char c=290;
printf(“%d”,c);
return 0;
}
- 290
- 256
- 34
- Garbage
Answer: C) 34
Explanation:
290 is beyond the range of unsigned char. Its corresponding value printed is: (290 % (UCHAR_MAX +1) where UCHAR_MAX represents highest (maximum) value of unsigned char type of variable. The value of UCHAR_MAX=255. Thus it prints 290 % (UCHAR_MAX+1)=34
42. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int a=0;
a=5||2|1;
printf(“%d”,a);
return 0;
}
- 1
- 7
- 0
- 8
Answer: A) 1
Explanation:
Bitwise OR operator (|) has precedence over logical OR operator (||). Thus the expression 5 || 2 | 1 is actually 5 || (2 |1).
Now,
2= 0000 0010
1= 0000 0001
2|1= 0000 0011=3
5 || 3 returns true as both are nonzero
Thus a=1
43. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int x =-100;
–100;
printf(“%d”,x);
return 0;
}
- 100
- -100
- 0
- Error
Answer: B) -100
Explanation:
The statement “-100;” is evaluated and this does not affect the value of “x”.
44. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int a,b,c;
a=0x10; b=010;
c=a+b;
printf(“%d”,c);
return 0;
}
- 20
- 24
- Garbage
- Error
Answer: B) 24
Explanation:
0x10 is hex value it’s decimal value is 16 and 010 is an octal value it’s decimal value is 8, hence answer will be 24.
45. Which C keyword is used to extend the visibility of variables?
- extend
- extends
- extern
- auto
Answer: C) extern
Explanation:
The “extern: keyword used to define an extern variable, that can be accessed in any source file. i.e., extern is used to extend the visibility of variables in C language.
46. What is the name of “&” operator in C?
- Ampersand
- And
- Address of
- None of the above
Answer: C) Address of
Explanation:
The “&” operator is known as ‘Address Of’ operator which is used to access the address of a variable.
47. Which of the following are valid decision-making statements in C?
- if
- switch
- nested if
- All of these
Answer: D) All of these
Explanation:
All valid decision-making statements in C program are:
- if statement
- if-else statement
- nested if statement
- switch statement
- nested switch statement
48. Decision making in the C programming language is ___.
- Repeating the same statement multiple times
- Executing a set of statements based on some condition
- Providing a name of the block of code
- All of these
Answer: B) Executing a set of statements based on some condition
Explanation:
Decision-making in C programming is executing a block of code to be executed by the program based on some condition.
49. Which of the following is a true value in C programming?
- 1
- “includehelp”
- ! NULL
- All of these
Answer: D) All of these
Explanation:
All non-zero and non-null values in C programming are true.
50. Ternary operator in C programming is ___.
- if-else-if
- ? :
- ? ; ?
- None of these
Answer: B) ? :
Explanation:
Ternary operator is used to execute expressions based on the given condition.
51. What will be the output of the following C code?
#include <stdio.h>
int main()
{
printf((43 > 43) ? “value 1 is greater!” : “value 1 is not greater!”);
return 0;
}
- value 1 is not greater
- value 1 is greater
- Error
- None of these
Answer: A) value 1 is not greater
52. What is the correct syntax of if statement in C program?
- if(condition){
} - if(condition) :
- If { [condition] }
- None of these
Answer: A)
if(condition){
}
Explanation:
The correct syntax of if statement in C program is:
if(condition){
// code to be executed
}
53. The if statement is a conditional statement?
- True
- False
Answer: A) True
Explanation:
The if statement is a conditional statement, i.e., the block is executed based on the given condition.
54. When the condition of if statement is false, the flow of code will ___.
- go into the if block
- Exit the program
- Continue the code after skipping the if block
- None of these
Answer: C) Continue the code after skipping the if block
Explanation:
When the condition of if statement is false, the code after the if block will be executed and the if block code is skipped.
55. What will be the result of the following condition?
(! (25 > 25))
- True
- False
- Error
- None of these
Answer: A) True
56. Which statement is required to execute a block of code when the condition is false?
- for
- if
- else
- All of these
Answer: C) else
Explanation:
In the if-else block, the if block is executed when condition is True and else block is executed when condition is false.
57. Can the else statement exist without the if statement in C?
- Yes
- No
Answer: B) No
Explanation:
The else statement needs an if statement to execute the block.
58. Which of these if…else block syntax is correct?
- if(condition){
}
else {
} - if(condition){
}
else(condition){
} - if{
}
else {
} - None of these
Answer: A)
if(condition){
}
else {
}
Explanation:
The syntax of if…else block of code in C is:
if(condition){
// true block
}
else {
// false block
}
59. The if-elseif-else statement in C programming is used?
- Create multiple conditional statements
- Return values
- Loop in if-else block
- All of these
Answer: A) Create multiple conditional statements
Explanation:
The if-elseif-else statement is a statement which contains multiple statements based on conditions.
60. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int marks = 43;
if (marks > 90)
printf(“Grade : A “);
else if (marks > 75)
printf(“Grade : B “);
else if (marks > 60)
printf(“Grade : C “);
if (marks > 40)
printf(“Grade : D “);
else
printf(“Fail “);
return 0;
}
- Grade : A
- Grade : B
- Grade : C
- Grade : D
Answer: D) Grade : D
61. How many expressions can be checked using if…elseif…else statement?
- 100
- 1
- Infinite
- None of these
Answer: C) Infinite
Explanation:
You can execute any number of expressions using if-elseif-else statements, each elseif statement containing one condition.
62. Is it possible to nest if-else statements in C programming?
- Yes
- No
Answer: A) Yes
Explanation:
Nesting of if-else statements in C programming is possible.
63. Which of the following syntax is correct for nested if-else statements?
- if(exp1){
- if(exp2){
- }
- }
- else {
- if(exp3){
- }
- }
- if(exp1){
- }else {
- }
- if{}
- None of these
Answer: A)
if(exp1){
if(exp2){
}
}
else {
if(exp3){
}
}
Explanation:
The correct syntax for nested if-else statements in C programming is:
if(exp1){
if(exp2){
}
}
else {
if(exp3){
}
}
64. What will be the output of the following C code?
#include <stdio.h>
int main(){
int n = 65;
if (n >= 75) {
if (n >= 95) {
printf(“Excellent”);
}
else
printf(“Pass”);
}
else
printf(“Fail”);
}
- Excellent
- Pass
- Fail
- None of these
Answer: C) Fail
65. Multiple values of the same variable can be tested using ___.
- switch
- for
- Function
- All of these
Answer: A) switch
Explanation:
The switch statement in C is used to test for multiple values of a variable.
66. Without a break statement in switch what will happen?
- All cases will work properly
- Cases will fall through after matching the first check
- Switch will throw error
- All of these
Answer: B) Cases will fall through after matching the first check
Explanation:
The break statement is used to terminate the current flow of code. And if it is not present in the switch statement, the cases will execute all cases after the matched case.
67. When all cases are unmatched which case is matched in a switch statement?
- Default case
- First case
- No case
- None of these
Answer: A) Default case
Explanation:
The default case of switch statement is executed when no other case is matched.
68. What will be the output of the following C code?
#include <stdio.h>
int main(){
char grade = ‘B’;
switch (grade) {
case ‘A’:
printf(“Excellent!\n“);
case ‘B’:
case ‘C’:
printf(“Well done\n“);
case ‘D’:
printf(“You passed\n“);
case ‘F’:
printf(“Better try again\n“);
break;
default:
printf(“Invalid grade\n“);
}
}
- Well done
- You passed
- Better try again
- All of these
Answer: D) All of these
Explanation:
There is no break statement in case B, Case C, case D. the code will fall through executing all the print statements.
69. Loops in C programming are used to ___.
- Execute a statement based on a condition
- Execute a block of code repeatedly
- Create a variable
- None of these
Answer: B) Execute a block of code repeatedly
Explanation:
Loops in programming are used to execute a block of code repeatedly.
70. Which of these is an exit-controlled loop?
- for
- if
- do…while
- while
Answer: C) do…while
Explanation:
The do…while loop check for a condition after executing the loop block once. Hence, it is called an exit-controlled loop.
71. Which statements are used to change the execution sequence?
- Loop control statement
- Function statement
- Conditional statement
- All of these
Answer: A) Loop control statement
Explanation:
Loop control statements in C are used to change the execution sequence of the loop.
72. What will happen if the loop condition will never become false?
- Program will throw an error
- Program will loop infinitely
- Loop will not run
- None of these
Answer: B) Program will loop infinitely
Explanation:
An infinite loop in a program is a condition when the loop continues when the loop continues to run infinitely because the condition never becomes false.
73. Which of these statements is correct in case of while loop in C?
- Executes the block till the condition become false
- Is an entry controlled loop
- There might be condition when the loop will not execute at all
- All of these
Answer: D) All of these
Explanation:
All of the above statements are true in the case of while loop. While loop is an entry-controlled loop, the block executes when the condition becomes false.
74. Which of the following is valid syntax for creating a while loop?
- while{
- } (condition)
- while(condition){
- }
- while{
- }
- All of these
Answer: B)
while(condition){
}
Explanation:
The correct syntax for creating a while loop is:
while(condition){
}
75. What will be the output of the following C code?
#include <stdio.h>
int main(){
int a = 11;
while (a < 20) {
printf(“%d “, a);
a += 2;
}
return 0;
}
- 11 13 15 17 19
- 11 12 13 14 15 16 17 18 19 20
- 11 13 15 17 19 21
- None of these
Answer: A) 11 13 15 17 19
76. Which loop executes the block a specific number of times?
- while loop
- for loop
- do…while loop
- All of these
Answer: B) for loop
Explanation:
The for loop executes the block a specific number of times.
77. Which of the following parts of the for loop can be eliminated in C?
- init
- condition
- increment
- All of these
Answer: D) All of these
Explanation:
Syntax of for loop:
for(init, condition, increment){
}
Inside the initialization statement (init), any of the three init or condition or increment can be eliminated i.e., all are optional. The loop can work without them also.
78. When all parts of the for loop are eliminated, what will happen?
- For loop will not work
- Infinite for loop
- Error
- None of these
Answer: B) Infinite for loop
Explanation:
On eliminating all the parts of a for loop an infinite for loop will run.
79. When the condition of the do-while loop is false, how many times will it execute the code?
- 0
- 1
- Infinite
- All of these
Answer: B) 1
Explanation:
The do-while loop is an exit-controlled loop, hence it will run at least once, even if the condition becomes false.
80. Can a loop be nested in C programming?
- Yes
- No
Answer: A) Yes
Explanation:
Yes, the nesting of loop is possible in C programming language.
81. What will be the output of the following C code?
#include <stdio.h>
int main(){
int i, j;
for (i = 2; i < 10; i++) {
for (j = 2; j <= (i / j); j++)
if (!(i % j))
break;
if (j > (i / j))
printf(“%d “, i);
}
return 0;
}
- 2 3 4 5 6 7 8 9
- 3 5 7 9
- 2 3 5 7
- 2 3 5 7 11
Answer: C) 2 3 5 7
82. A string is terminated by ___.
- Newline (‘\n’)
- Null (‘\0’)
- Whitespace
- None of the above
Answer: B) Null (‘\0’)
Explanation:
In C programming language, a string is a sequence of characters terminated with a null character \0.
83. Consider the below statement, can we assign a string to variable like this:
char c[100];
c = “C programming”;
- Yes
- No
Answer: B) No
Explanation:
No, we cannot assign a string like this. Because string is a character array and array type is not assignable. To assign a string to the character array, we need to use strcpy() function.
84. Which format specifier is used to read and print the string using printf() and scanf() in C?
- %c
- %str
- %p
- %s
Answer: D) %s
Explanation:
The format specifier “%s” is used to read and print the string using printf() and scanf() in C.
Example:
#include <stdio.h>
int main()
{
char name[30];
printf(“Input name: “);
scanf(“%s”, name);
printf(“Given name is: %s”, name);
return 0;
}
/*
Output:
Input name: Alvin
Given name is: Alvin
*/
85. Which function is used to read a line of text including spaces from the user in C?
- scanf()
- getc()
- fgets()
- All of the above
Answer: C) fgets()
Explanation:
In C programming language, the fgets() function can be used to read a line of text including spaces from the user.
Syntax:
fgets(variable_name, sizeof(size), stdin);
86. Which function is used to concatenate two strings in C?
- concat()
- cat()
- stringcat()
- strcat()
Answer: D) strcat()
Explanation:
In C programming language, the strcat() function is used to concatenate two strings.
Syntax:
strcat(s1, s2);
This function concatenates string s2 onto the end of string s1.
87. What will be the output of the following C code?
#include <stdio.h>
int main()
{
char str1[] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ };
char str2[] = “Hello”;
printf(“%ld,%ld”, sizeof(str1), sizeof(str2));
return 0;
}
- 5,5
- 6,6
- 5,6
- None of the above
Answer: C) 5,6
Explanation:
str1 is initialized with the characters and there are only 5 characters. Thus, the length of the str is 5. While, str2 is initialized with the string “Hello”, when we initialized the string in this way – a null (‘\0’) character is inserted after the string. Thus, the length of str2 is 6.
88. What will be the output of the following C code?
#include <stdio.h>
int main()
{
char str1[] = “Hello”;
char str2[10];
str2 = str1;
printf(“%s,%s”, str1, str2);
return 0;
}
- Hello,
- Hello,Hello
- Hello,HelloHello
- Error
Answer: D) Error
Explanation:
There will be a compilation error, because we cannot assign a string like this (str2 = str1). To resolve this issue, we have to use strcpy(str2,str1).
The output will be:
main.c:8:10: error: assignment to expression with array type
8 | str2 = str1;
| ^
89. What will be the output of the following C code? (If the input is “Hello world”)
#include <stdio.h>
int main()
{
char str[30];
scanf(“%s”, str);
printf(“%s”, str);
return 0;
}
- Hello world
- Hello
- Hello world\0
- Error
Answer: B) Hello
Explanation:
When we read a string using the scanf() function, the input is terminated by the whitespace. Here, the input is “Hello world”, so only “Hello” will be stored to str. Thus, the output will be “Hello”.
90. Which function is used to compare two strings in C?
- strcmp()
- strcmpi()
- compare()
- cmpi()
Answer: A) strcmp()
Explanation:
The function strcmp() is used to compare two strings in C language.
The strcmp() is a built-in library function and is declared in <string.h> header file. This function takes two strings as arguments and compare these two strings lexicographically.
Syntax:
int strcmp(const char* str1, const char* str2);
91. Which function is used to compare two strings with ignoring case in C?
- strcmp()
- strcmpi()
- compare()
- cmpi()
Answer: B) strcmpi()
Explanation:
The function strcmpi() is used to compare two strings with ignoring case in C language.
The strcmpi() is a built-in library function and is declared in <string.h> header file. This function takes two strings as arguments and compare these two strings, it is similar to strcmp() function but the only difference is that strcmpi() function is not case sensitive.
Syntax:
int strcmpi(const char* str1, const char* str2);
92. Which is the correct syntax to declare an array in C?
- data_type array_name[array_size];
- data_type array_name{array_size};
- data_type array_name[];
- All of the above
Answer: A) data_type array_name[array_size];
Explanation:
The correct syntax to declare an array in C is:
data_type array_name[array_size];
93. You can access elements of an array by ___.
- values
- indices
- memory addresses
- All of the above
Answer: B) indices
Explanation:
You can access elements of an array by indices. Array indices starts from 0 to array_size -1.
94. Which is/are the correct syntax to initialize an array in C?
- data_type array_name[array_size] = {value1, value2, value3, …};
- data_type array_name[] = {value1, value2, value3, …};
- data_type array_name[array_size] = {};
- Both A and B
Answer: D) Both A and B
Explanation:
Both the options A and B are correct to initialize an array.
Example:
int mark[5] = {19, 10, 8, 17, 9};
// or
int mark[] = {19, 10, 8, 17, 9};
95. Array elements are always stored in ___ memory locations.
- Random
- Sequential
- Both A and B
- None of the above
Answer: B) Sequential
Explanation:
Array elements are always stored in sequential memory locations.
96. Let x is an integer array with three elements having value 10, 20, and 30. What will be the output of the following statement?
printf(“%u”,x);
- Prints the value of 0th element (i.e., 10)
- Prints the garbage value
- An error occurs
- Print the address of the array (i.e., the address of first (0th) element
Answer: D) Print the address of the array (i.e., the address of first (0th) element
Explanation:
If we print the array (in this case, x). The output will be the memory address of the array (i.e., the address of first (0th) element.
97. What will be the output of the following C program?
#include <stdio.h>
int main()
{
int x[5] = { 10, 20, 30 };
printf(“%d”, x[3]);
return 0;
}
- 0
- 30
- Garbage value
- Error
Answer: A) 0
Explanation:
In C language, when an array is partially initialized at the time of declaration then the remaining elements of the array is initialized to 0 by default.
98. What will be the output of the following C program?
#include <stdio.h>
int main()
{
int x[5] = { 10, 20, 30 };
printf(“%d”, x[-1]);
return 0;
}
- 0
- 10
- Garbage value
- Error
Answer: C) Garbage value
Explanation:
C language compiler does not check array with its bounds, when an index is out of the range the garbage value is printed.
99. What will be the output of the following C program?
#include <stdio.h>
int main()
{
int x[5] = { 10, 20, 30 };
printf(“%ld”, sizeof(x)/sizeof(x[0]));
return 0;
}
- 3
- 4
- 5
- 6
Answer: C) 5
Explanation:
The statement sizeof(x)/sizeof(x[0]) can be used to get the total numbers of elements, sizeof(x) will return the size of array while sizeof(x[0]) will return the size of first element i.e., size of the type. Their division will return the total number of elements.
100. What will be the output of the following C program?
#include <stdio.h>
int main()
{
int x[5] = { 10, 20, 30 };
printf(“%d”, x[3]);
return 0;
}
- 0
- 30
- Garbage value
- Error
Answer: A) 0
Explanation:
In C language, when an array is partially initialized at the time of declaration then the remaining elements of the array is initialized to 0 by default.
101. What will be the output of the following C program?
#include <stdio.h>
int main()
{
int x[5] = { 10, 20, 30 };
printf(“%d”, x[-1]);
return 0;
}
- 0
- 10
- Garbage value
- Error
Answer: C) Garbage value
Explanation:
C language compiler does not check array with its bounds, when an index is out of the range the garbage value is printed.
102. If we pass an array as an argument to a function, what actually gets passed?
- Value of elements in array
- First element of the array
- Base address of the array i.e., the address of the first element
- Address of the last element of array
Answer: C) Base address of the array i.e., the address of the first element
Explanation:
If we pass an array as an argument to a function – the base address of the array (the address of the first element) is passed to the function.
7) C Structures and Union MCQs
103. Which of the following is the collection of different data types?
- structure
- string
- array
- All of the above
Answer: A) structure
Explanation:
In C programming language, a structure is a user-defined data type which is the collection of different data types.
104. Which operator is used to access the member of a structure?
- –
- >
- *
- .
Answer: D) .
Explanation:
The dot (.) operator is used to access the member of a structure.
105. Which of these is a user-defined data type in C?
- int
- union
- char
- All of these
Answer: B) union
Explanation:
Union is a user defined data type in C.
106. “A union can contain data of different data types”. True or False?
- True
- False
Answer: A) True
Explanation:
Union is a user defined data structure which can store data variables of different data types.
107. Which keyword is used to define a union?
- un
- union
- Union
- None of these
Answer: B) union
Explanation:
The union is defined using the keyword union.
108. The size of a union is ___.
- Sum of sizes of all members
- Predefined by the compiler
- Equal to size of largest data type
- None of these
Answer: C) Equal to size of largest data type
Explanation:
The size of the union is equal to the size of the largest data type declared in the union.
109. All members of union ___.
- Stored in consecutive memory location
- Share same memory location
- Store at different location
- All of these
Answer: B) Share same memory location
Explanation:
All members of a union in C are stored at the same memory location.
110. Which of the below statements is incorrect in case of union?
- Union is a user-defined data structure
- All data share same memory
- Union stores methods too
- union keyword is used to initialize
Answer: C) Union stores methods too
Explanation:
Unions in C is a data structure which store data types but not the methods.
111. The members of union can be accessed using ___.
- Dot Operator (.)
- And Operator (&)
- Asterisk Operator (*)
- Right Shift Operator (>)
Answer: A) Dot Operator (.)
Explanation:
The dot operator (.) is used to access members of a union.
112. In which case union is better than structure?
- Less memory is available
- Faster compilation is required
- When functions are included
- None of these
Answer: A) Less memory is available
113. Which is the correct syntax to create a union?
- union union_name {
}; - union union_name {
} - union union_name (
); - Union union_name (
)
Answer: A)
union union_name {
};
Explanation:
The correct syntax of creating a union is:
union union_name {
};
114. What will be the output of the following C program?
#include <stdio.h>
union values {
int val1;
char val2;
} myVal;
int main()
{
myVal.val1 = 66;
printf(“val1 = %p”, &myVal.val1);
printf(“\nval2 = %p”, &myVal.val2);
return 0;
}
- val1 = 0x54ac88dd2012
val2 = 0x55ac76dd2014 - Error
- val1 = 0x55ac76dd2014
val2 = 0x55ac76dd2014 - Exception
Answer: C) val1 = 0x55ac76dd2014
val2 = 0x55ac76dd2014
115. What is a function in C?
- User defined data type
- Block of code which can be reused
- Declaration syntax
- None of these
Answer: B) Block of code which can be reused
Explanation:
Function in C is a block of code which can be reused.
116. Functions in C can accept multiple parameters. True or False?
- True
- False
Answer: A) True
Explanation:
Functions in C programming can accept multiple parameters.
117. Which keyword is used to return values from function?
- Return
- Value
- Return type
- All of these
Answer: C) Return type
Explanation:
The return in declaration is initialized using return type.
118. Which of these is not a valid parameter passing method in C?
- Call by value
- Call by reference
- Call by pointer
- All of these
Answer: C) Call by pointer
Explanation:
Valid parameter passing method in C is:
- Call by value
- Call by reference
119. A C program contains ___.
- At least one function
- No function
- No value from command line
- All of these
Answer: A) At least one function
Explanation:
The main() function is required in the C program.
120. A recursive function in C ___.
- Call itself again and again
- Loop over a parameter
- Return multiple values
- None of these
Answer: A) Call itself again and again
Explanation:
Recursive function in C is a function which calls itself again and again.
121. The scope of a function is limited to?
- Current block
- Only function
- Whole file
- Directory
Answer: C) Whole file
Explanation:
The scope of a function is limited to the file it is declared in.
122. Which of the below syntax is the correct way of declaring a function?
- return function_name () {
} - data_type function_name (parameter) {
} - Void function_name (
) - None of these
Answer: B)
data_type function_name (parameter){
}
Explanation:
The correct syntax of declaring a function in C:
data_type function_name (parameter){
}
123. The sqrt() function is used to calculate which value?
- Square
- Square of reverse bits
- Square root
- None of these
Answer: C) Square root
Explanation:
The sqrt() method in C is used to calculate the square root of a number.
124. What will be the output of the following C program?
#include <stdio.h>
int myFunc(int x){
return (–x);
}
int main(){
int a = myFunc(13);
printf(“%d”, a);
return 0;
}
- 13
- 12
- 14
- Error
Answer: B) 12
125. Before using a pointer variable, it should be ___.
- Declared
- Initialized
- Both A. and B.
- None of the above
Answer: C) Both A. and B.
Explanation:
A pointer variable should be declared and initialized before the using.
126. An uninitialized pointer in C is called ___.
- Void pointer
- Empty pointer
- Invalid pointer
- Wild pointer
Answer: D) Wild pointer
Explanation:
An uninitialized pointer in C is called wild pointer. Since, the pointer is initialized it may lead a program to behave wrongly or to crash.
127. ___ is a pointer that occurs at the time when the object is de-allocated from memory without modifying the value of the pointer.
- Dangling pointer
- Wild pointer
- Void pointer
- Null pointer
Answer: A) Dangling pointer
Explanation:
A dangling pointer is a pointer that occurs at the time when the object is de-allocated from memory without modifying the value of the pointer.
128. A ___ can be assigned the address of any data type.
- Dangling pointer
- Wild pointer
- Void pointer
- Null pointer
Answer: C) Void pointer
Explanation:
A void pointer can be assigned the address of any data type.
129. Which pointer is called general-purpose pointer?
- Dangling pointer
- Wild pointer
- Void pointer
- Null pointer
Answer: C) Void pointer
Explanation:
A void pointer is called general-purpose, because it can be used with any type of variable.
130. Pointer arithmetic is not possible on ___.
- Integer pointers
- Float pointers
- Character pointers
- Void pointers
Answer: D) Void pointers
Explanation:
Pointer arithmetic is not possible on void pointers due to lack of concrete value and size.
131. Comment on the following pointer declaration?
int *p, x;
- p is a pointer to integer, x is not
- p and x, both are pointers to integer
- p is pointer to integer, x may or may not be
- p and x both are not pointers to integer
Answer: A) p is a pointer to integer, x is not
Explanation:
In the above given statement, variable p is a pointer to integer, while x is an integer variable.
132. What will be the output of the following C code?
#include <stdio.h>
int main(){
int x = 10, *ptr;
ptr = &x;
*ptr = 20;
printf(“%d”, x);
}
- 10
- 20
- Error
- A garbage value
Answer: B) 20
Explanation:
In the above program, x contains 10 and ptr is a pointer to x. We are changing the value of x with the help of pointer. Thus, the value will be changed and it will be 20.
133. What will be the output of the following C code?
#include <stdio.h>
int main(){
char* ptr;
ptr = “IncludeHelp”;
printf(“%c”, *&*ptr);
return 0;
}
- IncludeHelp
- I
- Some address
- Error
Answer: B) I
Explanation:
In the above program, in printf statement – we are using two symbols those are * and &. The * is a dereference operator, and the & is a reference operator. These symbols can be used any number of times. Here ptr points to the first character in the string “IncludeHelp”. *ptr dereferences it and so its value is I. Again & references it to an address and * dereferences it to the value I.
134. What is the correct syntax to declare pointer to pointer i.e., double pointer?
- type **pointer_name;
- type *&pointer_name;
- type *(*pointer_name);
- type **(pointer_name);
Answer: A) type **pointer_name;
Explanation:
The correct syntax syntax to declare pointer to pointer i.e., double pointer is:
type **pointer_name;
Example:
int **ptr; //declaration double pointer
135. What is ptr in the given statement?
int (*ptr)[5];
- ptr is an array of 5 pointers
- ptr is a simple integer array
- ptr is a pointer to a 5 elements integer array
- None of the above
Answer: C) ptr is a pointer to a 5 elements integer array
Explanation:
In the above statement, ptr is a pointer to a 5 elements integer array.
136. What is the correct syntax to declare a pointer to a constant?
- const type *pointer_name;
- type const *pointer_name;
- Both A. and B.
- None of the above
Answer: A) const type *pointer_name;
Explanation:
The correct syntax to declare a pointer to a constant is:
const type *pointer_name;
137. Which function is used to open a file in C?
- open()
- fopen()
- file_open()
- fileopen()
Answer: B) fopen()
Explanation:
In C programming language, the fopen() function is used to open a file.
Syntax:
ptr = fopen(“fileopen”,”mode”);
Where, fileopen is the name of the file, and mode is the mode of the file.
138. Which character(s) is/are used to open a binary file in append mode in C?
- a
- b
- ba
- ab
Answer: D) ab
Explanation:
The characters “ab” opens a binary file in append mode.
Syntax:
ptr = fopen(“fileopen”,”ab”);
139. Which character(s) is/are used to open a binary file in reading and writing mode in C?
- rw
- rwb
- rb+
- rwb
Answer: C) rb+
Explanation:
The characters “rb+” opens a binary file in reading and writing mode.
Syntax:
ptr = fopen(“fileopen”,”rb+”);
140. Which is the correct syntax to declare a file pointer in C?
- File *file_pointer;
- FILE *file_pointer;
- File file_pointer;
- FILE *file_pointer;
Answer: B) FILE *file_pointer;
Explanation:
The correct syntax to declare a file pointer in C is:
FILE *file_pointer;
141. Which function is used to close an opened file in C?
- close()
- fclose()
- file_close()
- fileclose()
Answer: B) fclose()
Explanation:
In C programming language, the fclose() function is used to close an opened file.
Syntax:
fclose(file_pointer);
142. Function fwrite() works with ___.
- Text files
- Binary files
- Both A. and B.
- None of the above
Answer: B) Binary files
Explanation:
Function fwrite() works with binary files. The file should be opened/created in binary mode.
143. What is the value of EOF in C?
- -1
- 0
- 1
- Null
Answer: A) -1
Explanation:
The EOF stands for End of File which is a Macro defined in stdio.h header file. With the GNU C Library, EOF is -1. In other libraries, its value may be some other negative number.
144. Which function checks the end-of-file indicator for the given stream in C?
- eof()
- EOF
- feof()
- None of the above
Answer: C) feof()
Explanation:
The C library function feof() checks the end-of-file indicator for the given stream.
Syntax:
int feof(FILE *stream);
145. Which function is used to seek the file pointer position in C?
- seek()
- fseek()
- fileseek()
- fmove()
Answer: B) fseek()
Explanation:
In C programming language, the fseek() function is used to seek the file pointer position.
Syntax:
int fseek(FILE *file_pointer, long int offset, int whence);
Where,
- file_pointer− This is the pointer to a FILE object that identifies the stream.
- offset − This is the number of bytes to offset from whence.
- whence − This is the position from where offset is added, the value of this parameter may SEEK_SET, SEEK_CUR, or SEEK_END.
146. Which function is used to delete an existing file in C?
- delete()
- fremove()
- frem()
- remove()
Answer: D) remove()
Explanation:
In C programming language, the remove() function is used to delete an existing file.
Syntax:
int remove(const char *filename);
Where, filename is the name of the file to be removed.
147. What is CPP in C programming?
- C processing platform
- C PreProcessor
- C pre-platform
- None of these
Answer: B) C PreProcessor
Explanation:
In C programming, C preprocessors are referred to as CPP.
148. Which symbol is used to begin a preprocessor?
- @
- !
- #
- All of these
Answer: C) #
Explanation:
All preprocessor commands begin with a hash symbol (#).
149. Which of these is a valid preprocessor in C?
- #include
- #if
- #error
- All of these
Answer: D) All of these
150. (\) operator in C is ___.
- Macro continuation operator
- Stringize operator
- Tokenizer
- None of these
Answer: A) Macro continuation operator
Explanation:
Macro continuation (/) operator is used to continue a macro which is too long for a single line.
151. Which operator is used to stringize variables in C?
- /
- &
- *
- #
Answer: D) #
Explanation:
# Operator is used to stringize variables in C.
152. What will be the output of the following C code?
#include <stdio.h>
#define message_for(a, b) \
printf(“Learn ” #a ” programming language at ” #b)
int main(void){
message_for(python, includehelp);
return 0;
}
- Learn python programming language at includehelp
- Learn #a programming language at #b
- Learn programming language at
- None of these
Answer: A) Learn python programming language at includehelp
153. Is it possible in a C program to merge two tokens into one token?
- Yes
- No
Answer: A) Yes
Explanation:
The ### preprocessor in C is used to merge two tokens to one.
154. Which of these is not a valid preprocessor in C?
- \
- ?
- ###
- None of these
Answer: B) ?
Explanation:
\ and ### are both valid preprocessors in C.
155. Header files ___.
- Contain function declarations
- Can be included to a program
- End with .h extension
- All of these
Answer: D) All of these
Explanation:
All statements are correct. The header files are special files included in a program that contain functions and macros which can be imported and used in the code. The extension of header files is “.h”.
156. Can programmers create their own header files?
- Yes
- No
Answer: A) Yes
Explanation:
A header file can be created by a programmer with some function that she needs to use in other files as well.
157. Which of these is valid syntax to include a header in C?
- #include <header>
- #include “header”
- Both A and B
- All of these
Answer: C) Both A and B
Explanation:
The valid syntaxes to include a header file to a program in C are:
- #include <header>
- #include “header”
158. What will happen if a header file is included in a program twice?
- Program will throw an error
- Program will throw an exception
- Program will run normally
- None of these
Answer: A) Program will throw an error
Explanation:
When the same header is included twice in the program, the compiler will throw an error as its teens to process it twice.
159. Which syntax is correct to include a specific preprocessor based on configuration?
- #defif system1 <system.h>
- #include system1 “system.h”
- import <system.h> if system1
- All of these
Answer: B) #include system1 “system.h”
Explanation:
The correct way to include a specific preprocessor based on configuration is known as computed include is:
#include system1 “system.h”