C Programming Language MCQ Exercise 429 Jan 2025 | 4 min read 1. Which of the following is the right way to pass a pointer to the function that accepts float as an argument and returns the int?
Explanation: The correct answer is b. The syntax for declaring a pointer to the function is return_type(*pointer_name)(parameter_list). The declaration of fptr as a pointer to function accepts float as an argument, and it returns int. 2. What is the output for the following code?
Explanation: The correct answer is a. The malloc function is assigned to 15 bytes of the string, and "Hello, World!" is copied over using strcpy. The size of the memory block is converted to 25 bytes by the realloc function, allowing strcat to append a "C" to the string. After that "Hello, World! C" is printed by the printf function. 3. If file is not already present, which of the following creates a fopen function modes file and opens the file for reading and writing?
Explanation: The correct answer is d. Using w+ mode, a file can be opened for both reading and writing to file. If the file does not exist, this mode will create a new file. 4. What is the output of the below-following code?
Explanation: The correct answer is c. All members of the union are united in memory because they share a common place of memory. The information in the shared memory address will be modified when a value is assigned to the member, which affects the value of other members 5. How to dynamically allocate memory for an array of 10 integers in C?
Explanation: The correct answer is b. To allocate the memory dynamically, malloc function is used in C. The total number of bytes to be allocated must be passed as an argument to malloc. 6. What does the code that follows below result in ?
Explanation: The correct answer is a. The factorial of 5 is 120. 7. What does the code that follows below result in ?
Explanation: The correct answer is a. The macro 'SQUARE(x)' is defined as '(x * x)'. When 'SQUARE(a + 1)' is expanded, it becomes '(a + 1 * a + 1)' because a is 3 here which is evaluated as ((3+1) * (3+1)). Therefore, the answer is 16. 8. Which keyword from the following option will indicate to the compiler that it would be better to use code for the function instead of a function call to reduce the overhead of the function call?
Explanation: The correct answer is c. The inline keyword will tell the compiler to replace a function call with the actual code of the function to reduce the function call overhead. 9. What does the code that follows below result in ?
Explanation: The correct answer is a. The & operator is used for bitwise AND operation. 4 is equal to 0100 and 9 is equal to 1001 in binary format. Next TopicC-programming-language-mcq-exercise-5 |
1. Which of the following statements about Bubble Sort is false? It can be executed using nested loops. An additional temporary variable is needed to swap the elements in an array. It can not be optimized to terminate the swapping early. It can sort an array of any data type. Show...
2 min read
1. In the recursive Fibonacci approach, what is a frequent optimization technique to avoid redundant calculations? Multiprocessing File I/O Memoization Iteration Show Answer Workspace Explanation: The correct answer is option "c". Memorization is a common optimization method used to avoid redundant calculations in the recursive Fibonacci technique. Reusing the results of expensive function...
3 min read
1. Which of the following statements accurately describes "Call by Value" in C? It allows the function to modify the original variables passed as arguments. It passes the addresses of the actual parameters to the function. Changes made to the parameters inside the function reflect in the original variables. It...
4 min read
1. What advantage does "Call by Reference" offer over "Call by Value" in C? Simplicity in implementation Avoidance of memory leaks Avoidance of unnecessary data copying Better compatibility with recursive functions Show Answer Workspace Explanation: The correct answer is option (c). The "Call by Reference" in C offers the advantage of avoiding...
4 min read
Two-dimensional array in C MCQ Exercise-4 1. In a 2D array of integers in C, what is the default value of an uninitialized element? Undefined -1 0 1 Show Answer Workspace Explanation: The correct answer is option "a". An uninitialized element in a 2D array of integers in C has an undefined default...
3 min read
1. When the C gets function is used, which of the following can cause problems? Read-only information from files. The input string is not null-terminated. Causes buffer overflow vulnerabilities. Can only read a predetermined number of characters. Show Answer Workspace Explanation: Option c is the correct answer. It can cause buffer overflow...
3 min read
1. How can you free or delete the allocated memory for a 2D array in C programming? free(matrix); free(matrix[0]); for(int i=0; i<rows; i++) free(matrix[i]); free(matrix); for(int i=0; i<cols; i++) free(matrix[i]); free(matrix); Show Answer Workspace Explanation: The...
2 min read
1. What is the output of the following C code? #include <stdio.h> int main() { int num = 5, term1 = 0, term2 = 1, _Term; printf("Fibonacci Series: %d, %d, ", term1, term2); for (int i =...
4 min read
1. How many elements contain a 2D array, such as int mat[4][3]? 7 12 10 6 Show Answer Workspace Explanation: The correct answer is option (b). Here, the mat[4][3] array will have 4 rows and 3 columns, which sum up to 12 elements. 2. Apart from...
2 min read
1. Which of the following option describes Bubble Sort's comparison strategy? Compare and swap adjacent elements if needed. Compare and swap non-adjacent elements. Compare and swap with a pivot element. Compare with a mid-point element. Show AnswerWorkspace Explanation: The correct answer is option (a). When two adjacent elements are not in the correct...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India