C++ programming questions focuses on “Function Declarations”. One shall practice these questions to improve their C++ programming skills needed for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ programming questions come with the detailed explanation of the answers which helps in better understanding of C++ concepts.
C++ programming questions on “Function Declarations” along with answers, explanations and/or solutions:
Q 1. Where does the execution of the program starts?
A. user-defined function
B. void function
C. main function
D. else function
Show Answer
Answer:-C. main functionExplanation
Normally the execution of the program in c++ starts from main only.Q 2. What are mandatory parts in the function declaration?
A. return type, function name, parameters
B. return type, function name
C. parameters, function name
D. parameters, variables
Show Answer
Answer:-B. return type, function nameExplanation
In a function, return type and function name are mandatory all else are just used as a choice.Q 3. which of the following is used to terminate the function declaration?
A. :
B. )
C. ;
D. ]
Show Answer
Answer:-C. ;Explanation
; semicolon is used to terminate a function declaration statement in C++.Q 4. How many can max number of arguments present in function in the c99 compiler?
A. 99
B. 90
C. 102
D. 127
Show Answer
Answer:-D. 127Explanation
C99 allows to pass a maximum of 127 arguments in a function.Q 5. Which is more effective while calling the functions?
A. call by value
B. call by object
C. call by pointer
D. call by reference
Show Answer
Answer:-D. call by referenceExplanation
In the call by reference, it will just passes the reference of the memory addresses of passed values rather than copying the value to new memories which reduces the overall time and memory use.Q 6. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void mani()
void mani()
{
cout<<“hai”;
}
int main()
{
mani();
return 0;
}
A. runtime
B. time
C. compile time error
D. runtime error
Show Answer
Answer:-C. compile time errorExplanation
We have to use the semicolon to declare the function in line 3. This is called a function declaration and a function declaration ends with a semicolon.Q 7. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void fun(int x, int y)
{
x = 20;
y = 10;
}
int main()
{
int x = 10;
fun(x, x);
cout << x;
return 0;
}
A. 10
B. 20
C. compile time error
D. 30
Show Answer
Answer:-A. 10Explanation
In this program, we called by value so the value will not be changed, So the output is 10 Output: $ g++ fun.cpp $ a.out 10Q 8. What is the scope of the variable declared in the user defined function?
A. whole program
B. only inside the {} block
C. the main function
D. header section
Show Answer
Answer:-B. only inside the {} blockExplanation
The variable is valid only in the function block as in other.Q 9. How many minimum number of functions should be present in a C++ program for its execution?
A. 0
B. 1
C. 2
D. 3
Leave a Reply