The ________ keyword in C is used to give a reference to a variable that is already defined in some other scope.
- auto
- extern
- register
- static
In C, the extern keyword is used to give a reference to a variable that is already defined in some other scope. It is often used to access global variables that are defined outside the current function or block. This keyword allows you to use variables across different scopes.
You are developing an interactive application that continuously accepts user input until the user decides to exit. Which loop construct would be most appropriate for this scenario?
- do-while loop
- for loop
- switch statement
- while loop
The most appropriate loop construct for an interactive application that accepts user input until the user decides to exit is a 'while loop.' It allows continuous input acceptance while checking an exit condition.
Function pointers in C can be stored in an array, creating a(n) ________ of function pointers.
- Array of Function Pointers
- Collection
- Group
- List
Function pointers in C can be stored in an array, creating an array of function pointers, which can be used for dynamic function calls.
What is the primary cause of memory leaks in a C program?
- Excessive memory fragmentation.
- Failure to free dynamically allocated memory.
- Incorrect use of the malloc function.
- Insufficient memory allocation.
The primary cause of memory leaks in a C program is the failure to free dynamically allocated memory using functions like free(). When you allocate memory but don't deallocate it properly, it leads to memory leaks.
What is the scope of a global variable in a C program?
- Accessible throughout the entire program
- Limited to the file where it's declared
- Local to the function it's defined in
- Only within the main() function
In C, global variables have a scope that spans the entire program, meaning they can be accessed from any part of the code.
When a string is declared as a character array, the string must be terminated with a ________.
- comma
- null character
- semicolon
- space
In C, a string is a sequence of characters terminated by a null character (' '). This null character signifies the end of the string.
What is the result of comparing two strings using the '==' operator in C?
- It compares the ASCII values of the first characters
- It compares the content of the strings
- It compares the length of the strings
- It compares the memory addresses of the strings
In C, the '==' operator compares the memory addresses of the strings, not their content.
In a program that processes large amounts of data, what strategy can be used to optimize the performance of loops?
- Loop branching optimization
- Loop indexing optimization
- Loop parallelization
- Loop unrolling
To optimize the performance of loops when processing large data, 'loop unrolling' can be used. Loop unrolling reduces loop overhead and can improve data processing speed.
The fread function in C is used to read data from a file and stores the data in the ________.
- Buffer
- Memory
- Stack
- Registers
The fread function in C reads data from a file and stores it in memory, making option b) "Memory" the correct answer.
In C, the ________ function is used to copy a specified number of characters from one string to another.
- memcpy()
- strcpy()
- strncat()
- strncpy()
In C, the strncpy() function is used to copy a specified number of characters from one string to another. Unlike strcpy(), it allows you to specify the maximum number of characters to copy, which helps prevent buffer overflows and enhances program security.