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

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

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

Answer:c
Explanation:None.

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

Answer:d
Explanation:None.

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

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

Answer:c
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

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 definied function?
a) whole program
b) only inside the {} block
c) both a and b
d) none of the mentioned
View Answer

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

Answer:b
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
About

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.


Sanfoundry Training Center of Excellence (CoE)

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.







1000 C++ MCQs | Quiz

Types
Booleans
Character Types
Integer Types
Floating Point Types
Sizes
Void
Enumerations
Declaration
Pointers
Arrays
Pointers into Arrays
Constants
References
Pointer to Void
Structures
Operators
Statements
Comments and Indentation
Function Declarations
Argument Passing
Value Return
Overloaded Function Names
Default Arguments
Unspecified Number of Arguments
Pointer to Function
Macros
Modularization and Interfaces
Namespaces
Exceptions
Linkage
Header Files Usage
Classes
User Defined Types
Objects
Operator Functions
Complex Number Type
Conversion Operators
Friends
Large Objects
Essential Operators
Subscripting
Function Call
Dereferencing
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
Specialization
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
Vector
Sequences
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
Heaps
Min and Max
Permutations
C Style Algorithms
Iterators and Sequences
Checked Iterators
Allocators
String Characters
Basic String
C Standard Library
Output Stream
Input Stream
Formatting
File Streams and String Streams
Buffering
Locale
C Input Output
Numeric Limits
Standard Mathematical Functions
Vector Arithmetic
Generalized Numeric Algorithms
Random Numbers
Subscribe Newsletter & Posts
Follow Manish & Sanfoundry