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, walkin 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 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) none of the mentioned
View Answer

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

2. What are mandatory parts in function declaration?
a) return type,function name
b) return type,function name,parameters
c) both a and b
d) none of the mentioned
View Answer

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) none of the mentioned
View Answer


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


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

Explanation:In the call by reference, it will just copy the address of the variable to access it, so it will reduce the memory in accessing it.

6. What is the output of this program?

  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) none of the mentioned
View Answer

Explanation:We have to use the semicolon to declare the function in line 3. If we did means, the program will execute.

7. What is the output of this program?

  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) none of the mentioned
View Answer

Explanation:In this program, we called by value so the value will not be changed, So the output is 10
$ g++ fun.cpp
$ a.out

8. What is the scope of the variable declared in the user definied function?
a) whole program
b) only inside the {} block
c) both a and b
d) none of the mentioned
View Answer

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

9. How many minimum number of functions are need to be presented in c++?
a) 0
b) 1
c) 2
d) 3
View Answer

Explanation:The main function is the mandatory part, it is needed for the execution of the program to start.

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

Here’s the list of Best Reference Books in C++ Programming Language.

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

Subscribe Newsletter & Posts

Manish Bhojasia, a technology veteran with 17+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below.

Practice Interview Questions & Answers, Quizzes, Objective, Multiple Choice Aptitude Tests for Freshers and Experienced People in these topics - Learn C, C++, Java and C# Programming with coding example on Simple problems as well as tough Algorithms and Data-structures along with runtime output: - C Programs, Data-Structures and Algorithms, C++ Algorithms, Java Algorithms, C# Programs, Android Programs in Java

C Tutorials and Linux Commands Tutorial - C Tutorials, Linux Commands

Career Mentoring with our Founder / CTO - Read More

1000 C++ MCQs | Quiz

Character Types
Integer Types
Floating Point Types
Pointers into Arrays
Pointer to Void
Comments and Indentation
Function Declarations
Argument Passing
Value Return
Overloaded Function Names
Default Arguments
Unspecified Number of Arguments
Pointer to Function
Modularization and Interfaces
Header Files Usage
User Defined Types
Operator Functions
Complex Number Type
Conversion Operators
Large Objects
Essential Operators
Function Call
Increment and Decrement
String Class
Derived Classes
Abstract Classes
Design of Class Hierarchies
Class Hierarchies & Abstract Classes
Simple String Template
Function Templates
Template Arguments for Policy Usage
Derivation and Templates
Error Handling
Grouping of Exceptions
Catching Exceptions
Resource Management
Exceptions That Are Not Errors
Exception Specifications
Uncaught Exceptions
Exceptions and Efficiency
Error Handling Alternatives
Standard Exceptions
Class Hierarchies Introduction
Multiple Inheritance
Access Control
Run Time Type Information
Pointers to Members
Free Store
Standard Library Design
Container Design
Sequence Adapters
Associative Containers
Almost Containers
Defining a New Container
Standard Library Algorithms
Sequences and Containers
Function Objects
Nonmodifying Sequence Algorithms
Modifying Sequence Algorithms
Stored Sequences
Min and Max
C Style Algorithms
Iterators and Sequences
Checked Iterators
String Characters
Basic String
C Standard Library
Output Stream
Input Stream
File Streams and String Streams
C Input Output
Numeric Limits
Standard Mathematical Functions
Vector Arithmetic
Generalized Numeric Algorithms
Random Numbers
Follow Manish & Sanfoundry