C Programming MCQs

Q.1 What will be the output of the following C code?
int main() {
int a = 10, b = 5;
printf(“%d”, a / b);
return 0;
}

A. 2
B. 5
C. 0
D. 10

Shw me The Right Answer

Answer . A 

Q.2 What is the output of the expression 2<3?

A. 0
B. 1
C. 2
D. 3

Shw me The Right Answer

Answer . B 

Q.3 What does the ‘!’ operator do in C?

A. Negation
B. Addition
C. Multiplication
D. None

Shw me The Right Answer

Answer . A 

Q.4 Which operator has higher precedence, ‘+’ or ‘*’?

A. *
B. Both are same
C. =+
D. None

Shw me The Right Answer

Answer . A 

Q.5 What does the ‘+’ operator do in C?

A. Addition
B. Subtraction
C. Multiplication
D. Division

Shw me The Right Answer

Answer . A 

Q.6 What is the result of the logical expression (1 && 0)?

A. 1
B. 0
C. True
D. False

Shw me The Right Answer

Answer . B 

Q.7 What does the ‘==’ operator check?

A. Assignment
B. Equality
C. Greater than
D. Less than

Shw me The Right Answer

Answer . B 

Q.8 Which operator is used for division in C?

A. –
B. *
C. /
D. =+

Shw me The Right Answer

Answer . C 

Q.9 Find the mistake in this code:
int main() {
float num;
printf(“Enter a number: “);
scanf(“%f”, num);
printf(“You entered: %f”, num);
return 0;
}

A. Missing & in scanf
B. Incorrect format specifier in printf
C. No error
D. Syntax error

Shw me The Right Answer

Answer . A 

Q.10 Identify the error in this C code:
int main() {
int x;
scanf(“%d”, x);
printf(“%d”, x);
return 0;
}

A. Missing & in scanf
B. Wrong format specifier
C. No error
D. Syntax error

Shw me The Right Answer

Answer . A 

Q.11 Pseudocode:
READ number PRINT “The number is “, number
What does this pseudocode do?

A. Reads and prints a number
B. Prints a fixed number
C. Generates a random number
D. None of these

Shw me The Right Answer

Answer . A 

Q.12 What will the following C code output?
int main() {
int num;
scanf(“%d”, &num);
printf(“%d”, num);
return 0;
}

A. The inputted number
B. %d
C. Syntax Error
D. Nothing

Shw me The Right Answer

Answer . A 

Q.13 What will be the output of the following C code?
int main() {
printf(“%d”, 500);
return 0;
}

A. 500
B. %d
C.. Syntax Error
D. None of these

Shw me The Right Answer

Answer . A 

Q.14 What does %d signify in the printf or scanf function?

A. Double data type
B. Decimal integer
C. Dynamic allocation
D. Directory path

Shw me The Right Answer

Answer . B 

Q.15 What is the purpose of the printf function in C?

A. To read input
B. To print output
C. To perform calculations
D. To control program flow

Shw me The Right Answer

Answer . B 

Q.16 Spot the error in this code snippet:
#include <stdio.h>
int main() {
const int age; age = 30;
printf(“%d”, age);
return 0;
}

A. Uninitialized constant
B. Missing return statement
C. Syntax error in printf statement
D. No error

Shw me The Right Answer

Answer . A 

Q.17 Identify the error in this C code:
int main() {
int number = 100.5;
printf(“%d”, number);
return 0;
}

A. Assigning float to int
B. Syntax error
C. No error
D. Wrong printf format

Shw me The Right Answer

Answer . A 

Q.18 What will be the output of the following C code?
int main() {
char c = ‘A’;
printf(“%d”, c);
return 0;
}

A. 65
B. A
C. Syntax Error
D. None of these

Shw me The Right Answer

Answer . A 

Q.19 What is the difference between ‘float’ and ‘double’ data types in C?

A. Syntax only
B. Precision
C. Usage
D. No difference

Shw me The Right Answer

Answer . B 

Q.20 What is the size of ‘int’ data type in C?

A. Depends on the system
B. 4 bytes
C. 8 bytes
D. 2 bytes

Shw me The Right Answer

Answer . A 

Q.21 Which of the following is a valid identifier in C?

A. 2ndName
B. _name
C. #name
D. none of these

Shw me The Right Answer

Answer . B 

Q.22 What data type would you use to store a character in C?

A. int
B. float
C. char
D. double

Shw me The Right Answer

Answer . C 

Q.23 Which of the following is not a keyword in C?

A. int
B. char
C. include
D. float

Shw me The Right Answer

Answer . C 

Q.24 Identify the error in this C program:
#include <stdio.h>
int main() {
print(“Hello, World!”);
return 0;
}

A. Missing #include statement
B. Incorrect function name
C. Syntax error in return statement
D. No error

Shw me The Right Answer

Answer . B 

Q.25 What will be the output of the following C program?
#include <stdio.h>
int main() {
printf(“Hello, World!”);
return 0;
}

A. Hello, World!
B. Syntax Error
C. 0
D. Nothing

Shw me The Right Answer

Answer . A 

Q.26 What is the primary purpose of writing a “Hello World” program when learning a new programming language?

A. To test if the language supports string operations
B. To learn complex programming concepts
C. To demonstrate basic syntax and output
D. To introduce advanced programming features

Shw me The Right Answer

Answer . C 

Q.27 How does a compiler differ from an interpreter?

A. A compiler executes code, while an interpreter does not
B. A compiler debugs code, while an interpreter does not
C. A compiler translates the entire program at once, while an interpreter translates it line by line
D. A compiler is used only in C programming, while an interpreter is not

Shw me The Right Answer

Answer . C 

Q.28 Which of the following is true about interpreters?

A. They execute programs faster than compilers
B. They translate the entire program at once
C. They translate and execute code line by line
D. They are not used in modern programming

Shw me The Right Answer

Answer . C 

Q.29 What is the main function of a compiler in programming?

A. To write code
B. To interpret code
C. To convert code into machine language
D. To debug code

Shw me The Right Answer

Answer . C 

Q.30 Why is learning programming important in today’s world?

A. For academic purposes only
B. To automate and solve complex problems
C. Only for software development
D. For entertainment purposes only

Shw me The Right Answer

Answer . B 

Q.31 What is the scope of a local variable in C?

A. Inside the function in which it is declared
B. Throughout the program
C. Inside the file
D. Throughout the function block where it is declared

Shw me The Right Answer

Answer . A 

Q.32 What is recursion in C?

A. A function calling another function
B. A function that has no return type
C. A function calling itself
D. A loop within a function

Shw me The Right Answer

Answer . C 

Q.33 What does ‘pass by value’ mean in C?

A. Passing a copy of the argument
B. Passing the argument directly
C. Passing the memory address
D. Passing the variable type

Shw me The Right Answer

Answer . A 

Q.34 What is the primary purpose of a function in C?

A. Code reuse and modularity
B. Error handling
C. Memory management
D. User interface creation

Shw me The Right Answer

Answer . A 

Q.35 Spot the mistake:
int main() {
for(int i = 0; i < 5; i++) {
if(i == 2)
continue;
printf(“%d “, i);
} return 0;
}

A. Infinite loop
B. Skips printing 2
C. Syntax error
D. No error

Shw me The Right Answer

Answer . B 

Q.36 Identify the error in this C code:
int main() {
int i = 0;
while(i < 3) {
i++;
}
printf(“%d “, i);
return 0;
}

A. Infinite loop
B. Syntax error
C. No error
D. Prints nothing

Shw me The Right Answer

Answer . C 

Q.37 SET i TO 0 WHILE i LESS THAN 10 IF i MOD 2 EQUALS 0 THEN CONTINUE INCREMENT i PRINT i END WHILE

A. Prints odd numbers from 1 to 9
B. Prints even numbers from 0 to 8
C. Prints all numbers from 0 to 9
D. Syntax error

Shw me The Right Answer

Answer . A 

Q.38 Pseudocode:
SET count TO 0 REPEAT PRINT count INCREMENT count UNTIL count EQUALS 3

A. Prints 0 1 2 3
B. Prints 0 1 2
C. Prints 3
D. Syntax error

Shw me The Right Answer

Answer . B 

Q.39 Pseudocode:
FOR i FROM 1 TO 5 PRINT i

A. Prints numbers from 1 to 5
B. Prints numbers from 1 to 4
C. Prints 5
D. Syntax error

Shw me The Right Answer

Answer . A 

Q.40 Pseudocode:
SET x TO 5 WHILE x GREATER THAN 0 DO PRINT x DECREMENT x

A. Prints numbers from 5 to 1 in descending order
B. Prints 5
C. Prints 0
D. Syntax error

Shw me The Right Answer

Answer . A 

Q.41 Pseudocode:
SET num TO 10 IF num EQUALS 10 THEN PRINT “Ten” ELSE PRINT “Not Ten”

A. Prints “Ten”
B. Prints “Not Ten”
C. Prints nothing
D. Syntax error

Shw me The Right Answer

Answer . A 

Q.42 What is the output of the following C code?
int main() {
int x = 0; do {
printf(“%d “, x);
x++;
} while(x < 3);
return 0;
}

A. 0 1 2
B. 0 1
C. 1 2 3
D. No output

Shw me The Right Answer

Answer . A 

Q.43 What does this C code do?
int main()
{ int i = 0;
while(i < 5) { if(i == 2) break;
printf(“%d “, i); i++; }
return 0;
}

A. Prints 0 1 2
B. Prints 0 1
C. Prints all numbers less than 5
D. Prints nothing

Shw me The Right Answer

Answer . B 

Q.44 What will the following C code print?
int main() {
for(int i = 0; i < 3; i++)
{ printf(“%d “, i); }
return 0;
}

A. 0 1 2
B. 1 2 3
C. 0 1 2 3
D. 1 2 3 4

Shw me The Right Answer

Answer . A 

Q.45 When is a do-while loop preferred over a while loop?

A. When the condition is complex
B. When the loop must execute at least once
C. When the loop should not execute
D. When the loop is infinite

Shw me The Right Answer

Answer . B 

Q.46 What is the purpose of the continue statement in loops?

A. Terminates the loop
B. Skips to the next iteration
C. Does nothing
D. Exits the program

Shw me The Right Answer

Answer . B 

Q.47 In a switch statement, what happens if a break statement is omitted from a case?

A. The program exits
B. The case is skipped
C. Fall-through to the next case
D. Syntax error

Shw me The Right Answer

Answer . C 

Q.48 What is the difference between for and while loops?

A. Syntax
B. Execution speed
C. Functionality
D. No difference

Shw me The Right Answer

Answer . A 

Q.49 What does the break statement do in a loop?

A. Exits the loop
B. Skips the current iteration
C. Repeats the loop
D. Does nothing

Shw me The Right Answer

Answer . A 

Q.50 Identify the mistake:
int main() {
int x = 10, y; y = x == 10 ? x : 0;
printf(“%d”, y);
return 0;
}

A. Incorrect use of ternary operator
B. Syntax error
C. No error
D. Wrong variable used

Shw me The Right Answer

Answer . C 

Q.51 Spot the error:
int main() {
int a = 10, b = 0;
printf(“%d”, a / b);
return 0;
}

A. Division by zero
B. Syntax error
C. No error
D. Wrong format specifier

Shw me The Right Answer

Answer . A 

Q.52 Pseudocode:
SET c TO 15 IF c MOD 2 EQUALS 0 THEN PRINT “Even” ELSE PRINT “Odd”

A. Prints “Even”
B. Prints “Odd”
C. Prints nothing
D. Syntax error

Shw me The Right Answer

Answer . B 

Q.53 Pseudocode:
SET x TO 5 IF x GREATER THAN 0 AND x LESS THAN 10 THEN PRINT “x is between 0 and 10”

A. Prints “x is between 0 and 10”
B. Prints nothing
C. Syntax error
D. Prints “x is not between 0 and 10”

Shw me The Right Answer

Answer . A 

Q.54 Pseudocode:
SET a TO 10, b TO 20 IF a GREATER THAN b THEN PRINT “a is greater” ELSE PRINT “b is greater or equal”

A. Prints “a is greater”
B. Prints “b is greater or equal”
C. Prints nothing
D. Syntax error

Shw me The Right Answer

Answer . B 

Q.55 Pseudocode:
SET value TO 10 PRINT NOT value

A. -10
B. 0
C. 1
D. 10

Shw me The Right Answer

Answer . B 

Q.56 Pseudocode:
 SET num TO 5 IF num EQUALS 5 THEN PRINT “Five” ELSE PRINT “Not Five”

A. Prints “Five”
B. Prints “Not Five”
C. Prints nothing
D. Syntax error

Shw me The Right Answer

Answer . A 

Q.57 Pseudocode:
SET a TO 10, b TO 20 PRINT a PLUS b

A. 30
B. 20
C. 10
D. 0

Shw me The Right Answer

Answer . A 

Q.58 Pseudocode:
SET x TO 5, y TO 10 IF x LESS THAN y THEN PRINT “x is less than y” ELSE PRINT “x is not less than y”

A. Prints “x is less than y”
B. Prints “x is not less than y”
C. Prints nothing
D. Syntax error

Shw me The Right Answer

Answer . A 

Q.59 What is the result of the following expression?
int a = 1; int b = a++ + ++a;

A. 2
B. 3
C. 4
D. 5

Shw me The Right Answer

Answer . C 

Q.60 What is the output of the following C code snippet?
int main() {
int x
= 10;
printf(“%d”, x++ + ++x);
return 0;
}

A. 20
B. 21
C. 22
D. 23

Shw me The Right Answer

Answer . C 

Q.61 What is the output of sizeof(pointer) where pointer is an integer pointer in C?

A. 4 on all systems
B. 8 on all systems
C. Depends on the system architecture
D. Depends on the compiler

Shw me The Right Answer

Answer . C 

Q.62 What is a pointer in C?

A. A variable that stores a memory address
B. A function
C. An array
D. A data type

Shw me The Right Answer

Answer . A 

Q.63 Find the mistake:
int main() {
int arr[5] = {1, 2, 3, 4, 5};
for(int i = 0; i <= 5; i++) {
printf(“%d “, arr[i]);
}
return 0;
}

A. Off-by-one error in loop bounds
B. Syntax error
C. No error
D. Incorrect array initialization

Shw me The Right Answer

Answer . A 

Q.64 Identify the error in this C code:
int main() {
int arr[3];
arr[3] = 10;
printf(“%d”, arr[3]);
return 0;
}

A. Array index out of bounds
B. Syntax error
C. No error
D. Wrong printf format

Shw me The Right Answer

Answer . A 

Q.65  ARRAY matrix[2][3] SET matrix[0][0] TO 1, matrix[0][1] TO 2, matrix[0][2] TO 3, matrix[1][0] TO 4, matrix[1][1] TO 5, matrix[1][2] TO 6 PRINT matrix[1][2]

A. Prints 1
B. Prints 5
C. Prints 6
D. Syntax error

Shw me The Right Answer

Answer . C   

Q.66 Pseudocode:
FUNCTION SumArray(ARRAY arr, SIZE) SET sum TO 0 FOR i FROM 0 TO SIZE-1 INCREMENT sum BY arr[i] RETURN sum

A. Calculates the sum of array elements
B. Returns the size of the array
C. Returns the first element
D. Syntax error

Shw me The Right Answer

Answer . A   

Q.67 Pseudocode:
ARRAY arr[10] FOR i FROM 0 TO 9 SET arr[i] TO i TIMES 2 END FOR PRINT arr[6]

A. Prints 6
B. Prints 12
C. Prints 7
D. Syntax error

Shw me The Right Answer

Answer . B   

Q.68 Pseudocode:
ARRAY numbers[5] SET numbers[0] TO 1 PRINT numbers[0]

A. Prints 1
B. Prints 0
C. Prints random value
D. Syntax error

Shw me The Right Answer

Answer . A   

Q.69 Complete the C code:
int main() {
int arr[5];
for(int i = 0; i < 5; i++) { ___ }
printf(“%d”, arr[2]);
return 0;
}

A. arr[i] = i;
B. arr[i] = i * 2;
C. arr[i] = i + 1;
D. arr[i] = 0;

Shw me The Right Answer

Answer . A   

Q.70 What does the following C code do?
int main() {
int arr[3][4] = {{1, 2}, {3, 4}};
printf(“%d”, arr[1][1]);
return 0;
}

A. Prints 2
B. Prints 3
C. Prints 4
D. Prints 0

Shw me The Right Answer

Answer . C   

Q.71 What is the output of this C code?
int main() {
int arr[5] = {1, 2, 3};
printf(“%d”, arr[4]);
return 0;
}

A. 0
B. 3
C. Random value
D. Error

Shw me The Right Answer

Answer . A   

Q.72 What will be the output of the following C code?
int main() {
int arr[] = {1, 2, 3, 4, 5};
printf(“%d”, arr[3]);
return 0;
}

A. 1
B. 2
C. 3
D. 4

Shw me The Right Answer

Answer . D   

Q.73 In C, can an array be resized after its declaration?

A. Yes
B. No
C. Only if it’s a dynamic array
D. Only in C99 standard

Shw me The Right Answer

Answer . B   

Q.74 How does C handle array index out of bounds errors during runtime?

A. Generates a compile-time error
B. Automatically corrects the index
C. Generates a runtime error
D. Does not check for bounds

Shw me The Right Answer

Answer . D   

Q.75 What is the default value of an uninitialized array in C?

A. 0
B. 1
C. Random memory value
D. -1

Shw me The Right Answer

Answer . C   

Q.76 How can you access the third element in the second row of a 2D array int arr[3][4]; in C?

A. arr[1][2]
B. arr[2][3]
C. arr[3][2]
D. arr[2][1]

Shw me The Right Answer

Answer . A   

Q.77 What is the size of a 2-dimensional array int arr[3][4]; in C?

A. 3
B. 4
C. 12
D. Cannot be determined

Shw me The Right Answer

Answer . C   

Q.78 Which of the following is a correct way to pass an array to a function in C?

A. By specifying the size of the array
B. By passing the first element
C. By passing the array name
D. By passing each element individually

Shw me The Right Answer

Answer . C   

Q.79 How do you initialize an array in C?

A. With any value
B. With 0s
C. With 1s
D. Cannot be initialized

Shw me The Right Answer

Answer . A   

Q.80 What happens when you try to access an array element outside its bounds in C?

A. Syntax error
B. Compilation error
C. Runtime error
D. Undefined behavior

Shw me The Right Answer

Answer . D   

Q.81 Which index is used to access the first element of an array in C?

A. 0
B. 1
C. -1
D. First

Shw me The Right Answer

Answer . A   

Q.82 How do you declare an array of integers in C?

A. int arr[10];
B. array int[10];
C. int array 10;
D. [10]int array;

Shw me The Right Answer

Answer . A   

Q.83 Find the error:
int main() {
int x = 5;
increment(&x);
printf(“%d”, x);
return 0;
}
void increment(int* n) {
*n++;
}

A. Incorrect pointer usage in increment
B. Syntax error
C. No error
D. Wrong printf format

Shw me The Right Answer

Answer . A   

Q.84 Spot the mistake:
int main() {
int result = sum(5, 10);
printf(“%d”, result);
return 0;
}
int sum(int a, int b) {
return;
}

A. Missing return value in sum
B. Syntax error
C. No error
D. Incorrect function parameters

Shw me The Right Answer

Answer . A   

Q.85 Identify the error in this C code:
int main() {
printHello();
return 0;
}
void printHello() {
printf(“Hello”);
}

A. Missing declaration of printHello
B. Syntax error
C. No error
D. Wrong function call

Shw me The Right Answer

Answer . A   

Q.86 Pseudocode:
 FUNCTION Fibonacci(n) IF n LESS THAN OR EQUAL TO 1 THEN RETURN n ELSE RETURN Fibonacci(n-1) PLUS Fibonacci(n-2) END FUNCTION CALL Fibonacci(5)

A. 5
B. 8
C. Error
D. None

Shw me The Right Answer

Answer . A   

Q.87 Pseudocode:
FUNCTION CheckEven(number) IF number MOD 2 EQUALS 0 THEN RETURN True ELSE RETURN False END FUNCTION CALL CheckEven(4)

A. True
B. False
C. Error
D. None

Shw me The Right Answer

Answer . A   

Q.88 Pseudocode:
FUNCTION Add(a, b) RETURN a PLUS b END FUNCTION CALL Add(5, 10)

A. 15
B. 5
C. 10
D. Error

Shw me The Right Answer

Answer . A   

Q.89 What is the output of this recursive function call?
int main() {
printf(“%d “, factorial(5));
return 0;
}
int factorial(int n) {
if (n==0)
return 1;
else
return n * factorial(n – 1);
}

A. 120
B. 24
C. 5
D. Error

Shw me The Right Answer

Answer . A   

Q.90 What will be the output of the following C code?
int main() {
int num = 10;
increment(num);
printf(“%d”, num);
return 0;
} void increment(int n) {
n++;
}

A. 10
B. 11
C. Error
D. Nothing

Shw me The Right Answer

Answer . A   

Q.91 What is a structure in C?

A. A collection of variables under a single name
B. A method for looping
C. A data type for characters
D. A control flow statement

Shw me The Right Answer

Answer . A   

Q.92 Spot the mistake:
int main() {
char *str = “Hello”;
str[0] = ‘M’;
printf(“%s”, str);
return 0;
}

A. Cannot modify a string literal
B. Syntax error
C. No error
D. Wrong printf format

Shw me The Right Answer

Answer . A   

Q.93 Identify the error in this C code:
int main() {
char str[] = “Hello”;
str[0] = ‘M’;
printf(“%s”, str);
return 0;
}

A. Cannot modify a string literal
B. No error
C. Syntax error
D. Wrong printf format

Shw me The Right Answer

Answer . B   

Q.94 Pseudocode:
FUNCTION CopyString(STRING source, STRING destination) FOR EACH character IN source SET destination TO source END FOR

A. Copies one string to another
B. Compares two strings
C. Concatenates two strings
D. Reverses a string

Shw me The Right Answer

Answer . A   

Q.95 Pseudocode:
FUNCTION FindChar(STRING str, CHAR ch) FOR EACH character IN str IF character EQUALS ch RETURN True END FOR RETURN False

A. Searches for a character in a string and returns true if found
B. Reverses the string
C. Concatenates the string
D. None of the above

Shw me The Right Answer

Answer . A   

Q.96 Pseudocode:
FUNCTION ConcatStrings(STRING str1, STRING str2) RETURN str1 PLUS str2 END FUNCTION

A. Concatenates two strings and returns the result
B. Finds the length of the two strings
C. Reverses the two strings
D. Compares the two strings

Shw me The Right Answer

Answer . A   

Q.97 What does the following C code do?
int main() {
char str1[] = “Hello”, str2[20];
strcpy(str2, str1);
strrev(str2);
printf(“%s”, str2);
return 0;
}

A. Copies str1 to str2 and reverses it
B. Concatenates str1 and str2
C. Compares str1 and str2
D. None of the above

Shw me The Right Answer

Answer . A   

Q.98 Complete the C code:
int main() {
char str[20];
___;
printf(“%s”, str);
return 0;
}
to copy “Hello” into str.

A. strcpy(str, “Hello”);
B. str = “Hello”;
C. strncpy(str, “Hello”, 5);
D. strcat(str, “Hello”);

Shw me The Right Answer

Answer . A   

Q.99 What is the output of this C code?
int main() {
char str[] = “Hello World”;
printf(“%d”, strlen(str));
return 0;
}

A. 11
B. 12
C. 10
D. Error

Shw me The Right Answer

Answer . A   

Q.100 What is the purpose of the strchr function in C?

A. Finds the first occurrence of a character in a string
B. Concatenates two strings
C. Reverses a string
D. Compares two strings

Shw me The Right Answer

Answer . A   

Q.101 How does the strncpy function differ from strcpy?

A. strncpy limits the number of characters copied
B. strncpy reverses the string
C. strncpy concatenates the string
D. No difference

Shw me The Right Answer

Answer . A   

Q.102 In C, which function is used to reverse a string?

A. strrev
B. strinvert
C. reverse
D. invert

Shw me The Right Answer

Answer . A   

Q.103 What happens if a string copied using strcpy is larger than the destination array?

A. Syntax error
B. Compilation error
C. Runtime error
D. Undefined behavior

Shw me The Right Answer

Answer . D   

Q.104 How do you declare an array of strings in C?

A. char *arr[];
B. string arr[];
C. char arr[][];
D. char **arr;

Shw me The Right Answer

Answer . A   

Q.105 What is the return value of strcmp when the two strings are equal in C?

A. 0
B. 1
C. -1
D. The length of the strings

Shw me The Right Answer

Answer . A   

Q.106 Which function is used to determine the length of a string in C?

A. strlen
B. strcmp
C. strncpy
D. strchr

Shw me The Right Answer

Answer . A   

Q.107 What does the strcat function do in C?

A. Concatenates two strings
B. Compares two strings
C. Converts a string to an integer
D. Splits a string into tokens

Shw me The Right Answer

Answer . A   

Q.108 What is the purpose of the strcpy function in C?

A. To compare two strings
B. To concatenate two strings
C. To copy one string to another
D. To find the length of a string

Shw me The Right Answer

Answer . C   

Q.109 How is a string represented in C?

A. As a series of characters followed by a null character
B. As an array of integers
C. As a single character
D. As a special data type

Shw me The Right Answer

Answer . A   

Q.110 Find the error:
int main() {
int arr[3] = {1, 2, 3};
int *p = arr;
printf(“%d”, *p + 2);
return 0;
}

A. Pointer arithmetic error
B. Syntax error
C. No error
D. Wrong printf format

Shw me The Right Answer

Answer . C   

Q.111 Spot the mistake:
int main() {
int a = 10, *p = &a;
*p++;
printf(“%d”, a);
return 0;
}

A. Incrementing a instead of *p
B. Syntax error
C. No error
D. Incorrect use of increment operator

Shw me The Right Answer

Answer . A   

Q.112 Identify the error in this C code:
int main() {
int *p; *p = 10;
printf(“%d”, *p);
return 0;
}

A. Uninitialized pointer
B. Syntax error
C. No error
D. Wrong printf format

Shw me The Right Answer

Answer . A   

Q.113 Pseudocode:
FUNCTION Increment(VALUE POINTER p) INCREMENT VALUE AT p END FUNCTION CALL Increment(ADDRESS OF num)

A. Increments num
B. Prints num
C. Returns num’s address
D. Error

Shw me The Right Answer

Answer . A   

Q.114 Pseudocode:
SET a TO 10, POINTER p TO ADDRESS OF a, PRINT VALUE AT p

A. Prints 10
B. Prints the address of a
C. Error
D. None of the above

Shw me The Right Answer

Answer . A   

Q.115 Complete the C code:
int main() {
int a = 10;
int *p = &a; ___;
printf(“%d”, a);
return 0;
}
to make the output 20.

A. *p = 20;
B. p = 20;
C. a = 20;
D. &a = 20;

Shw me The Right Answer

Answer . A   

Q.116 What does the following C code do?
int main() {
int arr[] = {1, 2, 3};
int *p = arr;
printf(“%d”, *(p + 1));
return 0;
}

A. Prints the first element of arr
B. Prints the second element of arr
C. Prints the third element of arr
D. Error

Shw me The Right Answer

Answer . B   

Q.117 What will be the output of the following C code?
int main() {
int a = 10;
int *p = &a;
printf(“%d”, *p);
return 0;
}

A. 10
B. Address of a
C. Error
D. 0

Shw me The Right Answer

Answer . A   

Q.118 How does dynamic memory allocation differ between malloc and calloc?

A. malloc initializes memory to zero, calloc does not
B. calloc initializes memory to zero, malloc does not
C. They don’t differ
D. malloc allocates more efficiently

Shw me The Right Answer

Answer . B   

Q.119 What does passing a pointer to a function allow the function to do?

A. Read the value of the variable
B. Change the value of the variable
C. Copy the variable
D. None of the above

Shw me The Right Answer

Answer . B   

Q.120 How do you access the value pointed to by a pointer in C?

A. Using the * operator
B. Using the & operator
C. Directly by the pointer name
D. Using the -> operator

Shw me The Right Answer

Answer . A   

Q.121 What is the use of the va_start, va_arg, and va_end macros in C?

A. They are used for file operations
B. They are used for memory allocation
C. They are used for handling variable arguments
D. They are used for error handling

Shw me The Right Answer

Answer . C   

Q.122 How can you access the individual command line arguments in a C program?

A. Using a for loop with argc and argv
B. Through global variables
C. By indexing into a predefined array
D. By calling a special function

Shw me The Right Answer

Answer . A   

Q.123 What is variable argument list in C, and which header file is required for it?

A. A list of arguments of variable types, stdlib.h required
B. A list of arguments of fixed types, stdio.h required
C. A list of arguments of variable length, stdarg.h required
D. A list of arguments of variable length, string.h required

Shw me The Right Answer

Answer . C   

Q.124 What is the purpose of argc in a C program?

A. To count the number of functions
B. To store environment variables
C. To count the number of command line arguments
D. To store error codes

Shw me The Right Answer

Answer . C   

Q.125 How are command line arguments passed to a C program?

A. Through global variables
B. Through function parameters
C. Through a dedicated command-line function
D. Through environment variables

Shw me The Right Answer

Answer . B   

Q.126 Spot the mistake:
#ifndef FILE_H #define FILE_H /* File contents */ #endif in a header file named “file.h”

A. The macro name should match the file name
B. No error
C. The header file name should be uppercase
D. The #ifndef and #define order is incorrect

Shw me The Right Answer

Answer . B   

Q.127 Identify the error in this C code snippet:
#include <stdio.h> #define MAX 100 #undef MAX int main() { printf(“%d”, MAX); return 0; }

A. Syntax error
B. Use of undefined MAX
C. No error
D. Incorrect usage of printf

Shw me The Right Answer

Answer . B   

Q.128 What happens when a header file is included twice in a C program without using include guards?

A. The program will not compile
B. The program compiles with warnings
C. The program compiles successfully, but it may cause errors
D. Nothing specific

Shw me The Right Answer

Answer . C   

Q.129 What is the result of using the #undef directive in C?

A. It deletes a file from the project
B. It removes a defined macro
C. It undefines a variable
D. It causes a compilation error

Shw me The Right Answer

Answer . B   

Q.130 How does the #ifndef directive function in C?

A. It checks if a variable is not defined
B. It imports a file if not previously imported
C. It checks if a macro is not defined
D. It defines a new macro if a condition is met

Shw me The Right Answer

Answer . C   

Q.131 What is the function of the #define directive in C?

A. To define a new function
B. To import a library
C. To define a macro or constant
D. To declare a variable

Shw me The Right Answer

Answer . C   

Q.132 What is the purpose of the #include directive in C?

A. To include a library during program execution
B. To declare a variable
C. To include a header file at compile time
D. To initialize variables

Shw me The Right Answer

Answer . C   

Q.133 Spot the mistake:
FILE *file = fopen(“example.bin”, “wb”); fwrite(&data, sizeof(data), 1, file); fclose(file);

A. Data should not be passed by reference in fwrite
B. fwrite arguments are in the wrong order
C. No error
D. File not opened in binary mode

Shw me The Right Answer

Answer . C   

Q.134 Identify the error in this C code for file writing:
FILE *file = fopen(“example.txt”, “w”); fprintf(file, “Hello World”); fclose(file);

A. Missing file mode in fopen
B. Incorrect usage of fprintf
C. No error
D. File not closed properly

Shw me The Right Answer

Answer . C   

Q.135 Complete the C code to read a binary file:
FILE *file = fopen(“example.bin”, “rb”); ___; fclose(file);

A. fread(buffer, sizeof(buffer), 1, file);
B. read(file, buffer, sizeof(buffer));
C. file >> buffer;
D. getline(file, buffer);

Shw me The Right Answer

Answer . A   

Q.136 What happens if you try to write to a file in C without opening it first?

A. The write operation succeeds with a warning
B. The write operation fails silently
C. An error occurs
D. The file is automatically created

Shw me The Right Answer

Answer . C   

Q.137 What is the purpose of the feof function in C?

A. To check if the end-of-file has been reached
B. To open a file
C. To read a file character by character
D. To write to a file

Shw me The Right Answer

Answer . A   

Q.138 How does file handling in binary mode differ from text mode in C?

A. Binary mode can read non-text files, text mode cannot
B. Binary mode is faster
C. Text mode translates newlines, binary mode does not
D. Text mode is more secure

Shw me The Right Answer

Answer . C   

Q.139 What function in C is typically used to open a file for reading or writing?

A. fopen()
B. open()
C. file_open()
D. stream()

Shw me The Right Answer

Answer . A   

Q.140 What is a stream in the context of C programming?

A. A sequence of characters
B. A type of data structure
C. A flow of binary data
D. A method of structuring code

Shw me The Right Answer

Answer . A   

Q.141 Spot the mistake:
struct Data { int val; }; int main() {
struct Data *ptr;
ptr->val = 100;
printf(“%d”, ptr->val);
return 0;
}

A. Uninitialized pointer used
B. Syntax error
C. No error
D. Wrong printf format

Shw me The Right Answer

Answer . A   

Q.142 Identify the error in this C code:
struct Point { int x, y; };
struct Point p1; p1.x = 10; p1.y = 20;

A. No error
B. Struct Point not properly declared
C. Struct members not properly accessed
D. Struct Point not properly instantiated

Shw me The Right Answer

Answer . A   

Q.143 Complete the C code:
union Data {
int i;
float f;
char str[20];
};
union Data data; ___;
printf(“%s”, data.str);
to store and print “Hello”.

A. data.str = “Hello”;
B. strcpy(data.str, “Hello”);
C. data = {.str = “Hello”};
D. data.str = {‘H’, ‘e’, ‘l’, ‘l’, ‘o’, ‘\0’};

Shw me The Right Answer

Answer . B   

Q.144 What does the following C code do?
struct Point {
int x, y;
};
struct Point p1 = {1, 2};
printf(“%d %d”, p1.x, p1.y);

A. Declares a structure and prints its members
B. Causes a syntax error
C. Initializes a structure but fails to print
D. None of the above

Shw me The Right Answer

Answer . A   

Q.145 What happens when a structure is passed to a function in C?

A. The entire structure is copied
B. Only the structure pointer is passed
C. The first element is passed
D. None of the above

Shw me The Right Answer

Answer . A   

Q.146 How are bit fields used in a structure in C?

A. To define the number of bits used by an integer type member
B. To encrypt data
C. To align data in memory
D. To define array sizes

Shw me The Right Answer

Answer . A   

Q.147 How can you instantiate a structure in C?

A. By using the new keyword
B. By declaring a variable of the structure type
C. By defining the structure with #define
D. By calling a function that returns a structure

Shw me The Right Answer

Answer . B   

Q.148 What is an enumerated data type in C?

A. A data type that allows numeric values only
B. A data type for storing lists of named constants
C. A special kind of array
D. A structure that can hold any data type

Shw me The Right Answer

Answer . B   

Q.149 What is the key difference between a structure and a union in C?

A. A structure can store multiple data types, a union cannot
B. A union can store multiple data types, a structure cannot
C. In a structure, only one member can be accessed at a time
D. In a union, only one member can be accessed at a time

Shw me The Right Answer

Answer . D   

Q.150 How do you access a member of a structure using a structure pointer in C?

A. With the dot operator (.)
B. With the arrow operator (->)
C. With the ampersand (&)
D. With the asterisk (*)

Shw me The Right Answer

Answer . B   

 

You may also like...

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments