The strlen function returns the length of a string, excluding the ________.
- null terminator
- first character
- whitespace characters
- special characters
The correct answer is the null terminator. The strlen function in C/C++ returns the length of a string by counting characters until it encounters the null terminator (' '). It excludes the null terminator from the count. The other options are not what strlen excludes.
The C function ________ is used to compare two strings lexicographically.
- strcmp
- strncmp
- strcompare
- strcasecmp
The correct answer is strcmp. This function compares two strings character by character and returns an integer value representing their lexicographical order. strncmp is used for comparing a specific number of characters, and the other options are not valid C functions.
You are debugging a C program and notice that the program crashes after running for a few minutes. Upon investigation, you find that a recursive function is being called multiple times. What could be the most likely cause of the crash?
- Hardware Failure
- Infinite Loop
- Memory Leak
- Stack Overflow
The most likely cause of the crash in this scenario is a stack overflow. When a recursive function is called multiple times without a proper base case or termination condition, it can fill up the call stack, causing a stack overflow and program crash.
What is the significance of using pointers in function arguments?
- It allows passing arguments by reference
- It enforces strong typing
- It reduces code readability
- It simplifies function declarations
Using pointers in function arguments allows passing arguments by reference, meaning the function can modify the original data, not just a copy. This is valuable when you want a function to modify variables from the caller's scope.
In a 'switch' statement, the ________ keyword is used to specify the code to execute if none of the cases match.
- Break
- Continue
- Default
- Exit
The correct option is (c) Default. In a 'switch' statement in C, the 'default' keyword is used to specify the code to execute if none of the cases match the provided value. It acts as a fallback option.
The function ________ is used to write data to a binary file.
- binary_write()
- fread()
- fwrite()
- write()
The correct function to write data to a binary file in C is fwrite(). It is designed to write a specified number of elements to a binary file, making it an essential function for handling binary data.
The function fopen in C opens a file and returns a pointer of type ________.
- FILE*
- char*
- double
- int
In C, the fopen function is used to open a file and returns a pointer of type FILE*, which represents the file stream.
The size of a structure in memory is determined by the ________ of its members.
- maximum
- minimum
- sum
- total
The size of a structure in memory is determined by the total size of its members. This includes the size of all individual data members within the structure.
Using the ________ keyword before a function suggests to the compiler that the function should be expanded at the point where it is called.
- Dynamic
- Inline
- Static
- Virtual
The "inline" keyword suggests to the compiler that the function should be expanded at the call site for performance optimization.
What is the significance of the SEEK_SET, SEEK_CUR, and SEEK_END constants in file handling?
- File attributes
- File permissions
- File positioning
- File type
In file handling, the SEEK_SET, SEEK_CUR, and SEEK_END constants are used to define the reference point for file positioning. SEEK_SET sets the file position from the beginning of the file, SEEK_CUR sets it relative to the current position, and SEEK_END sets it relative to the end of the file. These constants are crucial for accurate file positioning and seeking within files.