To access members of a structure using a pointer to that structure, the ________ operator is used.

  • arrow
  • colon
  • dot
  • hyphen
To access members of a structure using a pointer to that structure, the arrow (->) operator is used in C.

What happens if the fopen function fails to open the specified file?

  • The program crashes
  • It returns a NULL pointer
  • It displays an error message on the console
  • It opens a default file
The correct option is b. It returns a NULL pointer. When the fopen() function fails to open the specified file, it returns a NULL pointer, indicating that the file opening was unsuccessful. Programmers can then check for this NULL value to handle errors gracefully.

What is the significance of using a pointer to a structure?

  • It allows accessing the structure's elements directly
  • It allows dynamic memory allocation and manipulation of structures
  • It saves memory compared to not using a pointer
  • It simplifies code but doesn't affect performance
Using a pointer to a structure allows direct access to its elements, enabling efficient manipulation and modification of the structure's data.

What happens to a local variable when the function in which it is defined finishes executing?

  • It becomes a global variable
  • It remains in memory
  • It's accessible from other functions
  • It's automatically freed
When a function finishes executing, the local variables defined inside it are automatically freed, and their memory is reclaimed. They do not persist after the function call.

You are writing a C program where you need to maintain a counter that persists across multiple function calls. Which type of variable would you use?

  • Automatic variable
  • Global variable
  • Local variable
  • Static variable
In this scenario, you would use a static variable to maintain a counter that persists across multiple function calls. Static variables retain their values between function calls, making them suitable for this purpose. Local variables have limited scope and are not suitable for maintaining a persistent counter. Global variables introduce unnecessary complexity and may lead to naming conflicts. Automatic variables are limited to a function's scope and are not designed for persistent storage.

In the context of C programming, what is the importance of having a base case in a recursive function?

  • It makes the program run faster
  • It prevents infinite recursion and stack overflow
  • It reduces the need for using pointers
  • It simplifies the program's overall structure
Having a base case in a recursive function is crucial to prevent infinite recursion, which can lead to a stack overflow and program termination. The base case provides a stopping condition for the recursion and ensures the function terminates properly.

How do you declare a two-dimensional array of integers with 3 rows and 4 columns?

  • int arr[12];
  • int arr[3][4];
  • int arr[4][3];
  • int arr[][];
To declare a 2D array in C with 3 rows and 4 columns, you use the syntax: int arr[3][4]; The first dimension specifies the number of rows, and the second dimension specifies the number of columns.

How can function pointers be used to implement callbacks in C?

  • Function pointers allow direct function calls
  • Function pointers are not suitable for callbacks
  • Function pointers are only used for dynamic memory allocation
  • Function pointers can be passed as arguments to other functions
Function pointers in C can be passed as arguments to other functions, allowing you to define callbacks. This is commonly used in event-driven programming and implementing libraries with customizable behavior.

In C programming, why would you use an enumeration (enum)?

  • To create multi-dimensional arrays
  • To define a set of named integer constants
  • To perform arithmetic operations
  • To store floating-point numbers
Enumerations (enums) in C are used to define a set of named integer constants, making your code more readable and self-explanatory.

A ________ variable in C is a variable that is declared within a function or a block and is only accessible within that function or block.

  • extern
  • global
  • local
  • static
A "local" variable in C is a variable that is declared within a function or a block and is only accessible within that function or block. These variables have limited scope, and their lifetime is limited to the duration of the function or block in which they are defined.

In a C program that processes large images, memory is allocated dynamically to hold pixel data. After processing, the memory is not explicitly freed before the program exits. What is the likely impact of this practice?

  • Data Corruption
  • Improved Memory Management
  • Increased Program Speed
  • Memory Leak
Failing to free dynamically allocated memory at program exit can lead to memory leaks, potentially causing the program to consume excessive resources and slow down over time.

What is the primary difference between the scope and the lifetime of a variable?

  • Scope and lifetime are the same thing in C.
  • Scope defines the data type of a variable, while lifetime determines its value.
  • Scope determines whether a variable is local or global, while lifetime indicates its data type.
  • Scope refers to the range where a variable can be accessed, while lifetime refers to how long the variable exists.
The primary difference between the scope and lifetime of a variable is that scope refers to where a variable can be accessed, while lifetime indicates how long the variable exists in memory.