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!

Q91

Q91 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

Q92

Q92 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

Q93

Q93 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

Q94

Q94 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

Q95

Q95 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

Q96

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

Q97

Q97 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

Q98

Q98 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

Q99

Q99 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

Q100

Q100 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

Q101

Q101 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

Q102

Q102 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

Q103

Q103 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

Q104

Q104 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

Q105

Q105 Which function is used to determine the length of a string in C?

A

strlen

B

strcmp

C

strncpy

D

strchr

Q106

Q106 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

Q107

Q107 How do you declare an array of strings in C?

A

char *arr[];

B

string arr[];

C

char arr[][];

D

char **arr;

Q108

Q108 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

Q109

Q109 In C, which function is used to reverse a string?

A

strrev

B

strinvert

C

reverse

D

invert

Q110

Q110 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

Q111

Q111 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

Q112

Q112 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

Q113

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

Q114

Q114 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

Q115

Q115 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

Q116

Q116 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

Q117

Q117 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

Q118

Q118 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

Q119

Q119 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

Q120

Q120 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

ad verticalad vertical
ad