MCQ C 100 Question With Answer Explanation-1
MCQ C 100 Question With Answer Explanation-1
Question 1:
a) int
b) float
c) double
d) program
Explanation:
int, float, and double are all fundamental data types in C used to
represent integers, floating-point numbers, and double-precision
floating-point numbers, respectively.
Question 2:
C
#include <stdio.h>
int main() {
int x = 5;
int y = 2;
printf("%d", x % y);
return 0;
}
a) 2
b) 2.5
c) 1
d) 0
Explanation:
Question 3:
a) +
b) -
c) *
d) ()
Explanation:
Question 4:
Explanation:
The main() function is the starting point of execution for any C
program.
When a C program is run, the operating system first looks for the
main() function and begins executing the code within it.
Question 5:
a) const
b) static
c) volatile
d) register
Explanation:
Question 6:
C
#include <stdio.h>
int main() {
char str[] = "Hello";
printf("%s", str);
return 0;
}
a) H
b) Hello
c) ello
d) 0
Explanation:
Question 7:
a) int
b) float
c) string
d) char
Explanation:
Question 8:
Explanation:
Question 9:
a) for loop
b) while loop
c) if statement
d) function keyword
Explanation:
C
return_type function_name(parameter_list) {
// Function body
}
Question 10:
a) To define a function.
b) To declare a variable.
d) To create a loop.
Explanation:
Question 11:
a) int *ptr;
b) *int ptr;
c) int ptr*;
d) *ptr int;
Explanation:
The asterisk (*) indicates that ptr holds the memory address of an
integer variable.
Question 12:
C
#include <stdio.h>
int main() {
int a = 10;
int *ptr = &a;
printf("%d", *ptr);
return 0;
}
a) Address of a
b) 10
c) Garbage value
d) Error
Explanation:
*ptr dereferences the pointer, accessing the value stored at the memory
address pointed to by ptr.
Question 13:
Explanation:
Question 14:
C
#include <stdio.h>
int main() {
if (10 > 5) {
printf("True");
} else {
printf("False");
}
return 0;
}
a) False
b) True
c) 10
d) 5
Explanation:
Therefore, the code inside the if block will be executed, and the output will
be b) True.
Question 15:
a) while loop
b) do-while loop
c) for loop
d) switch statement
Explanation:
c) for loop
The for loop is specifically designed for iterating a known number of
times.
Question 16:
Explanation:
Question 17:
a) auto
b) register
c) static
d) volatile
Explanation:
auto, register, static, and extern are all valid storage class specifiers
in C.
Question 18:
a) To create a loop.
b) To define a function.
Explanation:
Question 19:
C
#include <stdio.h>
int main() {
int x = 5;
x++;
printf("%d", x);
return 0;
}
a) 4
b) 5
c) 6
d) 0
Explanation:
It first uses the current value of x (which is 5) in the expression, and then
increments x by 1.
Question 20:
a) scanf("%d", &ch);
b) scanf("%c", &ch);
c) getchar();
d) putchar(ch);
Explanation:
c) getchar();
This function reads a single character from the standard input (usually
the keyboard) and returns it as an integer.
Question 21:
C
#include <stdio.h>
int main() {
int a = 5, b = 2;
printf("%d", a / b);
return 0;
}
a) 2.5
b) 2
c) 3
d) 0
Explanation:
When you divide two integers in C, the result is also an integer (integer
division).
Question 22:
a) /* ... */
b) // ...
c) # ...
d) '...'
Explanation:
b) // ...
Question 23:
a) To create a loop.
b) To define a function.
Explanation:
Question 24:
C
#include <stdio.h>
int main() {
int a = 10;
if (a == 10) {
printf("a is 10");
}
return 0;
}
a) a is 10
b) 10
c) True
d) No output
Explanation:
Therefore, the code inside the if block will be executed, and the output will
be a) a is 10.
Question 25:
a) malloc()
b) calloc()
c) free()
Explanation:
Question 26:
C
#include <stdio.h>
int main() {
char str[] = "Hello";
printf("%c", str[0]);
return 0;
}
a) Hello
b) H
c) 0
d) Error
Explanation:
str[0] accesses the first character in the string "Hello", which is 'H'.
Question 27:
a) 'a'
b) "a"
c) a
d) &a
Explanation:
a) 'a'
Question 28:
d) To declare a variable.
Explanation:
Question 29:
a) #define
b) #include
c) #ifdef
d) #endif
Explanation:
a) #define
Question 30:
C
#include <stdio.h>
int main() {
int a = 10, b = 5;
if (a > b) {
printf("a is greater than b");
}
return 0;
}
a) a is greater than b
b) b is greater than a
c) a is equal to b
d) No output
Explanation:
Therefore, the code inside the if block will be executed, and the output will
be a) a is greater than b.
Question 31:
C
#include <stdio.h>
int main() {
int arr[] = {1, 2, 3, 4, 5};
int *ptr = arr;
printf("%d", *(ptr + 2));
return 0;
}
a) 1
b) 2
c) 3
d) 4
Explanation:
ptr points to the first element of the array (arr[0]).
Question 32:
Explanation:
Question 33:
Explanation:
The volatile keyword tells the compiler that the value of a variable
can change at any time, even without any explicit assignment within the
code.
This prevents the compiler from optimizing away code that reads or
writes to the variable, which might be necessary if the variable is
accessed by hardware or another thread.
Question 34:
C
#include <stdio.h>
int main() {
int x = 5;
int y = --x;
printf("%d %d", x, y);
return 0;
}
a) 5 4
b) 4 4
c) 5 5
d) 4 5
Explanation:
Question 35:
c) To define a macro.
Explanation:
Question 36:
a) A structure allocates memory for all its members, while a union allocates
memory only for the largest member.
b) A structure can have members of different data types, while a union can
only have members of the same data type.
Explanation:
a) A structure allocates memory for all its members, while a union
allocates memory only for the largest member.
In a union, all members share the same memory location, and only the
largest member's size is allocated.
Question 37:
Explanation:
Question 38:
C
#include <stdio.h>
int main() {
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = &arr[2];
printf("%d", *(ptr - 1));
return 0;
}
a) 1
b) 2
c) 3
d) 4
Explanation:
*(ptr - 1) accesses the element one position before the address pointed
to by ptr, which is arr[1].
Question 39:
What is the purpose of the static keyword when used with a local
variable within a function?
Explanation:
In contrast, ordinary local variables lose their values when the function
return type
Question 40:
What is the difference between a pre-increment ( --x ) and a
post-increment ( x-- ) operator in C?
Explanation:
Pre-increment ( --x )
Decrements the value of the variable x before using its value in the
expression.
Question 41:
#include <stdio.h>
int main() {
int *p = &a[0];
p += 2;
printf("%d", *p);
return 0;
a) 1
b) 2
c) 3
d) 4
Explanation:
p += 2 moves the pointer two positions forward in the array. Now, p points to
a[2].
*p dereferences the pointer and prints the value at the address pointed to by
p, which is a[2].
Question 42:
Explanation:
This allows you to use the variable in the current file without redefining
it.
Question 43:
#include <stdio.h>
int main() {
int x = 10;
*ptr = 20;
printf("%d", x);
return 0;
a) 10
b) 20
c) Address of x
d) Garbage value
Explanation:
Therefore, the value of x is changed to 20, and the output will be b) 20.
Question 44:
What is the purpose of the const qualifier when used with a function
parameter?
This helps in writing safer code and can also improve code readability.
Question 45:
#include <stdio.h>
int main() {
int i, j;
printf("\n");
return 0;
a)
00
11
22
b)
01
01
01
c)
00
11
22
d)
01
12
23
Explanation:
The inner loop iterates two times (j = 0, 1) for each iteration of the outer loop.
00
11
22
Question 46:
Explanation:
Question 47:
a) To define a macro.
d) To declare a variable.
Explanation:
If the macro is not defined, the code between #ifdef and #else (if
present) is compiled.
Question 48:
#include <stdio.h>
int main() {
int a = 5, b = 2;
float c = (float)a / b;
printf("%.2f", c);
return 0;
a) 2
b) 2.00
c) 2.50
d) 3
Explanation:
Question 49:
c) To point to a function.
Explanation:
A void pointer is a generic pointer that can point to any data type.
Question 50:
a) The while loop executes at least once, while the do-while loop may not
execute at all.
b) The do-while loop executes at least once, while the while loop may not
execute at all.
c) The while loop is used for iterating a specific number of times, while the
do-while loop is used for
Answer:
a) The while loop executes at least once, while the do-while loop may
not execute at all.
Explanation:
while loop:
If the condition is true, the loop body is executed, and then the
condition is checked again.
do-while loop:
The body of the loop is executed at least once before the condition is
checked.
If the condition is true, the loop body is executed again, and the
process repeats
Question 51:
#include <stdio.h>
int main() {
int x = 5;
return 0;
a) 7 11
b) 6 11
c) 7 12
d) 6 10
Explanation:
x++ uses the current value of x (5) in the calculation and then increments x to
6.
Output: c) 7 12
Question 52:
Explanation:
If break is not used, execution will continue to the next case in the
switch statement, even if it doesn't match the evaluated expression.
Question 53:
Explanation:
For example:
C
typedef struct {
int x;
int y;
} Point;
This creates an alias Point for the structure, so you can declare
variables like Point p1; instead of struct { int x; int y; }
p1;.
Question 54:
#include <stdio.h>
int main() {
strcat(str1, str2);
printf("%s", str1);
return 0;
a) Hello
b) World
c) HelloWorld
Explanation:
Appending World to Hello will likely cause a buffer overflow, as str1 might
not have enough space to hold the concatenated string.
Question 55:
Explanation:
Question 56:
Explanation:
Question 57:
#include <stdio.h>
int main() {
int sum = 0;
sum += arr[i];
printf("%d", sum);
return 0;
a) 5
b) 10
c) 15
d) 25
Explanation:
The code iterates through the array arr and adds each element to the
sum variable.
Output: c) 15
Question 58:
Explanation:
Question 59:
Explanation:
Question 60:
#include <stdio.h>
int main() {
int x = 10;
printf("%d", **ptr_ptr);
return 0;
a) 10
b) Address of x
c) Address of ptr
d) Garbage value
Explanation:
Then, it dereferences ptr to get the value stored at the address pointed
to by ptr, which is the value of x (10).
Question 61:
a) int age;
b) age int;
c) integer age;
Explanation:
a) int age;
Question 62:
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
a) Hello, World!
b) Hello, World
c) World!
d) No output
Explanation:
a) Hello, World!
Question 63:
a) ^
b) *
c) /
d) +
Explanation:
d) +
Question 64:
d) To declare a variable.
Explanation:
Question 65:
a) char letter;
b) string letter;
c) character letter;
d) letter char;
Explanation:
a) char letter;
Question 66:
#include <stdio.h>
int main() {
int a = 10;
int b = 5;
int c = a - b;
printf("%d", c);
return 0;
a) 5
b) 15
c) 2
d) 0
Explanation:
a) 5
Question 67:
a) const
b) static
c) volatile
d) register
Explanation:
a) const
Question 68:
a) To define a function.
b) To declare a variable.
d) To create a loop.
Explanation:
Question 69:
a) 'a'
b) "a"
c) a
d) &a
Explanation:
b) "a"
Question 70:
a) for loop
b) while loop
c) if-else statement
d) switch statement
Explanation:
b) while loop
Question 71:
Which of the following is used to read a line of text from the user in C?
a) scanf("%d", &num);
b) scanf("%c", &ch);
c) gets(str);
d) putchar(ch);
Explanation:
c) gets(str);
Question 72:
#include <stdio.h>
int main() {
int a = 5, b = 2;
int c = a * b;
printf("%d", c);
return 0;
}
a) 7
b) 3
c) 10
d) 2
Explanation:
c) 10
Question 73:
a) float num;
b) integer num;
c) character num;
d) string num;
Explanation:
a) float num;
Question 74:
Explanation:
Question 75:
a) int array[10];
b) int array(10);
c) int 10 array;
d) array int[10];
Explanation:
a) int array[10];
Question 76:
#include <stdio.h>
int main() {
int a = 10;
if (a > 0) {
printf("Positive");
}
return 0;
a) Positive
b) Negative
c) Zero
d) No output
Explanation:
a) Positive
Question 77:
a) /* ... */
b) // ...
c) # ...
d) '...'
Explanation:
b) // ...
Question 78:
What is the purpose of the sizeof operator in C?
Explanation:
Question 79:
a) int *ptr;
b) char *ptr;
c) float *ptr;
d) void *ptr;
Explanation:
This declares a pointer named ptr that can hold the address of
acharacter variable.
Question 80:
#include <stdio.h>
int main() {
int a = 5;
int b = 2;
int c = a % b;
printf("%d", c);
return 0;
a) 2
b) 2.5
c) 1
d) 0
Explanation:
c) 1
Question 81:
a) for loop
b) while loop
c) if statement
d) function keyword
Explanation:
d) function keyword
While not a keyword itself, the return type of the function acts as
the "function keyword."
For example:
C
int myFunction(int a, int b) {
// Function body
Question 82:
#include <stdio.h>
int main() {
int x = 5;
x *= 2;
printf("%d", x);
return 0;
}
a) 7
b) 3
c) 10
d) 2
Explanation:
c) 10
Question 83:
a) 'a'
b) "a"
c) a
d) &a
Explanation:
a) 'a'
Question 84:
Explanation:
Question 85:
a) bool flag;
b) boolean flag;
c) int flag;
d) char flag;
Explanation:
c) int flag;
Question 86:
#include <stdio.h>
int main() {
int x = 10, y = 5;
if (x == y) {
printf("Equal");
} else {
printf("Not Equal");
return 0;
a) Equal
b) Not Equal
c) True
d) False
Explnation:
b) Not Equal
Therefore, the code within the else block is executed, and "Not
Equal" is printed.
Question 87:
a) // ...
b) /* ... */
c) # ...
d) '...'
Explanation:
b) / ... /
Question 88:
a) To create a loop.
b) To define a function.
Explanation:
Question 89:
a) malloc()
b) calloc()
c) free()
Explanation:
Question 90:
a) int (*fptr)();
b) int *fptr();
c) int fptr*;
d) *int fptr();
Explanation:
This declares a pointer named fptr that can hold the address of
a function that returns an integer and takes no arguments.
Question 91:
#include <stdio.h>
int main() {
int x = 10;
x /= 2;
printf("%d", x);
return 0;
}
a) 5
b) 12
c) 2
d) 0
Explanation:
a) 5
Question 92:
a) \n
b) \t
c) \r
d) \
Explanation:
a) \n
Question 93:
What is the purpose of the static keyword when used with a global
variable?
a) To make the variable accessible only within the current file.
Explanation:
Question 94:
a) int array[2];
b) int array[2][3];
Explanation:
b) int array[2][3];
Question 95:
#include <stdio.h>
int main() {
int a = 5;
if (a > 0) {
printf("Positive");
} else if (a < 0) {
printf("Negative");
} else {
printf("Zero");
return 0;
a) Positive
b) Negative
c) Zero
d) No output
Explanation:
a) Positive
Question 96:
a) for loop
b) while loop
c) do-while loop
d) switch statement
Explanation:
c) do while loop
The do-while loop executes the body of the loop at least once
before checking the condition.
Question 97:
Explanation:
Question 98:
c) To dereference a pointer.
d) To perform logical AND operation.
Explanation:
Question 99:
a) struct { ... }
b) class { ... }
c) union { ... }
d) enum { ... }
Explanation:
a) struct { ... }
Question 100:
#include <stdio.h>
int main() {
printf("%ld", sizeof(str));
return 0;
}
a) 1
b) 5
c) 6
d) 7
Explanation:
c) 6
The string "Hello" consists of 5 characters ('H', 'e', 'l', 'l', 'o') and a
null character ('\0') at the end.