When using dynamic memory allocation for arrays, which standard library function is used to release the memory that was previously reserved?
- calloc
- free
- malloc
- realloc
The correct function to release dynamically allocated memory is free. It is used to deallocate the memory previously reserved using malloc or calloc.
The function ________ is used to find the first occurrence of a character in a string in C.
- findchar
- locatechar
- strchr
- searchchar
The correct answer is strchr. strchr is a standard C function used to find the first occurrence of a character in a string. The other options are not valid C functions for this purpose.
What is the standard notation for passing command line arguments in a C program?
- int main(String[] args)
- int main(int argc, char *argv[])
- main(int argc, char *argv[])
- void main(args)
The standard notation for passing command line arguments in a C program is 'int main(int argc, char *argv[])'. 'argc' holds the number of arguments, and 'argv' is an array of argument values.
The ________ statement is used to exit a loop prematurely.
- break
- continue
- return
- switch
In programming, the "break" statement is used to exit a loop prematurely. It is often used in loops such as "for" and "while" to terminate the loop based on a specific condition. The "break" statement is not used to return from a function, control a switch statement, or skip the current iteration of a loop, so it is the correct option.
When declaring a pointer in C, which symbol is used to denote that a variable is a pointer?
- #
- $
- &
- *
In C, the asterisk (*) symbol is used to declare a pointer variable. For example, int *ptr declares a pointer to an integer.
When you increment a pointer in C, it advances the pointer by the size of the type to which it points, which is known as ________.
- Looping
- Memory allocation
- Pointer arithmetic
- Typecasting
When you increment a pointer in C, it advances the pointer by the size of the type to which it points, and this operation is known as pointer arithmetic. It allows you to navigate through data structures in memory.
What is the significance of using pointers when working with structures in C?
- Pointers allow dynamic memory allocation.
- Pointers enable structures to be passed to functions efficiently.
- Pointers prevent data corruption in structures.
- Pointers simplify access to structure members.
Using pointers when working with structures in C is essential because they enable efficient access to structure members when they are passed to functions. This allows you to manipulate data inside structures without having to create copies of the entire structure.
How can a structure be passed to a function in C?
- By creating a copy inside the function
- By reference
- By using global variables
- By value
A structure can be passed to a function in C by reference (using a pointer or passing the address of the structure). This allows the function to modify the original structure's contents.
What is a pointer in C programming?
- A control structure in C
- A data type used for characters
- A function that returns values
- A variable that stores addresses
A pointer in C is a variable that stores the memory address of another variable. It's often used for dynamic memory allocation and accessing data indirectly.
What is the role of the 'continue' statement in a loop?
- It exits the program.
- It restarts the loop from the beginning.
- It skips the current iteration and continues with the next.
- It terminates the loop.
The 'continue' statement is used in loops to skip the current iteration and move to the next iteration. It does not terminate the loop but helps to skip certain iterations.