mcq on function in C language,user defined function mcq, function with parameters mcq

Q5.What is the meaning a parameter in a function?
A. The return value of a function
B. An input value to the function
C. The name of the function
D. The output value of the function
Answer: B


Q6.What is the task or purpose of the main() in C?
A. To initialize other functions
B. To define other functions
C. To call other functions
D. To begin or start the execution of the program
Answer: D


Q7.How arguments are passed to a function in C ?
A. By reference
B. By value
C. By address
D. By pointer
Answer: B


Q8.________ keyword is used to define a function in C.
A. define
B. void
C. function
D. main
Answer: B


Q9.How do you define function without argument in C?
A. void func()
B. void func(void)
C. void func(arguments)
D. void func(int x)
Answer: B


Q10.Why return statement used in function?
A. To declare the function
B. To call the function
C. To return a value from the function
D. To define the function
Answer: C


Q11.Choose valid function declaration in C?
A. int add(int x, y)
B. int add(int x, int y)
C. add(int x, int y)
D. void add(int x, int y)
Answer: B


Q12.The scope of a variable declared inside a function is ______
A. Local to the function
B. Global
C. Static
D. Automatic
Answer: A


Q13.find the invalid function call from given option below?
A. add(5, 10)
B. add(x, y,)
C. add(a + b, c)
D. add(5)
Answer: B


Q14.The use of static keyword in C function is ________.
A. To make the function private
B. To make the function public
C. To preserve the value of a variable between function calls
D. To define the function
Answer: C


Q15.What is the difference between actual parameters and formal parameters in a function in C?
A. Formal parameters are used in the function definition, while actual parameters are used in the function call
B. Formal parameters are used in the function call, while actual parameters are used in the function definition
C. Formal parameters are used to declare the function, while actual parameters are used to define the function
D. Formal parameters are used to define the function, while actual parameters are used to declare the function
Answer: A


Q16.which one of the following is correct to define a function that returns a float value in C?
A. void func(float x)
B. float func(float x)
C. float func(int x)
D. void func(int x)
Answer: B


Q17.Trace out the output of the following program?

int square(int x) {
return x * x;
}
int main() {
int result = square(5);
printf("%d", result);
return 0;
}

A. 10
B. 25 C. 5
D. 100
Answer: B


Q18.what is the meaning of following function prototype in C ?
void docalculation(int x, int y, int* sum, int* diff);
A. The function takes two input parameters and returns two output parameters
B. The function takes two input parameters and returns an integer value
C. The function takes two input parameters and returns a floating-point value
D. The function takes two input parameters and returns a void value
Answer: A


Q19.Choose the correct way to call the above function.
void printMessage() {
printf("Hello, World!\n");
}
A. printMessage();
B. printMessage(void);
C. printMessage(Hello, World!);
D. void printMessage();
Answer: A


Q20.Find the correct output of the following program code?
int add(int x, int y) {
return x + y;
}
int main()
{
printf("%d", add(5, 10));
return 0;
}
A. 5
B. 10
C. 15
D. 50
Answer: C


Q21.the purpose of a function header in C is ______
A. To declare the function name
B. To define the function
C. To specify the return type and parameters of the function
D. To call the function
Answer: C


Q22.which one of following is correct to declare a function that takes an int parameter and returns a float value ?
A. void func(int x);
B. float func(int x);
C. int func(float x);
D. void func(float x);
Answer: B


Q23.identify the correct syntax to define a function in C language?
A. void func() {}
B. func void() {}
C. int func() {}
D. float func() {}
Answer: A


Q24.What is the use of return type in a function?
A. To specify the name of the function
B. To define the function
C. To specify the type of value returned by the function
D. To call the function
Answer: C


Q25.Find out the valid function definition in C?
A. void func();
B. int func(int x);
C. float func(float x);
D. int func(void);
Answer: D


Q26.What is the scope of a variable declared in the main() function ?
A. Local to the main() function
B. Global
C. Static
D. Automatic
Answer: A


Q27.What is the purpose of the const in a function parameter declaration ?
A. To make the parameter a constant value
B. To specify the return type of the function
C. To define the function
D. To call the function
Answer: A


Q28.Choose the correct option to declare a function that returns an int value and takes no parameters in C?
A. void func()
B. int func()
C. void func(int x)
D. int func(void)
Answer: D


Q29.What is the correct output of the following program code?
#include <stdio.h>
void printHello() {
printf("Hello");
}
int main() {
printHello();
return 0;
}
A. Hello
B. World
C. Hello World
D. 0
Answer: A


Q30.What is a function declaration in C?
A. To define the function
B. To declare the function
C. To call the function
D. To specify the return type of the function
Answer: B


Q31.What is the use or purpose of the void keyword in a function declaration in C?
A. To specify the return type of the function
B. To define the function
C. To make the function private
D. To call the function
Answer: A


Q32.Choose the valid function call in C.
A. func();
B. func(int x);
C. func(5, 10);
D. func(void);
Answer: A


Q33.Which one is correct answer to define a function that takes an integer pointer as a parameter in C?
A. void func(int* x);
B. int func(int x);
C. void func(int x);
D. int func(int* x);
Answer: A


Q34.Find out the output of the following program code?
#include <stdio.hgt;
int cube(int p) {
return p * p * p;
}
int main() {
printf("%d", cube(3));
return 0;
}
A. 3
B. 6
C. 9
D. 27
Answer: D


Q35.why return keyword used inside functions in C?
A. To define the function
B. To declare the function
C. To specify the return value of the function
D. To call the function
Answer: C


Q36.What is the correct way to declare a function that takes no parameters and returns void in C?
A. void func() {}
B. void func(void) {}
C. void func void {}
D. void func(void) {}
Answer: D


Q37.find the output of the following code snippet?
#include <stdio.hgt;
void greet(char name[]) {
printf("Hello, %s!\n", name);
}
int main() {
char name[20] = "Alice";
greet(name);
return 0;
}
A. Hello
B. Hello, Alice!
C. Hello, name!
D. 0
Answer: B



Previous Topic:-->>Arrays MCQ. || Next topic:-->>structure MCQ in C.