0% found this document useful (0 votes)
32 views10 pages

C Function

The document contains a series of multiple-choice questions and answers related to functions in the C programming language. Key topics include function return types, declarations, prototypes, recursion, and the use of keywords. It also covers function parameters, storage classes, and the scope of variables.

Uploaded by

Partha Gayen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views10 pages

C Function

The document contains a series of multiple-choice questions and answers related to functions in the C programming language. Key topics include function return types, declarations, prototypes, recursion, and the use of keywords. It also covers function parameters, storage classes, and the scope of variables.

Uploaded by

Partha Gayen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

1. What is the default return type of a function in C if not specified?

A) int
B) void
C) float
D) double
✅ Answer: A) int

2. A function that calls itself is known as:


A) Redundant Function
B) Inline Function
C) Recursive Function
D) Static Function
✅ Answer: C) Recursive Function

3. Which keyword is used to return a value from a function?


A) break
B) return
C) exit
D) stop
✅ Answer: B) return

4. What is the correct way to declare a function in C?


A) function int myFunc();
B) int myFunc();
C) declare int myFunc();
D) def myFunc();
✅ Answer: B) int myFunc();

5. Which of the following is not a valid storage class for functions in C?


A) auto
B) extern
C) static
D) register
✅ Answer: D) register

6. Functions must be defined:


A) Before main()
B) Inside main()
C) After main()
D) Either before or after main()
✅ Answer: D) Either before or after main()
7. What is a function prototype?
A) A function with no return type
B) Declaration of a function before its use
C) Function without parameters
D) None of the above
✅ Answer: B) Declaration of a function before its use

8. What is the output of the following code?

CopyEdit

int fun() {

return 5;

int main() {

printf("%d", fun());

return 0;

A) Error
B) 0
C) 5
D) Undefined
✅ Answer: C) 5

9. Which of the following is a user-defined function?


A) printf()
B) scanf()
C) main()
D) Any function written by the programmer
✅ Answer: D) Any function written by the programmer

10. In C, functions are:


A) Call by name
B) Call by object
C) Call by value
D) Call by reference only
✅ Answer: C) Call by value
11. Which header file is required to use the printf() function?
A) conio.h
B) stdlib.h
C) string.h
D) stdio.h
✅ Answer: D) stdio.h

12. Which function is the entry point of a C program?


A) start()
B) main()
C) first()
D) begin()
✅ Answer: B) main()

13. A function that doesn’t return any value must be declared as:
A) int
B) float
C) void
D) null
✅ Answer: C) void

14. Can a function have multiple return statements?


A) Yes
B) No
✅ Answer: A) Yes

15. Which of the following can be passed to a function?


A) Constants
B) Variables
C) Expressions
D) All of the above
✅ Answer: D) All of the above

16. Recursive functions must have:


A) A loop
B) A global variable
C) A stopping condition
D) None of the above
✅ Answer: C) A stopping condition
17. Function overloading is possible in C?
A) Yes
B) No
✅ Answer: B) No

18. What does the main() function return?


A) void
B) float
C) char
D) int
✅ Answer: D) int

19. Which keyword is used to define a function in C?


A) function
B) define
C) def
D) No special keyword
✅ Answer: D) No special keyword

20. In C, how are arrays passed to a function?


A) By value
B) By reference
C) By copy
D) By address
✅ Answer: B) By reference

21. The number of parameters passed to a function is called:


A) Function type
B) Function count
C) Function arity
D) Function prototype
✅ Answer: C) Function arity

22. Which of the following can be nested in C?


A) Functions
B) Loops
C) Both
D) None
✅ Answer: B) Loops
(Note: Functions cannot be defined inside functions in standard C.)
23. Which of the following function declarations is valid?

A) int sum(int a, int b);


B) int sum(a, b);
C) function sum(int a, int b);
D) sum(int, int);
✅ Answer: A) int sum(int a, int b);

24. Which function is used to exit from a C program?


A) stop()
B) return()
C) exit()
D) quit()
✅ Answer: C) exit()

25. What is the maximum number of return values a function can have in C?
A) 1
B) 2
C) 0
D) Unlimited
✅ Answer: A) 1
(But you can return a structure to simulate multiple values)

26. Which of the following is true about function declaration in C?


A) It tells the compiler about the function name and how to call it
B) It defines what the function does
C) It’s optional in C
D) It must be after the function definition
✅ Answer: A) It tells the compiler about the function name and how to call it

27. What will happen if a function is called without a declaration?


A) Compiler will ignore it
B) Linker error
C) Compile-time error (in modern compilers)
D) It will run successfully
✅ Answer: C) Compile-time error (in modern compilers)

28. Which of the following is not a part of function signature in C?


A) Function name
B) Number of parameters
C) Return type
D) Type of parameters
✅ Answer: C) Return type

29. In which memory area are function arguments stored?


A) Heap
B) Stack
C) Static
D) Register
✅ Answer: B) Stack

30. Which of the following is true about inline functions in C?


A) They are defined using the keyword inline
B) They are available in standard C
C) They exist only in C++
D) They are used to store function addresses
✅ Answer: C) They exist only in C++

31. What will the following function return?

CopyEdit

int test() {

int x = 5;

A) 5
B) 0
C) Garbage
D) Compilation Error
✅ Answer: D) Compilation Error (No return statement for non-void function)

32. What happens if you write return; in a function with return type int?
A) Returns 0
B) Returns garbage
C) Compile error
D) Runs successfully
✅ Answer: C) Compile error

33. A function with no return type and no arguments is written as:


A) function() void {}
B) void function()
C) function(void)
D) none of the above
✅ Answer: B) void function()

34. What is the correct syntax for calling a function with two arguments?
A) fun a b;
B) fun(a, b);
C) fun(a; b);
D) fun a, b;
✅ Answer: B) fun(a, b);

35. In which of the following cases do we not require a return statement?


A) int return type
B) void return type
C) float return type
D) char return type
✅ Answer: B) void return type

36. What happens if a return value is ignored?


A) Compile-time error
B) Runtime error
C) No issue
D) Undefined behavior
✅ Answer: C) No issue

37. Can a function be defined inside another function in C?


A) Yes
B) No
✅ Answer: B) No

38. What is the output of this code?

CopyEdit

int fun() {

int a = 10;

return a++;

}
int main() {

printf("%d", fun());

A) 10
B) 11
C) 9
D) Error
✅ Answer: A) 10

39. Which of the following functions can access a static variable declared inside another function?
A) All functions
B) Only that function
C) Any external function
D) Static variables can't be accessed
✅ Answer: B) Only that function

40. Can main() be called recursively in C?


A) No
B) Yes
✅ Answer: B) Yes

41. How many main() functions can a C program have?


A) 1
B) 2
C) Unlimited
D) Depends on compiler
✅ Answer: A) 1

42. Which of the following is the correct return type of malloc() function?
A) void
B) int*
C) void*
D) char*
✅ Answer: C) void*

43. What type of parameters does the main() function usually accept?
A) void
B) int, char**
C) char[]
D) float
✅ Answer: B) int, char**

44. In a function definition, which part is optional?


A) Parameter list
B) Function body
C) Return type
D) All of these
✅ Answer: A) Parameter list

45. How can you prevent a function from being accessed from other files?
A) Use register
B) Use auto
C) Use static
D) Use extern
✅ Answer: C) Use static

46. What is the use of void keyword in a function?


A) Makes function inline
B) No return value
C) Prevents function call
D) Allocates memory
✅ Answer: B) No return value

47. Can we return multiple values from a function in C?


A) Yes, directly
B) No
C) Yes, by using pointers or structures
D) Only in C++
✅ Answer: C) Yes, by using pointers or structures

48. What is the scope of variables declared inside a function?


A) Global
B) Block
C) Function
D) Local
✅ Answer: D) Local

49. The address of a function in C can be stored in:


A) Integer pointer
B) Void pointer
C) Function pointer
D) String
✅ Answer: C) Function pointer

50. Which of the following can not be passed to a function?


A) Array
B) Constant
C) Pointer
D) Preprocessor macro
✅ Answer: D) Preprocessor macro

You might also like