When using pointers to structures, the ________ operator is used to access the members of the structure.
- Arrow (->)
- Asterisk (*)
- Comma (,)
- Period (.)
Pointers to structures are used with the arrow operator (->) to access structure members. The arrow operator is used to dereference the pointer and access the member directly.
How does C++ resolve calls to overloaded functions?
- Overloaded function resolution is based on the function name
- Overloaded function resolution is based on the number and types of parameters
- Overloaded function resolution is based on the return type
- Overloaded function resolution is random
In C++, when there are multiple overloaded functions with the same name, the compiler resolves the calls based on the number and types of parameters provided in the function call. This process is known as function overloading, and it allows C++ to choose the most appropriate function to call based on the arguments provided.
You're working on an application that processes large datasets. Why might you choose to use pointers to arrays instead of traditional arrays?
- Pointers to arrays allow for dynamic memory allocation, which is essential when the dataset size is unknown or can change.
- Pointers to arrays enable safer data access, reducing the risk of buffer overflows.
- Pointers to arrays provide better performance due to reduced memory overhead.
- Pointers to arrays simplify memory management by automatically releasing memory when no longer needed.
When dealing with large datasets, it is often more practical to use pointers to arrays to allocate memory dynamically, especially when the dataset size is not known in advance. This ensures efficient memory usage. Traditional arrays have a fixed size, which may not be suitable for large datasets.
What is the advantage of using function pointers in C for implementing callback functions?
- Allows dynamic callback selection
- Enhances code modularity
- Reduces code redundancy
- Simplifies debugging
Function Pointers allow dynamic selection of callback functions in C, which is useful in scenarios where you need to change callbacks at runtime without modifying the main code. It reduces code redundancy and enhances code modularity, but it might make debugging more challenging due to indirection.
What is the effect of not specifying the size of the array when initializing it with a list of values?
- Compilation error
- The array is initialized with a default size of 10
- The array size is automatically set based on the number of values
- Undefined behavior
When initializing an array with a list of values in C without specifying the size, the array size is automatically set based on the number of values. It is a convenient feature in C known as array initialization without a size specification.
The function ________ is used to read formatted input from the standard input.
- scanf
- printf
- cout
The "scanf" function is used in C and C++ to read formatted input from the standard input (usually the keyboard). It allows you to input and store values in variables while specifying the format in which data should be entered. Options like "print," "printf," and "cout" are used for output, not input.
String literals in C are stored in ________ memory segment.
- Code
- Data
- Heap
- Stack
In C, string literals are stored in the data memory segment. This segment contains constants, such as global and static variables.
The function ________ can be used to determine the size of a file in C.
- size()
- filesize()
- file_size()
- fsize()
The correct option is fsize(). The fsize() function is commonly used in C to determine the size of a file by positioning the file pointer at the end and then retrieving the position.
The function ________ is used in C to allocate memory for an array of specified size dynamically.
- free
- malloc
- printf
- scanf
In C, the function 'malloc' is used to allocate memory for an array of specified size dynamically. 'malloc' stands for memory allocation.
What is the default value of elements in an array declared as int arr[5]; in C?
- 0
- 5
- Random integers
- Undefined
In C, when you declare an array without initializing it, all its elements are set to 0 by default. Hence, the correct answer is 0.