Study
C MCQ Questions and Answers on Functions and Pointers. Questions are on
Recursion, Pass by Value and Pass By Reference. Attend C technical interviews
easily after reading these Multiple Choice Questions.
Go
through C Theory Notes on Functions before reading
questions.
1) Choose correct statement about Functions in C
Language.
A) A
Function is a group of c statements which can be reused any number of times.
B) Every
Function has a return type.
C) Every
Function may no may not return a value.
D) All the
above.
Answer [=]
D
2) Choose a correct statement about C
Language Functions.
A) A
function name can not be same as a predefined C Keyword.
B) A
function name can start with an Underscore( _ ) or A to Z or a to z.
C) Default
return type of any function is an Integer.
D) All the
above.
Answer [=]
D
3) Choose a correct statement about C Function.?
main()
{
printf("Hello");
}
A)
"main" is the name of default must and should Function.
B) main() is
same as int main()
C) By
default, return 0 is added as the last statement of a function without specific
return type.
D) All the
above
Answer [=]
D
4) A function which calls itself is called a ___
function.
A) Self
Function
B) Auto
Function
C) Recursive
Function
D) Static
Function
Answer [=]
C
5) What is the output of C Program with Functions.?
int
main()
{
void show()
{
printf("HIDE");
}
show();
return 0;
}
A) No output
B) HIDE
C) Compiler
error
D) None of
the above
Answer [=]
B
Explanation:
Notice that show() function is
defined inside main() function. It will not produce a compile error. But, it is
not recommended to define a FUNCTION INSIDE A FUNCTION. DO NOT DO.
6) What is the output of C Program with functions.?
void
show();
int
main()
{
show();
printf("ARGENTINA ");
return 0;
}
void
show()
{
printf("AFRICA ");
}
A) ARGENTINA
AFRICA
B) AFRICA
ARGENTINA
C) ARGENTINA
D) Compiler
error
Answer [=]
B
Explanation:
First show() function is called. So
it prints AFRICA first.
7) What is the output of C Program with functions.?
int
main()
{
show();
printf("BANK ");
return 0;
}
void
show()
{
printf("CURRENCY ");
}
A) CURRENCY
BANK
B) BANK
CURRENCY
C) BANK
D) Compiler
error
Answer [=]
D
Explanation:
Yes.
Compiler error. Before calling the show(); function, its Function Prototype
should be declared before outside of main() and before main().
void
show();
int
main()
{
show();
printf("BANK ");
return 0;
}
8) How many values can a C Function return at a time.?
A) Only One
Value
B) Maximum
of two values
C) Maximum
of three values
D) Maximum
of 8 values
Answer [=]
A
Explanation:
Using a return val; statement, you
can return only one value.
9) What is the output of a C program with functions.?
void
show();
void
main()
{
show();
printf("RAINBOW ");
return;
}
void
show()
{
printf("COLOURS ");
}
A) RAINBOW
COLOURS
B) COLOURS
RAINBOW
C) COLOURS
D) Compiler
error
Answer [=]
B
Explanation:
VOID
functions should not return anything. RETURN; is returning nothing.
1. First
void main() return; nothing. Still it is valid.
2. Second void show() function is NO
RETURN statement. It is also valid.
10) What is the output of C Program.?
void
show();
void
main()
{
printf("PISTA ");
show();
}
void
show()
{
printf("CACHEW ");
return 10;
}
A) PISTA
CACHEW
B) CASHEW
PISTA
C) PISTA
CASHEW with compiler warning
D) Compiler
error
Answer [=]
C
Explanation:
void show() function should not
return anything. So return 10; is not recommended.
11) What is the output of C Program with functions.?
int
show();
void
main()
{
int a;
printf("PISTA COUNT=");
a=show();
printf("%d", a);
}
int
show()
{
return 10;
}
A) PISTA
COUNT=
B) PISTA
COUNT=0
C) PISTA
COUNT=10
D) Compiler
error
Answer [=]
C
Explanation:
int show() function returns TEN
(10). 10 is assigned to a at a=show().
12) What is the output of C Program with functions.?
void
main()
{
int a;
printf("TIGER COUNT=");
a=show();
printf("%d", a);
}
int
show()
{
return 15;
return 35;
}
A) TIGER
COUNT=15
B) TIGER
COUNT=35
C) TIGER
COUNT=0
D) Compiler
error
Answer [=]
A
Explanation:
More than one return statement will
not cause Compiler Error. But only FIRST return STATEMENT is executed. Anything
after return 15; is not reachable.
13) What are types of Functions in C Language.?
A) Library
Functions
B) User
Defined Functions
C) Both Library
and User Defined
D) None of
the above
Answer [=]
C
14) What is the output of C program with functions.?
int
show();
void
main()
{
int a;
a=show();
printf("%d", a);
}
int
show()
{
return 15.5;
return 35;
}
A) 15.5
B) 15
C) 0
D) Compiler
error
Answer [=]
B
Explanation:
It is
perfectly Okay to return a float number 15.5 as an Integer inside int show()
function. 15.5 is demoted to integer as 15 and returned.
15) What is the output of C Program.?
int
myshow(int);
void
main()
{
myshow(5);
myshow(10);
}
int
myshow(int b)
{
printf("Received %d, ", b);
}
A) Received
5, Received 10,
B) Received
10, Received 5,
C) Received
0, Received 0,
D) Compiler
error
Answer [=]
A
Explanation:
Notice the function prototype
declaration int myshow(int). If you declare wrong either Compiler warning or
error is thrown. myshow(5) passes number 5. 5 is received as variable int b.
16) What is the output of C Program with functions and
pointers.?
int myshow(int);
void
main()
{
int a=10;
myshow(a);
myshow(&a);
}
int
myshow(int b)
{
printf("Received %d, ", b);
}
A) Received
10, Received 10,
B) Received
10, Received RANDOMNumber,
C) Received
10, Received RANDOMNumber, with a compiler warning
D) Compiler
error
Answer [=]
C
Explanation:
a is 10. &a is the address of
the variable a which is a random memory location. To receive an address, int
myshow(int b) should be rewritten as int myshow(int *k).
17) What is the output of C Program with functions and
pointers.?
int
myshow(int *);
void
main()
{
int a=10;
myshow(&a);
}
int
myshow(int *k)
{
printf("Received %d, ", *k);
}
A) Received
RANDOMNumber,
B) Received
10,
C) Received
10,
D) Compiler
error
Answer [=]
C
Explanation:
It is called Passing a variable by
reference. You are passing &a instead of a. Address of a or &a is
received as int *k. Observe the function prototype declaration before main(), int
myshow(int *).
18) What is the output of C Program with functions and
pointers.?
void
myshow(int *);
void
main()
{
int a=10;
printf("%d ", a);
myshow(&a);
printf("%d", a);
}
void
myshow(int *k)
{
*k=20;
}
A) 10 10
B) 20 20
C) 10 20
D) Compiler
error
Answer [=]
C
Explanation:
You passed &a instead of a into
myshow(int) function. *k=20 changes the valued of passed variable passed by
reference.
19) What is the output of C Program with functions.?
void
myshow(int);
void
main()
{
int a=10;
printf("%d ", a);
myshow(a);
printf("%d", a);
}
void
myshow(int k)
{
k=20;
}
A) 10 10
B) 20 20
C) 10 20
D) Compiler
error
Answer [=]
A
Explanation:
You passed variable a directly by
value. myshow(a). k=20 will not actually change the variable a as variable k
and variable a are completely different. It is called Pass By Value.
20) Choose correct statements about C Language Pass By
Value.
A) Pass By
Value copies the variable value in one more memory location.
B) Pass By
Value does not use Pointers.
C) Pass By
Value protects your source or original variables from changes in outside
functions or called functions.
D) All the
above
Answer [=]
D
0 Comments