In C, the ________ function is used to write a string to a file.
- write()
- fputstring()
- fwrite()
- fputs()
The correct option is fputs(). This function is used to write a string to a file in C, providing a convenient way to output a sequence of characters to the specified file.
In C, a structure member with a specified width is known as a ________.
- Bit Field
- Conditional Statement
- Enum Member
- Pointer Variable
In C, a structure member with a specified width is known as a bit field, allowing you to optimize memory usage by using a specific number of bits.
An array name in C essentially acts as a ________ to the first element of the array.
- container
- pointer
- reference
- variable
An array name in C essentially acts as a reference to the first element of the array, making it easy to access.
To allocate memory dynamically and initialize it to a specific value, the ________ function can be used in C.
- calloc()
- free()
- malloc()
- realloc()
In C, the "calloc()" function is used to dynamically allocate memory and initialize it to a specific value. It takes two arguments for the number of elements and the size of each element, allocating memory for an array.
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.
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.
In C++, if two overloaded functions have the same signature but differ in const qualification, it leads to ________.
- Ambiguity Error
- Compilation Error
- Linker Error
- Undefined Behavior
When two overloaded functions in C++ have the same signature but differ in const qualification, it leads to undefined behavior. The compiler cannot determine which function to call, resulting in ambiguous code. It's essential to avoid such situations for code clarity and reliability.
How does the 'switch' statement compare to a series of 'if-else' statements in terms of efficiency?
- The 'switch' statement is generally more efficient when comparing a single value to multiple options.
- The 'switch' statement is less efficient than 'if-else' statements.
- The 'switch' statement and 'if-else' statements have the same efficiency.
- Efficiency depends on the specific use case.
The 'switch' statement is typically more efficient than a series of 'if-else' statements when you need to compare a single value to multiple options. It allows for jump tables, which can lead to faster execution. However, the efficiency may vary depending on the compiler and specific scenarios.
In C, which function can be used to search for a substring within a string?
- find()
- locate()
- search()
- strstr()
The strstr() function in C is used to search for a substring within a string. It returns a pointer to the first occurrence of the substring or NULL if the substring is not found.
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.
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.
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.