The use of ________ allows for dynamic memory allocation for arrays in C.
- for loop
- getchar()
- malloc()
- sizeof()
Dynamic memory allocation in C is achieved using functions like malloc().
Which standard library function in C is used to concatenate two strings?
- strcat
- strcmp
- strconcat
- strcopy
The strcat function in C is used to concatenate (append) one string to the end of another. It takes two strings as arguments and modifies the first string to include the second one at the end.
The ________ function is used to write data to a file in C.
- fprintf
- fread
- fscanf
- fwrite
In C, the fwrite function is used to write data to a file. It allows you to write binary data to a file stream.
When reading a file in C, which function can be used to check if the end of the file has been reached?
- fclose()
- feof()
- ferror()
- fseek()
The feof() function is used to check if the end of a file has been reached during file reading operations in C.
What is the primary purpose of the malloc function in C?
- To allocate memory for a single variable
- To allocate memory for an array of elements and initialize them
- To free memory allocated by calloc
- To reallocate memory for an array
The primary purpose of the malloc function in C is to allocate memory for a single variable. It returns a pointer to the allocated memory, which can be used to store data.
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.
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.
Which function is used to close a file that has been opened for reading or writing?
- closefile()
- endfile()
- fclose()
- stopfile()
In C, the fclose() function is used to close a file that has been opened for reading or writing. It is essential to close files to release system resources and ensure that data is properly saved.
A function in C returns a value to the calling function using the ________ keyword.
- output
- result
- return
- value
In C, the "return" keyword is used to return a value to the calling function. It specifies the value that the function will return.
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.
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.
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.