What is the impact of using inline functions on the size of the compiled binary?

  • It depends on the compiler
  • Larger compiled binary
  • No impact on the binary size
  • Smaller compiled binary
Inline functions tend to reduce binary size because they replace function calls with code directly inserted at the call site. This can lead to more efficient code and smaller binary sizes.

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.

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 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 happens to the memory allocation when a structure is defined?

  • Memory is allocated for all its members
  • Memory is allocated for the structure itself
  • Memory is allocated only for the first member
  • No memory allocation occurs
When you define a structure in C, memory is allocated for the structure itself, which includes memory for all its members.

In a union, all members share the same ________.

  • Data Type
  • Memory Address
  • Name
  • Value
In a union, all members share the same memory location. Unions allow different variables to occupy the same memory space, providing efficient storage.

How can using pointers to structures optimize memory usage in a C program?

  • Efficient memory allocation
  • Faster program execution
  • Improved data security
  • Reducing memory leaks
Using pointers to structures allows for more efficient memory allocation since only memory addresses are stored, reducing memory overhead. It also helps in preventing memory leaks by allowing explicit memory deallocation.

What considerations should be taken into account when using nested loops?

  • Nested loops are only used for mathematical calculations and not in other scenarios.
  • Nested loops should always have the same loop control variable.
  • Nested loops should never be used in programming.
  • The number of iterations in nested loops can grow quickly, impacting performance.
When using nested loops, it's important to consider the potential impact on performance. The number of iterations in nested loops can grow exponentially, especially if the outer loop iterates N times and the inner loop iterates M times, resulting in N * M iterations. This can lead to performance issues, so it's essential to carefully plan and optimize nested loop usage.

In C, which operator has the highest precedence?

  • Arithmetic operators
  • Assignment operators
  • Logical operators
  • Relational operators
In C, arithmetic operators have the highest precedence, meaning they are evaluated first in an expression.

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.