C++ Programming Questions and Answers – Function Declarations

This section on tough 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.

Here is a listing of tough C++ programming questions on “Function Declarations” along with answers, explanations and/or solutions:

1. Where does the execution of the program starts?
a) user-defined function
b) main function
c) void function
d) else function
View Answer

Answer: b
Explanation: Normally the execution of the program in c++ starts from main only.

2. What are mandatory parts in the function declaration?
a) return type, function name
b) return type, function name, parameters
c) parameters, function name
d) parameters, variables
View Answer

Answer: a
Explanation: In a function, return type and function name are mandatory all else are just used as a choice.

3. which of the following is used to terminate the function declaration?
a) :
b) )
c) ;
d) ]
View Answer

Answer: c
Explanation: ; semicolon is used to terminate a function declaration statement in C++.
advertisement
advertisement

4. How many can max number of arguments present in function in the c99 compiler?
a) 99
b) 90
c) 102
d) 127
View Answer

Answer: d
Explanation: C99 allows to pass a maximum of 127 arguments in a function.

5. Which is more effective while calling the functions?
a) call by value
b) call by reference
c) call by pointer
d) call by object
View Answer

Answer: b
Explanation: 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.

6. What will be the output of the following C++ code?

  1.     #include <iostream>
  2.     using namespace std;
  3.     void mani()
  4.     void mani()
  5.     {
  6.         cout<<"hai";
  7.     }
  8.     int main()
  9.     {
  10.         mani();
  11.         return 0;
  12.     }

a) hai
b) haihai
c) compile time error
d) runtime error
View Answer

Answer: c
Explanation: 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.
advertisement

7. What will be the output of the following C++ code?

advertisement
  1.     #include <iostream>
  2.     using namespace std;
  3.     void fun(int x, int y)
  4.     {
  5.         x = 20;
  6.         y = 10;
  7.     }
  8.     int main()
  9.     {
  10.         int x = 10;
  11.         fun(x, x);
  12.         cout << x;
  13.         return 0;
  14.     }

a) 10
b) 20
c) compile time error
d) 30
View Answer

Answer: a
Explanation: 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
10

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
View Answer

Answer: b
Explanation: The variable is valid only in the function block as in other.

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
View Answer

Answer: b
Explanation: The execution of a C++ program starts from main function hence we require atleast 1 function to be present in a C++ program to execute and i.e. the main function.

Sanfoundry Global Education & Learning Series – C++ Programming Language.

To practice all areas of C++ language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.