When you declare an array, what does the number inside the square brackets represent?
- Array's name length
- Index of the last element
- Number of elements in the array
- Total memory allocated to the array
The number inside the square brackets when declaring an array in C represents the number of elements or the size of the array. It indicates how many elements the array can hold.
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.
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.
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.
How does C handle array indices that are out of bounds?
- C dynamically resizes the array
- C ignores out-of-bounds indices
- C throws a runtime error
- C wraps around to the beginning of the array
In C, when array indices are out of bounds, the behavior is undefined. C does not perform any bounds checking, and it's the programmer's responsibility to ensure indices are within bounds to avoid unexpected results.
What will happen if the condition in a 'while' loop is initially false?
- It will enter the loop and execute it once.
- It will enter the loop and run indefinitely.
- It will result in a compile-time error.
- It won't enter the loop.
When the condition in a 'while' loop is initially false, the loop will not execute, and the program will proceed to the next statement.
The function ________ in C changes the size of the memory block pointed to by a given pointer.
- realloc()
- free()
- malloc()
- calloc()
The correct option is 'realloc()'. The realloc() function is used to change the size of a previously allocated memory block, making it suitable for resizing dynamic arrays.
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.
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 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.
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.
In C, when an array is passed to a function, is it passed by value or by reference?
- By reference
- By value
- It depends on the array size
- Not possible to pass arrays to functions
In C, arrays are passed to functions by reference, which means that changes made to the array inside the function affect the original array in the caller.