1. What is a function in C?
Answer:
Explanation:
A function in C is a named block of code that performs a specific task and can be called from other parts of the program.
2. How is a function declared in C?
Answer:
Explanation:
A function in C is declared with its return type, followed by the function name and a list of parameters enclosed in parentheses.
3. What is the purpose of a return statement in a C function?
Answer:
Explanation:
The return statement in a C function is used to return a value from the function to the place where the function was called.
4. Which of the following is a correct way to define a function in C?
Answer:
Explanation:
The correct syntax to define a function in C includes the return type, function name, parameter list, and a block of code.
5. Which keyword is used to indicate that a function does not return a value in C?
Answer:
Explanation:
The 'void' keyword is used to specify that a function does not return a value.
6. What is function prototyping in C?
Answer:
Explanation:
Function prototyping in C involves declaring a function before its actual definition. This allows the function to be called before it is defined.
7. What is the output of the following C code?
int add(int a, int b) { return a + b; }
int main() {
printf("%d", add(3, 4));
return 0;
}
Answer:
Explanation:
The function 'add' adds the two integers 3 and 4 and returns their sum, which is 7.
8. Which of the following is true about the main function in C?
Answer:
Explanation:
The main function in C is the entry point of a program and must return an integer value, usually 0 for successful execution.
9. How are arguments passed to functions in C?
Answer:
Explanation:
In C, arguments are passed to functions by value, meaning a copy of the argument is made and used inside the function.
10. Can a function return multiple values in C?
Answer:
Explanation:
While a function in C cannot directly return multiple values, it can do so indirectly by using pointers or by returning a structure.
11. What are global variables in C?
Answer:
Explanation:
Global variables are declared outside of all functions and can be accessed by any function within the program.
12. What is recursion in C?
Answer:
Explanation:
Recursion in C is a technique where a function calls itself directly or indirectly, allowing for solutions to certain problems.
13. What is the scope of a local variable in C?
Answer:
Explanation:
The scope of a local variable in C is limited to the block or function where it is declared.
14. Which of the following is an example of function overloading in C?
Answer:
Explanation:
Function overloading, which is defining multiple functions with the same name but different parameters, is not possible in C.
15. How can you dynamically allocate memory for a function's local variables in C?
Answer:
Explanation:
Dynamic memory allocation in C can be done using functions like malloc(), which is useful for allocating memory during runtime.
16. What is a static function in C?
Answer:
Explanation:
A static function in C is one whose visibility is limited to the file in which it is declared, making it inaccessible from other files.
17. What is the difference between formal and actual parameters in C?
Answer:
Explanation:
Formal parameters are the variables declared in the function definition, whereas actual parameters are the values passed to the function during a function call.
18. What is a library function in C?
Answer:
Explanation:
Library functions are those provided by C's standard libraries, such as stdio.h, stdlib.h, math.h, etc.
19. Can a C function return another function?
Answer:
Explanation:
In C, a function cannot return another function directly, but it can return a pointer to a function.
20. What is the output of the following C code?
void update(int x) { x = x + 5; }
int main() {
int y = 5;
update(y);
printf("%d", y);
return 0;
}
Answer:
Explanation:
Since arguments in C are passed by value, the update function modifies a copy of y, not y itself. Therefore, the value of y remains 5.
Comments
Post a Comment
Leave Comment