Questions: C Programming
Back to Topics List

C Programming Questions

Page 3 of 3 (Displaying Questions 201 – 249 of 249 Total)

201. When should a global variable be declared as `static`?

Show Answer

It should be declared as `static` when you want to restrict its visibility and access only to the functions within the same source file, preventing naming conflicts.

Added: Nov 30, 2025

202. What are the two main types of arrays in terms of memory layout?

Show Answer

Single-dimensional (linear) arrays and Multi-dimensional arrays (often implemented as an array of arrays in row-major order).

Added: Nov 30, 2025

203. What is the role of the `time_t` data type?

Show Answer

It is a data type used to represent time, typically as an integer count of seconds.

Added: Nov 30, 2025

204. What is a "fencepost error" in loop programming?

Show Answer

A fencepost error (or off-by-one error) occurs when a loop iterates one time too many or one time too few, often caused by confusion between 0-based indexing and the count of elements.

Added: Nov 30, 2025

205. What is the purpose of the `L` suffix on an integer constant (e.g., `100L`)?

Show Answer

It forces the integer constant to be treated as a `long int`.

Added: Nov 30, 2025

206. What is the purpose of the `U` suffix on an integer constant (e.g., `100U`)?

Show Answer

It forces the integer constant to be treated as an `unsigned int`.

Added: Nov 30, 2025

207. What is the purpose of the `fgetpos()` and `fsetpos()` functions?

Show Answer

They are used to record the current position in a file stream and restore the position later, respectively, using the `fpos_t` type.

Added: Nov 30, 2025

208. What is the difference between `printf()` and `fprintf()`?

Show Answer

`printf()` writes formatted output to the standard output stream (`stdout`). `fprintf()` writes formatted output to a specified file stream.

Added: Nov 30, 2025

209. What is the minimum number of characters a `char` variable can hold?

Show Answer

The C standard guarantees that a `char` can hold at least the values from -127 to 127 (or 0 to 255 if unsigned). Its size is 1 byte.

Added: Nov 30, 2025

210. What is the purpose of the `vprintf()` function and its variants?

Show Answer

They are used to print formatted output using a `va_list` argument, typically implemented in variadic functions like wrappers for `printf`.

Added: Nov 30, 2025

211. How can you read a single character without waiting for the Enter key (non-canonical mode)?

Show Answer

This requires platform-specific system calls (like `getch()` or `getche()` in `conio.h` on some systems, or using termios on Unix/Linux) as it is not part of the standard C library.

Added: Nov 30, 2025

212. What is the advantage of using a `switch` statement over an `if-else if` ladder?

Show Answer

A `switch` statement is often more readable and, in some cases, can be optimized by the compiler to execute faster than a long `if-else if` ladder.

Added: Nov 30, 2025

213. When should a C programmer use the `const` keyword?

Show Answer

Use `const` for variables whose value should not change after initialization, to improve code readability, allow the compiler to optimize, and prevent accidental modification.

Added: Nov 30, 2025

214. What is an indeterminate value in C?

Show Answer

An indeterminate value is a value stored in a variable that has not been initialized. It could be any value, sometimes referred to as garbage.

Added: Nov 30, 2025

215. What is the concept of `scope` in terms of C identifiers?

Show Answer

Scope determines the region of the program code where an identifier (variable, function, etc.) is visible and can be accessed.

Added: Nov 30, 2025

216. What is a "comma operator" (`,`) and what is its result?

Show Answer

The comma operator evaluates its operands from left to right and the result of the entire expression is the value of the rightmost operand.

Added: Nov 30, 2025

217. What is the primary difference between a `union` and a `struct` in initialization?

Show Answer

Only the **first member** of a `union` can be initialized in its declaration. All members of a `struct` can be initialized.

Added: Nov 30, 2025

218. What is the maximum size of a C program?

Show Answer

The size of a C program is limited only by the available memory and the architecture of the operating system and processor (e.g., 32-bit vs 64-bit address space).

Added: Nov 30, 2025

219. How does the `calloc()` function initialize the allocated memory?

Show Answer

`calloc()` initializes all bytes of the allocated memory to zero.

Added: Nov 30, 2025

220. What is the advantage of using function pointers?

Show Answer

They allow for dynamic function calling (runtime selection), implementing callbacks, and creating dispatch tables/v-tables (polymorphism).

Added: Nov 30, 2025

221. What is the role of the `void` return type in a function?

Show Answer

It signifies that the function does not return any value to the calling function.

Added: Nov 30, 2025

222. What is the C standard library function used for string concatenation?

Show Answer

The `strcat()` function (String Concatenation) is used to append one string to the end of another.

Added: Nov 30, 2025

223. What is the C standard library function used for string comparison?

Show Answer

The `strcmp()` function (String Compare) is used to compare two strings lexicographically.

Added: Nov 30, 2025

224. What is the difference between `NULL` and a dangling pointer?

Show Answer

`NULL` is a pointer that explicitly points to no memory location. A dangling pointer points to a memory location that *was* valid but has since been deallocated (freed).

Added: Nov 30, 2025

225. What is the purpose of the `clock()` function?

Show Answer

The `clock()` function returns the approximate processor time consumed by the program since it was started.

Added: Nov 30, 2025

226. What is a side effect in C programming?

Show Answer

A side effect is any action a function or expression takes that alters the state of the program other than its main return value (e.g., modifying a global variable, performing I/O).

Added: Nov 30, 2025

227. What is the C standard library function for finding the length of a string?

Show Answer

The `strlen()` function (String Length).

Added: Nov 30, 2025

228. What is the primary difference between a `char` and an `int` type?

Show Answer

A `char` is intended to hold a single byte (character value), while an `int` is intended to hold a standard integer value (typically 4 bytes).

Added: Nov 30, 2025

229. What is the definition of **Little-Endian**?

Show Answer

Little-Endian is a byte order where the least significant byte of a data word is stored at the lowest memory address.

Added: Nov 30, 2025

230. What is the definition of **Big-Endian**?

Show Answer

Big-Endian is a byte order where the most significant byte of a data word is stored at the lowest memory address.

Added: Nov 30, 2025

231. What is the primary benefit of using bitwise operators for setting/clearing flags?

Show Answer

It is highly efficient and memory-friendly, allowing multiple boolean states to be stored in a single integer variable.

Added: Nov 30, 2025

232. What is the purpose of the `time()` function?

Show Answer

The `time()` function returns the current calendar time of the system as a value of type `time_t`.

Added: Nov 30, 2025

233. What is the use of the format specifier `%n` in `printf()`?

Show Answer

The `%n` specifier stores the number of characters successfully written to the stream up to that point into the associated integer pointer argument.

Added: Nov 30, 2025

234. What is the function of the `tmpfile()` function?

Show Answer

The `tmpfile()` function creates a temporary binary file that is automatically deleted when the file is closed or the program terminates.

Added: Nov 30, 2025

235. What is the minimum number of times a `for` loop is guaranteed to execute?

Show Answer

Zero times, if the test condition is false initially.

Added: Nov 30, 2025

236. What is the primary difference between the binary file mode "w" and "a"?

Show Answer

"w" (write) overwrites the entire file if it exists. "a" (append) adds new content to the end of the file, preserving existing content.

Added: Nov 30, 2025

237. What is a self-referential structure?

Show Answer

A structure that contains a pointer to itself as one of its members, commonly used to build data structures like linked lists and trees.

Added: Nov 30, 2025

238. How do you check if a character is a digit in C?

Show Answer

By using the `isdigit()` function from the `<ctype.h>` header file.

Added: Nov 30, 2025

239. How do you convert a string to an integer in C?

Show Answer

By using the `atoi()` function (ASCII to Integer) from the `<stdlib.h>` header file.

Added: Nov 30, 2025

240. What is the purpose of the `signal()` function?

Show Answer

The `signal()` function is used to specify how a program should handle specific operating system signals (like an interrupt or termination request).

Added: Nov 30, 2025

241. What is a temporary variable?

Show Answer

A temporary variable is a local variable used for short-term storage within a small scope, often within a loop or for holding an intermediate calculation result.

Added: Nov 30, 2025

242. What is the concept of "Pass by Pointer" in C?

Show Answer

It is another term for Call by Reference, where the memory address of a variable is passed to a function, allowing the function to modify the original variable.

Added: Nov 30, 2025

243. What is the standard header file for general utilities, memory allocation, and conversion functions?

Show Answer

The `<stdlib.h>` header file (Standard Library).

Added: Nov 30, 2025

244. What is the effect of using the `static` keyword on a variable inside a function?

Show Answer

It retains the variable's value between multiple function calls, and the variable is initialized only once.

Added: Nov 30, 2025

245. What is the primary danger of array indexing beyond its boundaries?

Show Answer

It leads to **undefined behavior**, typically corrupting other data in memory or causing a program crash (buffer overflow).

Added: Nov 30, 2025

246. How is a constant created using the preprocessor?

Show Answer

By using the `#define` directive (e.g., `#define PI 3.14159`).

Added: Nov 30, 2025

247. What is the difference between `long int` and `long long int`?

Show Answer

`long long int` (C99) is guaranteed to be at least 64 bits wide, whereas `long int` is guaranteed to be at least 32 bits wide.

Added: Nov 30, 2025

248. What is the effect of the `const` keyword on a function's parameter?

Show Answer

It prevents the function from modifying the value of that parameter inside its body.

Added: Nov 30, 2025

249. What is the purpose of the `ctime()` function in `<time.h>`?

Show Answer

It converts a calendar time value (`time_t`) into a human-readable string representing the local time.

Added: Nov 30, 2025