When you declare an array, what does the number inside the square brackets represent?
- Array's name length
- Index of the last element
- Number of elements in the array
- Total memory allocated to the array
The number inside the square brackets when declaring an array in C represents the number of elements or the size of the array. It indicates how many elements the array can hold.
What is the significance of using pointers to functions in C?
- Faster execution
- Improved code reusability and flexibility
- No significance
- Safer code
Pointers to functions in C allow for dynamic function calls and can lead to improved code reusability and flexibility.
A pointer in C holds the ________ of a variable.
- data value
- memory address
- size
- variable name
A pointer in C holds the memory address of a variable. It points to the location in memory where the variable's value is stored.
Which statement is true regarding the difference between inline functions and macros in C?
- Inline functions are always faster
- Inline functions can access local variables
- Macros are always inlined
- Macros are type-safe
Inline functions in C can access local variables and provide better type safety compared to macros. Macros are simple text replacements, which may lead to unexpected behavior.
In an application that writes user data to a text file, what precaution should be taken to avoid data corruption or loss?
- Delay disk writes to optimize performance.
- Ensure the application flushes the buffer after each write.
- Overwrite existing data without checking for errors.
- Use a non-atomic write operation.
To avoid data corruption or loss, it's crucial to flush the buffer after each write operation to ensure data is written to the file immediately.
What is the term used to describe the number of indices needed to select an element in a multidimensional array?
- Array Depth
- Dimensionality
- Index Complexity
- Selection Rank
The term used to describe the number of indices needed to select an element in a multidimensional array is dimensionality. In a multidimensional array, each dimension requires a separate index to access an element.
The function ________ in C changes the size of the memory block pointed to by a given pointer.
- realloc()
- free()
- malloc()
- calloc()
The correct option is 'realloc()'. The realloc() function is used to change the size of a previously allocated memory block, making it suitable for resizing dynamic arrays.
You're writing a program that needs to efficiently calculate the power of 2 for a given exponent. Which operator would be most efficient to use?
- * (Multiplication)
- ** (Exponentiation)
- << (Left Shift)
- ^ (Bitwise XOR)
The correct answer is C) ** (Exponentiation). To efficiently calculate the power of 2 for a given exponent, you should use the exponentiation operator (**).
What will happen if the condition in a 'while' loop is initially false?
- It will enter the loop and execute it once.
- It will enter the loop and run indefinitely.
- It will result in a compile-time error.
- It won't enter the loop.
When the condition in a 'while' loop is initially false, the loop will not execute, and the program will proceed to the next statement.
How does C handle array indices that are out of bounds?
- C dynamically resizes the array
- C ignores out-of-bounds indices
- C throws a runtime error
- C wraps around to the beginning of the array
In C, when array indices are out of bounds, the behavior is undefined. C does not perform any bounds checking, and it's the programmer's responsibility to ensure indices are within bounds to avoid unexpected results.