1. What does the 'printf' function do in C?
Answer:
Explanation:
The 'printf' function is used in C to print output to the console. It can format strings, numbers, and other data types.
2. Which function is used to read a formatted input in C?
Answer:
Explanation:
The 'scanf' function is used to read formatted input from the standard input (console).
3. Which header file must be included to use the 'printf' and 'scanf' functions?
Answer:
Explanation:
The 'printf' and 'scanf' functions are part of the standard input/output library in C, and they require the inclusion of the <stdio.h> header file.
4. What does the 'strcpy' function do in C?
Answer:
Explanation:
The 'strcpy' function is used to copy one string into another in C.
5. Which standard library function allocates memory dynamically in C?
Answer:
Explanation:
The 'malloc' function is used to allocate memory dynamically at runtime in C.
6. How do you compare two strings in C?
Answer:
Explanation:
The 'strcmp' function is used to compare two strings in C. It returns 0 if the strings are equal.
7. Which function is used to calculate the length of a string in C?
Answer:
Explanation:
The 'strlen' function is used to calculate the length of a string in C, excluding the null terminator.
8. What does the 'free' function do in C?
Answer:
Explanation:
The 'free' function is used to release memory that was previously allocated dynamically (e.g., using malloc or calloc).
9. Which function is used to read a line of text from a file in C?
Answer:
Explanation:
The 'fgets' function is used to read a line of text from a file or other stream in C.
10. How can you open a file in C?
Answer:
Explanation:
The 'fopen' function is used to open a file in C, returning a pointer to the file.
11. Which function is used to close a file in C?
Answer:
Explanation:
The 'fclose' function is used to close a file in C. It takes a file pointer as its argument.
12. What is the purpose of the 'qsort' function in C?
Answer:
Explanation:
The 'qsort' function is used for sorting elements in an array. It implements the quicksort algorithm.
13. Which function is used to convert a string to an integer in C?
Answer:
Explanation:
The 'atoi' function converts a string to an integer in C.
14. How is memory allocated for an array of integers in C?
Answer:
Explanation:
The 'malloc' function can be used to allocate memory dynamically for an array of integers in C, based on the required number of elements.
15. What does the 'memset' function do in C?
Answer:
Explanation:
The 'memset' function is used to fill a block of memory with a specific value in C. It is often used for initialization.
Comments
Post a Comment