In this tutorial you will learn about the C++ Functions with No Arguments and No return value and its application with practical example.
C++ Functions with No Arguments and No return value
In this tutorial, we will learn to create a C++ program that will use Functions with No Arguments and No return value using C++ programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C++ programming topics:
- Operators in C++ Programming.
- Basic Input and Output function in C++ Programming.
- Basic C++ programming.
- Arithmetic operations in C++ Programming.
- Functions in C++ programming.
What are functions in C++?
In every programming language, there are many types of functions available. There are two major types of functions in C++ programming.
- Predefined functions.
- User-defined functions.
In user-defined functions there are four types:-
- Function with no argument and no return value
- Function with no argument but the return value
- User-defined Function with argument but no return value
- User-defined Function with argument and return value
Algorithm:-
1 2 3 4 5 6 7 8 9 10 11 |
1. Initiating the program. 2. Creating a user defined function with no argument and no return type. 3. Writing the function body code. 4. Write main function code. 5. Call user defined function. 6. End program. |
Program using Functions with No Arguments and No return value.
In this program, we will create a function that will print the symbols using a user-defined function with no return type and no arguments. With the help of this program, we can print the “*” of the above function type.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
/* C++ program using Functions with No Arguments and No return value */ #include <iostream> using namespace std; int main() { /* Declaring a user dfined function with no argument and no return type */ void print(); /* Calling that user defined function in main function for printing */ print(); cout<<"\nFunction with no Arguments and no return type \n"; // print(); return 0; } /* Body of called function in main function */ void print(void) { //printing the data on screen for (int i=1;i<10;i++) cout<<"* "; cout<<"\n"; } |
Output:-
Creating the user-defined function with no arguments and no return type.
Body of the user-defined function.
Calling the user-defined function.
Body of the main function of the program.