Q121
Q121 How do you access a member of a structure using a structure pointer in C?
With the dot operator (.)
With the arrow operator (->)
With the ampersand (&)
With the asterisk (*)
Q122
Q122 What is the key difference between a structure and a union in C?
A structure can store multiple data types, a union cannot
A union can store multiple data types, a structure cannot
In a structure, only one member can be accessed at a time
In a union, only one member can be accessed at a time
Q123
Q123 What is an enumerated data type in C?
A data type that allows numeric values only
A data type for storing lists of named constants
A special kind of array
A structure that can hold any data type
Q124
Q124 How can you instantiate a structure in C?
By using the new keyword
By declaring a variable of the structure type
By defining the structure with #define
By calling a function that returns a structure
Q125
Q125 How are bit fields used in a structure in C?
To define the number of bits used by an integer type member
To encrypt data
To align data in memory
To define array sizes
Q126
Q126 What happens when a structure is passed to a function in C?
The entire structure is copied
Only the structure pointer is passed
The first element is passed
None of the above
Q127
Q127 What does the following C code do?
struct Point {
int x, y;
};
struct Point p1 = {1, 2};
printf("%d %d", p1.x, p1.y);
Declares a structure and prints its members
Causes a syntax error
Initializes a structure but fails to print
None of the above
Q128
Q128 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".
data.str = "Hello";
strcpy(data.str, "Hello");
data = {.str = "Hello"};
data.str = {'H', 'e', 'l', 'l', 'o', '\0'};
Q129
Q129 Identify the error in this C code:
struct Point { int x, y; };
struct Point p1; p1.x = 10; p1.y = 20;
No error
Struct Point not properly declared
Struct members not properly accessed
Struct Point not properly instantiated
Q130
Q130 Spot the mistake:
struct Data { int val; }; int main() {
struct Data *ptr;
ptr->val = 100;
printf("%d", ptr->val);
return 0;
}
Uninitialized pointer used
Syntax error
No error
Wrong printf format
Q131
Q131 What is a stream in the context of C programming?
A sequence of characters
A type of data structure
A flow of binary data
A method of structuring code
Q132
Q132 What function in C is typically used to open a file for reading or writing?
fopen()
open()
file_open()
stream()
Q133
Q133 How does file handling in binary mode differ from text mode in C?
Binary mode can read non-text files, text mode cannot
Binary mode is faster
Text mode translates newlines, binary mode does not
Text mode is more secure
Q134
Q134 What is the purpose of the feof function in C?
To check if the end-of-file has been reached
To open a file
To read a file character by character
To write to a file
Q135
Q135 What happens if you try to write to a file in C without opening it first?
The write operation succeeds with a warning
The write operation fails silently
An error occurs
The file is automatically created
Q136
Q136 Complete the C code to read a binary file:
FILE *file = fopen("example.bin", "rb"); ___; fclose(file);
fread(buffer, sizeof(buffer), 1, file);
read(file, buffer, sizeof(buffer));
file >> buffer;
getline(file, buffer);
Q137
Q137 Identify the error in this C code for file writing:
FILE *file = fopen("example.txt", "w"); fprintf(file, "Hello World"); fclose(file);
Missing file mode in fopen
Incorrect usage of fprintf
No error
File not closed properly
Q138
Q138 Spot the mistake:
FILE *file = fopen("example.bin", "wb"); fwrite(&data, sizeof(data), 1, file); fclose(file);
Data should not be passed by reference in fwrite
fwrite arguments are in the wrong order
No error
File not opened in binary mode
Q139
Q139 What is the purpose of the #include directive in C?
To include a library during program execution
To declare a variable
To include a header file at compile time
To initialize variables
Q140
Q140 What is the function of the #define directive in C?
To define a new function
To import a library
To define a macro or constant
To declare a variable
Q141
Q141 How does the #ifndef directive function in C?
It checks if a variable is not defined
It imports a file if not previously imported
It checks if a macro is not defined
It defines a new macro if a condition is met
Q142
Q142 What is the result of using the #undef directive in C?
It deletes a file from the project
It removes a defined macro
It undefines a variable
It causes a compilation error
Q143
Q143 What happens when a header file is included twice in a C program without using include guards?
The program will not compile
The program compiles with warnings
The program compiles successfully, but it may cause errors
Nothing specific
Q144
Q144 Identify the error in this C code snippet:
#include <stdio.h> #define MAX 100 #undef MAX int main() { printf("%d", MAX); return 0; }
Syntax error
Use of undefined MAX
No error
Incorrect usage of printf
Q145
Q145 Spot the mistake:
#ifndef FILE_H #define FILE_H /* File contents */ #endif in a header file named "file.h"
The macro name should match the file name
No error
The header file name should be uppercase
The #ifndef and #define order is incorrect
Q146
Q146 How are command line arguments passed to a C program?
Through global variables
Through function parameters
Through a dedicated command-line function
Through environment variables
Q147
Q147 What is the purpose of argc in a C program?
To count the number of functions
To store environment variables
To count the number of command line arguments
To store error codes
Q148
Q148 What is variable argument list in C, and which header file is required for it?
A list of arguments of variable types, stdlib.h required
A list of arguments of fixed types, stdio.h required
A list of arguments of variable length, stdarg.h required
A list of arguments of variable length, string.h required
Q149
Q149 How can you access the individual command line arguments in a C program?
Using a for loop with argc and argv
Through global variables
By indexing into a predefined array
By calling a special function
Q150
Q150 What is the use of the va_start, va_arg, and va_end macros in C?
They are used for file operations
They are used for memory allocation
They are used for handling variable arguments
They are used for error handling