0% found this document useful (0 votes)
25 views61 pages

MCQ C 100 Question With Answer Explanation-1

The document contains a set of 100 multiple-choice questions (MCQs) related to the C programming language, each followed by an explanation of the correct answer. Topics covered include data types, operators, control structures, memory management, and syntax rules in C. Each question is designed to test knowledge and understanding of fundamental concepts in C programming.

Uploaded by

vijayaraja013
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views61 pages

MCQ C 100 Question With Answer Explanation-1

The document contains a set of 100 multiple-choice questions (MCQs) related to the C programming language, each followed by an explanation of the correct answer. Topics covered include data types, operators, control structures, memory management, and syntax rules in C. Each question is designed to test knowledge and understanding of fundamental concepts in C programming.

Uploaded by

vijayaraja013
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

MCQ C 100 QUESTION WITH ANSWER EXPLANATION

Question 1:

Which of the following is NOT a valid keyword in C?

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.

program is not a reserved word in C. Keywords have specific


meanings and cannot be used as identifiers (variable names, function
names, etc.).

Question 2:

What is the output of the following code?

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:

The % operator is the modulus operator. It gives the remainder of the


division.

5 divided by 2 gives a quotient of 2 and a remainder of 1.

Therefore, the output will be 1.

Question 3:

Which operator has the highest precedence in C?

a) +

b) -

c) *

d) ()

Explanation:

Parentheses () have the highest precedence in C. This means that


expressions within parentheses are evaluated first, regardless of other
operators.

Question 4:

What is the purpose of the main() function in a C program?

a) It is the entry point of the program.

b) It is used to define variables.

c) It is used to perform input/output operations.

d) It is used to create user-defined functions.

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:

Which of the following is used to declare a constant variable in C?

a) const

b) static

c) volatile

d) register

Explanation:

The const keyword is used to declare a constant variable.

Once a variable is declared as const, its value cannot be changed


during the program's execution.

Question 6:

What is the output of the following code?

C
#include <stdio.h>

int main() {
char str[] = "Hello";
printf("%s", str);
return 0;
}

a) H

b) Hello

c) ello
d) 0

Explanation:

The %s format specifier in printf() is used to print a string.

The str array holds the string "Hello".

Therefore, the output will be "Hello".

Question 7:

Which of the following is NOT a valid data type in C?

a) int

b) float

c) string

d) char

Explanation:

int, float, and char are all fundamental data types in C.

string is not a fundamental data type in C. Strings are typically


represented as arrays of characters (like char str[]).

Question 8:

What is the purpose of the break statement in a loop?

a) To exit the loop immediately.

b) To skip the current iteration and continue to the next one.

c) To repeat the current iteration.

d) To pause the execution of the loop.

Explanation:

The break statement is used to immediately terminate the execution of


a loop, regardless of the loop's condition.
Control is then transferred to the statement following the loop.

Question 9:

Which of the following is used to create a user-defined function in C?

a) for loop

b) while loop

c) if statement

d) function keyword

Explanation:

In C, you define functions using the function keyword (which is actually


the function's return type, like int, void, etc.).

The general syntax is:

C
return_type function_name(parameter_list) {
// Function body
}

Question 10:

What is the purpose of the #include directive in C?

a) To define a function.

b) To declare a variable.

c) To include a header file.

d) To create a loop.

Explanation:

The #include directive is used to include the contents of a header file


into your C source code.
Header files often contain function prototypes, macro definitions, and
other important declarations that your code may need. For example,
#include <stdio.h> includes the standard input/output library,
which provides functions like printf() and scanf().

Question 11:

Which of the following is the correct syntax for declaring a pointer to an


integer in C?

a) int *ptr;

b) *int ptr;

c) int ptr*;

d) *ptr int;

Explanation:

*a) int ptr;

This is the correct syntax.

int *ptr; declares a variable named ptr that is a pointer to an


integer.

The asterisk (*) indicates that ptr holds the memory address of an
integer variable.

Question 12:

What is the output of the following code?

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:

&a gives the memory address of the variable a.

ptr = &a; assigns the memory address of a to the pointer ptr.

*ptr dereferences the pointer, accessing the value stored at the memory
address pointed to by ptr.

Therefore, the output will be b) 10.

Question 13:

What is the purpose of the sizeof operator in C?

a) To find the address of a variable.

b) To determine the size of a data type or variable in bytes.

c) To allocate memory dynamically.

d) To check if a variable is initialized.

Explanation:

b) To determine the size of a data type or variable in bytes.

The sizeof operator returns the size of a data type or a variable in


bytes.

For example, sizeof(int) will return the number of bytes used to


store an integer on the specific system.

Question 14:

What is the output of the following code?

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:

The condition 10 > 5 is true.

Therefore, the code inside the if block will be executed, and the output will
be b) True.

Question 15:

Which loop is most suitable for iterating a specific number of times?

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.

It has three parts: initialization, condition, and increment/decrement,


making it well-suited for controlling the number of iterations.

Question 16:

What is the purpose of the continue statement within a loop?

a) To exit the loop immediately.

b) To skip the current iteration and proceed to the next one.

c) To repeat the current iteration.

d) To pause the execution of the loop.

Explanation:

b) To skip the current iteration and proceed to the next one.

The continue statement skips the remaining part of the current


iteration of the loop and immediately jumps to the next iteration.

Question 17:

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

a) auto

b) register

c) static

d) volatile

Explanation:

auto, register, static, and extern are all valid storage class specifiers
in C.

auto is the default storage class for local variables.


register suggests to the compiler that the variable should be stored
in a register for faster access.

static makes a variable retain its value between function calls.

extern declares a variable that is defined elsewhere in the program.

Question 18:

What is the purpose of the #ifndef, #define, and #endif directives in


C?

a) To create a loop.

b) To define a function.

c) To include a header file.

d) To prevent multiple inclusions of a header file.

Explanation:

d) To prevent multiple inclusions of a header file.

These preprocessor directives are used together to create a conditional


inclusion block.

This ensures that a header file is included only once in a program,


preventing compilation errors and inconsistencies.

Question 19:

What is the output of the following code?

C
#include <stdio.h>

int main() {
int x = 5;
x++;
printf("%d", x);
return 0;
}
a) 4

b) 5

c) 6

d) 0

Explanation:

x++ is the post-increment operator.

It first uses the current value of x (which is 5) in the expression, and then
increments x by 1.

Therefore, the output will be c) 6.

Question 20:

Which of the following is used to read a single character from the


standard input in C?

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.

scanf("%c", &ch); can also be used, but getchar() is often more


concise for reading a single character

Question 21:

What is the output of the following code?

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:

In this code, a and b are integers.

When you divide two integers in C, the result is also an integer (integer
division).

5 divided by 2 results in 2 (the decimal part is truncated).

Therefore, the output will be b) 2.

Question 22:

Which of the following is used to represent a single-line comment in C?

a) /* ... */

b) // ...

c) # ...

d) '...'

Explanation:

b) // ...

// is used to start a single-line comment in C.


Any text following // on the same line is ignored by the compiler.

/* ... */ is used for multi-line comments.

Question 23:

What is the purpose of the struct keyword in C?

a) To create a loop.

b) To define a function.

c) To create a user-defined data type.

d) To include a header file.

Explanation:

c) To create a user-defined data type.

The struct keyword is used to define a structure, which is a


user-defined data type that can group variables of different data types
under a single name.

Question 24:

What is the output of the following code?

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:

The condition a == 10 is true because the value of a is indeed 10.

Therefore, the code inside the if block will be executed, and the output will
be a) a is 10.

Question 25:

Which of the following is used to dynamically allocate memory in C?

a) malloc()

b) calloc()

c) free()

d) All of the above

Explanation:

d) All of the above

malloc() allocates a block of memory of a specified size.

calloc() allocates a block of memory of a specified size and


initializes all bytes to zero.

free() releases a block of memory that was previously allocated using


malloc() or calloc().

Question 26:

What is the output of the following code?

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'.

%c in the printf() statement is used to print a single character.

Therefore, the output will be b) H.

Question 27:

Which of the following is used to represent a character constant in C?

a) 'a'

b) "a"

c) a

d) &a

Explanation:

a) 'a'

Single quotes ('...') are used to represent character constants in C.

"a" represents a string literal.

Question 28:

What is the purpose of the return statement within a function?

a) To exit the function immediately.


b) To skip the current iteration of a loop.

c) To return a value from the function.

d) To declare a variable.

Explanation:

c) To return a value from the function.

The return statement is used to return a value from a function to the


calling function.

Question 29:

Which of the following is used to define a macro in C?

a) #define

b) #include

c) #ifdef

d) #endif

Explanation:

a) #define

The #define directive is used to define a macro, which is a symbolic


constant or a code snippet that can be replaced by its value during
preprocessing.

Question 30:

What is the output of the following code?

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:

The condition a > b is true because 10 is greater than 5.

Therefore, the code inside the if block will be executed, and the output will
be a) a is greater than b.

Question 31:

What is the output of the following code?

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]).

*(ptr + 2) accesses the element two positions ahead of the address


pointed to by ptr, which is arr[2].

Since arr[2] is 3, the output will be c) 3.

Question 32:

What is the difference between malloc() and calloc() in C?

a) malloc() initializes the allocated memory to zero, while calloc() does


not.

b) calloc() initializes the allocated memory to zero, while malloc() does


not.

c) malloc() allocates memory for a single variable, while calloc()


allocates memory for an array.

d) malloc() allocates memory on the stack, while calloc() allocates


memory on the heap.

Explanation:

b) calloc() initializes the allocated memory to zero, while malloc()


does not.

malloc() only allocates a block of memory of the specified size


without initializing its contents.

calloc() allocates a block of memory of the specified size and


initializes all bytes in that block to zero.

Question 33:

What is the purpose of the volatile keyword in C?

a) To prevent a variable from being optimized by the compiler.

b) To declare a constant variable.

c) To allocate memory for a variable on the stack.


d) To declare a variable that can be modified by external factors.

Explanation:

d) To declare a variable that can be modified by external factors.

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:

What is the output of the following code?

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:

--x is the pre-decrement operator.

It decrements the value of x by 1 before using it in the expression.

So, x becomes 4, and then its value (4) is assigned to y.


Therefore, the output will be b) 4 4.

Question 35:

What is the purpose of the typedef keyword in C?

a) To create a new data type.

b) To declare a pointer to a function.

c) To define a macro.

d) To allocate memory dynamically.

Explanation:

a) To create a new data type.

The typedef keyword is used to create a new name (alias) for an


existing data type.

For example, typedef unsigned int UINT; creates a new data


type named UINT that is equivalent to unsigned int.

Question 36:

What is the difference between a structure and a union in C?

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.

c) A structure is used to create arrays, while a union is used to create


pointers.

d) A structure is a collection of variables of different data types, while a union


is a collection of variables 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 structure, each member has its own memory space.

In a union, all members share the same memory location, and only the
largest member's size is allocated.

Question 37:

What is the purpose of the enum keyword in C?

a) To define a set of named integer constants.

b) To create a user-defined function.

c) To allocate memory dynamically.

d) To declare a pointer to a structure.

Explanation:

a) To define a set of named integer constants.

The enum keyword is used to define an enumerated type, which is a set


of named integer constants.

For example, enum Days { Monday, Tuesday, Wednesday,


Thursday, Friday, Saturday, Sunday }; defines an
enumerated type named Days with constants Monday (which is
typically assigned the value 0), Tuesday (1), and so on.

Question 38:

What is the output of the following code?

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 points to the third element of the array (arr[2]).

*(ptr - 1) accesses the element one position before the address pointed
to by ptr, which is arr[1].

Since arr[1] is 2, the output will be b) 2.

Question 39:

What is the purpose of the static keyword when used with a local
variable within a function?

a) To make the variable accessible from other functions.

b) To make the variable accessible only within the function.

c) To make the variable retain its value between function calls.

d) To make the variable read-only.

Explanation:

c) To make the variable retain its value between function calls.

When a local variable is declared as static, its value is preserved


between function calls.

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.

Certainly, let's continue with 10 more challenging C language MCQ questions:

Question 41:

What is the output of the following code snippet?

#include <stdio.h>

int main() {

int a[5] = {1, 2, 3, 4, 5};

int *p = &a[0];

p += 2;

printf("%d", *p);

return 0;

a) 1

b) 2

c) 3
d) 4

Explanation:

p initially points to the first element of the array (a[0]).

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].

Since a[2] is 3, the output will be c) 3.

Question 42:

What is the purpose of the extern keyword in C?

a) To declare a variable that is defined elsewhere in the program.

b) To declare a variable that is constant.

c) To declare a variable that is local to a function.

d) To declare a variable that is stored in a register.

Explanation:

a) To declare a variable that is defined elsewhere in the program.

The extern keyword is used to declare a variable that has been


defined in another file.

This allows you to use the variable in the current file without redefining
it.

Question 43:

What is the output of the following code snippet?

#include <stdio.h>
int main() {

int x = 10;

int *ptr = &x;

*ptr = 20;

printf("%d", x);

return 0;

a) 10

b) 20

c) Address of x

d) Garbage value

Explanation:

ptr points to the memory location of x.

*ptr = 20 assigns the value 20 to the memory location pointed to by ptr,


which is the location of x.

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?

a) To prevent the function from modifying the value of the parameter.

b) To make the function return a constant value.

c) To make the function itself constant.

d) To make the function call faster.


Explanation:

a) To prevent the function from modifying the value of the parameter.

When a function parameter is declared with the const qualifier, it


indicates that the function should not modify the value of that parameter
within its body.

This helps in writing safer code and can also improve code readability.

Question 45:

What is the output of the following code snippet?

#include <stdio.h>

int main() {

int i, j;

for (i = 0; i < 3; i++) {

for (j = 0; j < 2; j++) {

printf("%d ", i);

printf("\n");

return 0;

a)

00
11

22

b)

01

01

01

c)

00

11

22

d)

01

12

23

Explanation:

The outer loop iterates three times (i = 0, 1, 2).

The inner loop iterates two times (j = 0, 1) for each iteration of the outer loop.

Inside the inner loop, the value of i is printed.

Therefore, the output will be:

00
11

22

Question 46:

What is the role of a compiler in C programming?

a) To execute the C program.

b) To translate the C code into machine code.

c) To debug the C program.

d) To write the C code.

Explanation:

b) To translate the C code into machine code.

The compiler is a software program that translates the source code


written in C (which is high-level language) into machine code (low-level
language) that the computer can understand and execute.

Question 47:

What is the purpose of the #ifdef, #endif, and #else preprocessor


directives?

a) To define a macro.

b) To include a header file.

c) To create conditional compilation blocks.

d) To declare a variable.

Explanation:

c) To create conditional compilation blocks.

These preprocessor directives are used to create conditional


compilation blocks in C.
#ifdef checks if a particular macro is defined.

If it is defined, the code between #ifdef and #endif is compiled.

If the macro is not defined, the code between #ifdef and #else (if
present) is compiled.

Question 48:

What is the output of the following code snippet?

#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:

(float)a casts the integer value of a to a floating-point number before the


division.

This ensures that the division is performed as a floating-point operation,


resulting in a more accurate result.
The output will be c) 2.50.

Question 49:

What is the purpose of the void pointer in C?

a) To point to a specific data type.

b) To point to any data type.

c) To point to a function.

d) To point to a constant value.

Explanation:

b) To point to any data type.

A void pointer is a generic pointer that can point to any data type.

However, it cannot be dereferenced directly.

To access the value pointed to by a void pointer, you need to cast it to


the appropriate data type.

Question 50:

What is the difference between a while loop and a do-while loop in C?

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:

The condition is checked before the body of the loop is executed.

If the condition is true, the loop body is executed, and then the
condition is checked again.

If the condition is initially false, the loop body is never executed.

do-while loop:

The body of the loop is executed at least once before the condition is
checked.

After the first execution, the condition is checked.

If the condition is true, the loop body is executed again, and the
process repeats

Question 51:

What is the output of the following code snippet?

#include <stdio.h>

int main() {

int x = 5;

int y = x++ + ++x;

printf("%d %d", x, y);

return 0;

a) 7 11
b) 6 11

c) 7 12

d) 6 10

Explanation:

This code involves both pre-increment and post-increment operators, which


can be tricky.

x++ uses the current value of x (5) in the calculation and then increments x to
6.

++x increments the value of x to 7 before using it in the calculation.

Therefore, y = 5 (from x++) + 7 (from ++x) = 12.

The final values of x and y are 7 and 12, respectively.

Output: c) 7 12

Question 52:

What is the purpose of the break statement within a switch statement?

a) To exit the switch statement immediately.

b) To skip the next case in the switch statement.

c) To execute the next case in the switch statement.

d) To continue execution after the switch statement.

Explanation:

a) To exit the switch statement immediately.

The break statement within a switch statement is used to


immediately exit the switch block.

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:

What is the purpose of the typedef keyword when used with a


structure?

a) To create an alias for the structure name.

b) To make the structure members public.

c) To make the structure members private.

d) To allocate memory for the structure.

Explanation:

a) To create an alias for the structure name.

typedef can be used to create an alias for a structure name, making it


easier to use in the code.

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:

What is the output of the following code snippet?

#include <stdio.h>
int main() {

char str1[] = "Hello";

char str2[] = "World";

strcat(str1, str2);

printf("%s", str1);

return 0;

a) Hello

b) World

c) HelloWorld

d) Undefined behavior (potential buffer overflow)

Explanation:

strcat(str1, str2) concatenates (appends) the string str2 to the end of


str1.

However, str1 has limited space.

Appending World to Hello will likely cause a buffer overflow, as str1 might
not have enough space to hold the concatenated string.

d) Undefined behavior (potential buffer overflow) is the most accurate


answer in this case.

Question 55:

What is the purpose of function pointers in C?

a) To call a function without knowing its name.

b) To pass a function as an argument to another function.


c) To return a function from another function.

d) All of the above

Explanation:

● d) All of the above


○ Function pointers allow you to:
■ Call a function without knowing its name at compile time.

Pass a function as an argument to another function (e.g.,


callback functions).

Return a function from another function.

Question 56:

What is the purpose of the #include <stdlib.h> header file in C?

a) Provides input/output functions like printf and scanf.

b) Provides memory allocation functions like malloc and free.

c) Provides mathematical functions like sin and cos.

d) Provides string manipulation functions like strcpy and strcat.

Explanation:

b) Provides memory allocation functions like malloc and free.

The stdlib.h header file provides standard library functions,


including memory allocation functions like malloc, calloc,
realloc, and free.

Question 57:

What is the output of the following code snippet?

#include <stdio.h>
int main() {

int arr[] = {1, 2, 3, 4, 5};

int sum = 0;

for (int i = 0; i < 5; i++) {

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.

The sum of the elements in the array is 1 + 2 + 3 + 4 + 5 = 15.

Output: c) 15

Question 58:

What is the purpose of the recursive function calls in C?

a) To avoid using loops.

b) To solve problems that can be broken down into smaller, similar


subproblems.
c) To increase the speed of execution.

d) To reduce memory usage.

Explanation:

b) To solve problems that can be broken down into smaller, similar


subproblems.

Recursive functions call themselves within their own definition.

They are particularly useful for solving problems that can be


broken down into smaller, similar subproblems, such as
calculating factorials, traversing tree data structures, and
searching algorithms like depth-first search.

Question 59:

What is the purpose of the union data type in C?

a) To group variables of different data types under a single name, where


only one member can be active at a time.

b) To group variables of the same data type under a single name.

c) To create an array of structures.

d) To define a set of named integer constants.

Explanation:

a) To group variables of different data types under a single name,


where only one member can be active at a time.

In a union, all members share the same memory location.

Therefore, only one member of the union can be active at a


time, and its size is determined by the size of its largest member.

Question 60:

What is the output of the following code snippet?

#include <stdio.h>
int main() {

int x = 10;

int *ptr = &x;

int **ptr_ptr = &ptr;

printf("%d", **ptr_ptr);

return 0;

a) 10

b) Address of x

c) Address of ptr

d) Garbage value

Explanation:

ptr is a pointer to the integer x.

ptr_ptr is a pointer to the pointer ptr.

**ptr_ptr first dereferences ptr_ptr to get the value of ptr, which


is the address of x.

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:

Which of the following is used to declare an integer variable named 'age'


in C?

a) int age;

b) age int;
c) integer age;

d) var age = int;

Explanation:

a) int age;

This is the correct syntax for declaring an integer variable named


'age' in C.

The general syntax for declaring a variable is: data_type


variable_name;

Question 62:

What is the output of the following code snippet?

#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!

This is the classic "Hello, World!" program.


The printf() function is used to print the given string to the
console.

The \n at the end of the string inserts a newline character,


moving the cursor to the next line.

Question 63:

Which of the following operators is used for addition in C?

a) ^

b) *

c) /

d) +

Explanation:

d) +

The + operator is used for addition in C.

Question 64:

What is the purpose of the return 0; statement in the main()


function?

a) To indicate successful program execution.

b) To print a message to the console.

c) To stop the program execution.

d) To declare a variable.

Explanation:

a) To indicate successful program execution.

In C, the main() function typically returns an integer value.

return 0; indicates that the program has executed


successfully.
Non-zero return values can be used to indicate errors.

Question 65:

Which of the following is used to declare a character variable in C?

a) char letter;

b) string letter;

c) character letter;

d) letter char;

Explanation:

a) char letter;

char is the data type used to store a single character in C.

Question 66:

What is the output of the following code snippet?

#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

The code calculates c as the difference between a (10) and b (5),


which is 10 - 5 = 5.

Question 67:

Which of the following is used to declare a constant variable in C?

a) const

b) static

c) volatile

d) register

Explanation:

a) const

The const keyword is used to declare a constant variable in C.

The value of a constant variable cannot be changed after it is


initialized.

Question 68:

What is the purpose of the #include <stdio.h> directive?

a) To define a function.

b) To declare a variable.

c) To include the standard input/output library.

d) To create a loop.
Explanation:

c) To include the standard input/output library.

stdio.h is a header file that provides standard input/output


functions like printf, scanf, getchar, putchar, etc.

Question 69:

Which of the following is used to represent a string literal in C?

a) 'a'

b) "a"

c) a

d) &a

Explanation:

b) "a"

Double quotes ("...") are used to represent string literals in C.

'a' represents a single character.

Question 70:

Which of the following is used to create a loop that executes a block of


code repeatedly as long as a condition is true?

a) for loop

b) while loop

c) if-else statement

d) switch statement

Explanation:

b) while loop

The while loop is used to repeatedly execute a block of code as long as a


given condition remains true.
Certainly, let's continue with 10 more basic C language MCQ questions:

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);

The gets() function is used to read a line of text from the


standard input (usually the keyboard) and store it in a character
array.

Note: The gets() function has security vulnerabilities and is


generally discouraged. fgets() is a safer alternative.

Question 72:

What is the output of the following code snippet?

#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

The code calculates c as the product of a (5) and b (2), which is 5


* 2 = 10.

Question 73:

Which of the following is used to declare a floating-point variable in C?

a) float num;

b) integer num;

c) character num;

d) string num;

Explanation:

a) float num;

float is the data type used to store floating-point numbers


(numbers with decimal points) in C.

Question 74:

What is the purpose of the break statement within a for loop?

a) To exit the loop immediately.

b) To skip the current iteration and continue to the next one.


c) To repeat the current iteration.

d) To pause the execution of the loop.

Explanation:

a) To exit the loop immediately.

The break statement within a for loop causes the loop to


terminate immediately, regardless of the loop condition.

Question 75:

Which of the following is used to declare an array of 10 integers in C?

a) int array[10];

b) int array(10);

c) int 10 array;

d) array int[10];

Explanation:

a) int array[10];

This declares an array named array that can hold 10 integer


elements.

Question 76:

What is the output of the following code snippet?

#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

Since the value of a is 10, which is greater than 0, the condition in


the if statement is true.

Therefore, the message "Positive" is printed.

Question 77:

Which of the following is used to represent a single-line comment in C?

a) /* ... */

b) // ...

c) # ...

d) '...'

Explanation:

b) // ...

// is used to start a single-line comment in C.

Any text following // on the same line is ignored by the compiler.

Question 78:
What is the purpose of the sizeof operator in C?

a) To find the address of a variable.

b) To determine the size of a data type or variable in bytes.

c) To allocate memory dynamically.

d) To check if a variable is initialized.

Explanation:

b) To determine the size of a data type or variable in bytes.

The sizeof operator returns the size of a data type or a variable


in bytes.

For example, sizeof(int) will return the number of bytes used


to store an integer on the specific system.

Question 79:

Which of the following is used to declare a pointer to a character in C?

a) int *ptr;

b) char *ptr;

c) float *ptr;

d) void *ptr;

Explanation:

*b) char ptr;

This declares a pointer named ptr that can hold the address of
acharacter variable.

Question 80:

What is the output of the following code snippet?

#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

The % operator is the modulus operator, which gives the


remainder of the division.

5 divided by 2 gives a quotient of 2 and a remainder of 1.

Certainly, let's continue with 10 more basic C language MCQ questions:

Question 81:

Which of the following is used to create a user-defined function in C?

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

Here, int is the return type, and myFunction is the function


name.

Question 82:

What is the output of the following code snippet?

#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

x *= 2 is the shorthand for x = x * 2.

This multiplies the value of x by 2, resulting in x becoming 10.

Question 83:

Which of the following is used to represent a character constant in C?

a) 'a'

b) "a"

c) a

d) &a

Explanation:

a) 'a'

Single quotes ('...') are used to represent character constants in


C.

"a" represents a string literal.

Question 84:

What is the purpose of the continue statement within a loop?

a) To exit the loop immediately.

b) To skip the current iteration and proceed to the next one.

c) To repeat the current iteration.


d) To pause the execution of the loop.

Explanation:

b) To skip the current iteration and proceed to the next one.

The continue statement skips the remaining part of the current


iteration of the loop and immediately jumps to the next iteration.

Question 85:

Which of the following is used to declare a boolean variable in C


(although not a native boolean type)?

a) bool flag;

b) boolean flag;

c) int flag;

d) char flag;

Explanation:

c) int flag;

C doesn't have a native boolean data type.

Integers are commonly used to represent boolean values, where


0 typically represents false and any non-zero value represents
true.

Question 86:

What is the output of the following code snippet?

#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

The condition x == y is false because x is 10 and y is 5.

Therefore, the code within the else block is executed, and "Not
Equal" is printed.

Question 87:

Which of the following is used to represent a multi-line comment in C?

a) // ...

b) /* ... */

c) # ...

d) '...'

Explanation:
b) / ... /

/* ... */ is used to enclose multi-line comments in C.

aAny text between /* and */ is ignored by the compiler.

Question 88:

What is the purpose of the #ifndef, #define, and #endif directives in


C?

a) To create a loop.

b) To define a function.

c) To include a header file.

d) To prevent multiple inclusions of a header file.

Explanation:

d) To prevent multiple inclusions of a header file.

These preprocessor directives are used together to create a


conditional inclusion block.

This ensures that a header file is included only once in aprogram,


preventing compilation errors and inconsistencies.

Question 89:

Which of the following is used to allocate memory dynamically in C?

a) malloc()

b) calloc()

c) free()

d) All of the above

Explanation:

d) All of the above

malloc() allocates a block of memory of a specified size.


calloc() allocates a block of memory of a specified size and
initializes all bytes to zero.

free() releases a block of memory that was previously allocated


using malloc() or calloc().

Question 90:

Which of the following is used to declare a pointer to a function in C?

a) int (*fptr)();

b) int *fptr();

c) int fptr*;

d) *int fptr();

Explanation:

*a) int (fptr)();

This declares a pointer named fptr that can hold the address of
a function that returns an integer and takes no arguments.

Certainly, let's continue with 10 more basic C language MCQ questions:

Question 91:

What is the output of the following code snippet?

#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

x /= 2 is the shorthand for x = x / 2.

This divides the value of x by 2, resulting in x becoming 5.

Question 92:

Which of the following is used to represent an escape sequence for a


newline character in C?

a) \n

b) \t

c) \r

d) \

Explanation:

a) \n

\n is the escape sequence for a newline character.

It moves the cursor to the beginning of the next line.

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.

b) To make the variable accessible from other files.

c) To make the variable a constant.

d) To make the variable a pointer.

Explanation:

a) To make the variable accessible only within the current file.

When a global variable is declared with the static keyword, its


scope is limited to the current file.

It cannot be accessed from other files.

Question 94:

Which of the following is used to declare a two-dimensional array in C?

a) int array[2];

b) int array[2][3];

c) int array[2, 3];

d) int [2][3] array;

Explanation:

b) int array[2][3];

This declares a two-dimensional array named array with 2 rows


and 3 columns.

Question 95:

What is the output of the following code snippet?

#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

Since the value of a is 5, which is greater than 0, the first


condition in the if-else statement is true.

Therefore, the message "Positive" is printed.

Question 96:

Which of the following is used to create a loop that executes a block of


code at least once?

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:

What is the purpose of the #include <math.h> header file in C?

a) Provides input/output functions like printf and scanf.

b) Provides memory allocation functions like malloc and free.

c) Provides mathematical functions like sin and cos.

d) Provides string manipulation functions like strcpy and strcat.

Explanation:

c) Provides mathematical functions like sin and cos.

The math.h header file provides a wide range of mathematical


functions, such as trigonometric functions (sin, cos, tan),
logarithmic functions (log, log10), exponential functions (exp,
pow), and more.

Question 98:

What is the purpose of the & operator in C?

a) To perform bitwise AND operation.

b) To get the address of a variable.

c) To dereference a pointer.
d) To perform logical AND operation.

Explanation:

b) To get the address of a variable.

The & operator is used to get the memory address of a variable.

Question 99:

Which of the following is used to declare a structure in C?

a) struct { ... }

b) class { ... }

c) union { ... }

d) enum { ... }

Explanation:

a) struct { ... }

The struct keyword is used to define a structure in C, which is a


user-defined data type that groups variables of different data
types under a single name.

Question 100:

What is the output of the following code snippet?

#include <stdio.h>

int main() {

char str[] = "Hello";

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.

Therefore, the size of the str array is 6 bytes.

You might also like