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.
The ________ function is used to move the file pointer to a specified position in a file.
- moveptr()
- fseek()
- setposition()
- positionfile()
The correct option is b) fseek(). This function in C is used to move the file pointer to a specified position in the file. It takes the file pointer, offset, and origin as arguments.
The function ________ is used to copy one string to another in C.
- compare()
- length()
- strcpy()
- swap()
In C, the function strcpy() is used to copy one string to another. It takes two string arguments and copies the contents of the source string to the destination string until it encounters a null character.
Which sorting algorithm is most efficient when dealing with small datasets or partially sorted data?
- Bubble Sort
- Insertion Sort
- Merge Sort
- Quick Sort
Insertion Sort is efficient for small datasets and partially sorted data due to its simplicity and low overhead.
Which operator is used to access the value stored at the address specified by a pointer?
- &
- *
- ->
- .
The '*' operator in C is used to access the value stored at the address specified by a pointer. It is also known as the dereference operator. The '&' operator is used to get the address of a variable, not the value.
The data type ________ is used in C to store a single character.
- char
- character
- double
- int
In C, the 'char' data type is used to store a single character. It can hold a single character, such as a letter or a symbol, within single quotes.
How are the members of a structure accessed in C?
- By using the arrow (->) operator
- By using the dollar sign ($)
- By using the dot (.) operator
- By using the exclamation mark (!)
In C, structure members are accessed using the dot (.) operator. This allows you to access the individual fields within a structure.
You are debugging a C program and notice that a variable intended to store large numbers is not holding the values correctly. What might be the issue with the data type used?
- The issue might be with using an int data type.
- The issue might be with using a float data type.
- The issue might be with using a double data type.
- The issue might be with using a short data type.
The correct option is 3. When dealing with large numbers, it's more appropriate to use a double data type because it provides greater precision compared to int and float, which may result in loss of precision for large numbers. short data type is typically used for smaller integers.