an HCL GUVI product

c programming banner

C Programming Multiple Choice Questions (MCQs) and Answers

Master C Programming with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of C Programming. Begin your placement preparation journey now!

Q31

Q31 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

Q32

Q32 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

Q33

Q33 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

Q34

Q34 Pseudocode:

FUNCTION Add(a, b) RETURN a PLUS b END FUNCTION CALL Add(5, 10)

A

15

B

5

C

10

D

Error

Q35

Q35 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

Q36

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

Q37

Q37 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

Q38

Q38 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

Q39

Q39 What is the default value of an uninitialized array in C?

A

0

B

1

C

Random memory value

D

-1

Q40

Q40 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

Q41

Q41 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

Q42

Q42 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

Q43

Q43 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

Q44

Q44 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

Q45

Q45 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

Q46

Q46 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

Q47

Q47 What is a pointer in C?

A

A variable that stores a memory address

B

A function

C

An array

D

A data type

Q48

Q48 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

Q49

Q49 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

Q50

Q50 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

Q51

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

Q52

Q52 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

Q53

Q53 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

Q54

Q54 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

Q55

Q55 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

Q56

Q56 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

Q57

Q57 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

Q58

Q58 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

Q59

Q59 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

Q60

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

ad vertical