How can you determine the size of an array in C?
- By counting the number of elements
- By using the 'size' function
- Using the 'length' keyword
- Using the 'sizeof' operator
You can determine the size of an array in C by using the 'sizeof' operator. It returns the size in bytes, so dividing it by the size of one element gives you the number of elements in the array.
The ________ statement is used to skip the rest of the loop's body and continue with the next iteration.
- break
- continue
- exit
- return
In C and many other programming languages, the 'continue' statement is used to skip the current iteration and move to the next iteration within a loop. It allows you to bypass the remaining code in the loop body.
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.
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.
A ________ search works by repeatedly dividing the portion of the array that could contain the item until you've narrowed down the possible locations to just one.
- Binary
- Depth-First
- Hash
- Linear
A 'Binary' search works by repeatedly dividing the portion of the array that could contain the item until you've narrowed down the possible locations to just one. It's an efficient search algorithm for sorted arrays.
How does the 'ternary' operator (?:) work in C?
- It defines a function in C
- It performs bit-level operations
- It's used for binary arithmetic
- It's used to create a conditional expression
The 'ternary' operator in C, represented as '?:', is a shorthand way to write a simple conditional expression. It allows you to return one of two values based on a condition.
What is a key characteristic of a union in C?
- Allows multiple data types in a single memory location
- Automatically allocates memory on the stack
- Only works with integers
- Provides dynamic memory allocation
A union in C allows you to store different data types in a single memory location, and it's a crucial feature for creating composite data types.