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!

Q121

Q121 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

Q122

Q122 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

Q123

Q123 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

Q124

Q124 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

Q125

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

A

strlen

B

strcmp

C

strncpy

D

strchr

Q126

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

A

char *arr[];

B

string arr[];

C

char arr[][];

D

char **arr;

Q127

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

A

strrev

B

strinvert

C

reverse

D

invert

Q128

Q128 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

Q129

Q129 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

Q130

Q130 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

Q131

Q131 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

Q132

Q132 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 (*)

Q133

Q133 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

Q134

Q134 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

Q135

Q135 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

Q136

Q136 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

Q137

Q137 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'};

Q138

Q138 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

Q139

Q139 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

Q140

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

A

fopen()

B

open()

C

file_open()

D

stream()

Q141

Q141 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

Q142

Q142 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

Q143

Q143 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

Q144

Q144 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

Q145

Q145 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

Q146

Q146 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

Q147

Q147 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

Q148

Q148 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

Q149

Q149 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

Q150

Q150 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

ad vertical