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!

Q61

Q61 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

Q62

Q62 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

Q63

Q63 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

Q64

Q64 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

Q65

Q65 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

Q66

Q66 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

Q67

Q67 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

Q68

Q68 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

Q69

Q69 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

Q70

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

Q71

Q71 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

Q72

Q72 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

Q73

Q73 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

Q74

Q74 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

Q75

Q75 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

Q76

Q76 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

Q77

Q77 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

Q78

Q78 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

Q79

Q79 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

Q80

Q80 Which of the following is not a keyword in C?

A

int

B

char

C

include

D

float

Q81

Q81 Which of the following is a valid identifier in C?

A

2ndName

B

_name

C

#name

D

none of these

Q82

Q82 What is the difference between 'float' and 'double' data types in C?

A

Syntax only

B

Precision

C

Usage

D

No difference

Q83

Q83 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

Q84

Q84 What does %d signify in the printf or scanf function?

A

Double data type

B

Decimal integer

C

Dynamic allocation

D

Directory path

Q85

Q85 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

Q86

Q86 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

Q87

Q87 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

Q88

Q88 What does the '==' operator check?

A

Assignment

B

Equality

C

Greater than

D

Less than

Q89

Q89 What is the result of the logical expression (1 && 0)?

A

1

B

0

C

True

D

False

Q90

Q90 What does the '+' operator do in C?

A

Addition

B

Subtraction

C

Multiplication

D

Division

ad vertical