Login Register
Code2night
  • Home
  • Blog Archive
  • Tutorial
  • Interview Q&A
  • Languages
    • Angular
    • C
    • c#
    • C#
    • HTML/CSS
    • Java
    • JavaScript
    • Node.js
    • Python
    • React
    • Security
    • SQL Server
    • TypeScript
  • Post Blog
  • Tools
    • JSON Beautifier
    • HTML Beautifier
    • XML Beautifier
    • CSS Beautifier
    • JS Beautifier
    • PDF Editor
    • Word Counter
    • Base64 Encode/Decode
    • Diff Checker
    • JSON to CSV
    • Password Generator
    • SEO Analyzer
    • Background Remover
  1. Home
  2. Blog
  3. Mastering Functions in C++: A Complete Guide with Examples

Mastering Functions in C++: A Complete Guide with Examples

Date- Dec 09,2023

3420

c++ user defined functions

Because there are no library functions with predetermined definitions, a user-defined function is one that is written by the user when writing any application. To fulfill the user's individual needs, the user must create his or her own functions. Such functions must be appropriately defined by the user. There is no such necessity to include any specific library in the program.

Different Types of User-Defined Functions in C

  1. Function with no arguments and no return value
  2. Function with arguments and no return value
  3. Function with no arguments and a return value
  4. Function with arguments and with return value


  • 1. return_type is the data type of the value that the function will return. If the function doesn't return anything, use void.
  • 2. function_name is the name you give to the function.
  • 3. parameters are the inputs the function accepts.
  • 4. function body contains the code that performs the specific task.
  • 5. return result is used to return a value from the function, where result(here we use int d as a RESULT) should be an expression of the same data type as return_type.

Function with no argument and no return type

#include<iostream.h>
#include<conio.h>
void add();
void add()
{
int a,b,c;
cout<<"Enter the value of a\n";
cin>>a;
cout<<"Enter the value of b\n";
cin>>b;
c=a+b;
cout<<"The value of c\n"<<c;
}
void main()
{
clrscr();
add();
getch();
}




Function with arguments and no return value

#include<iostream.h>
#include<conio.h>
void add(int x,int y);
void add(int x,int y)
{
int c;
cout<<"Enter the value of x\n";
cin>>x;
cout<<"Enter the value of y\n";
cin>>y;
c=x+y;
cout<<"The value of c is\n"<<c;
}
void main()
{
clrscr();
int x,y;
add(x,y);
getch();
}





Function with no arguments and a return value

#include<iostream.h>
#include<conio.h>
int add();
int add()
{
int x,y,c;
cout<<"Enter the value of x\n";
cin>>x;
cout<<"Enter the value of y\n";
cin>>y;
c=x+y;
return c;
}
void main()
{
clrscr();
int d;
d=add();
cout<<"The Result is\n"<<d;
getch();
}




Function with arguments and a return value
#include<iostream.h>
#include<conio.h>
int add();
int add(int x,int y)
{
int c;
cout<<"Enter the value of x";
cin>>x;
cout<<"Enter the value of y";
cin>>y;
c=x+y;
return c;
}
void main()
{

clrscr();
int x,y,d;
d=add(x,y);
cout<<d;
getch();
}




S
Shubham Saini
Programming author at Code2Night — sharing tutorials on ASP.NET, C#, and more.
View all posts →

Related Articles

Ultimate Guide to Operator Overloading in C++: Explained
Dec 09, 2023
Mastering Inheritance in C++: A Complete Guide with Examples
Dec 09, 2023
Complete Guide to Classes in C++ with Examples
Dec 09, 2023
Complete Guide to Using Templates in C++ with Examples
Dec 09, 2023
Previous in C++
Ultimate Guide to Operator Overloading in C++: Explained
Next in C++
Complete Guide to Using Templates in C++ with Examples

Comments

Contents

More in C++

  • Input/Output Statements in C++ 3427 views
  • Ultimate Introduction to C++: Get Started in Minutes 3119 views
View all C++ posts →

Tags

AspNet C# programming AspNet MVC c programming AspNet Core C software development tutorial MVC memory management Paypal coding coding best practices data structures programming tutorial tutorials object oriented programming Slick Slider StripeNet
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1760
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp
Code2Night

A community platform for sharing programming knowledge, tutorials, and blogs. Learn, write, and grow with developers worldwide.

Panipat, Haryana, India
info@code2night.com
Quick Links
  • Home
  • Blog Archive
  • Tutorials
  • About Us
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Guest Posts
  • SEO Analyzer
Free Dev Tools
  • JSON Beautifier
  • HTML Beautifier
  • CSS Beautifier
  • JS Beautifier
  • Password Generator
  • QR Code Generator
  • Hash Generator
  • Diff Checker
  • Base64 Encode/Decode
  • Word Counter
  • SEO Analyzer
By Language
  • Angular
  • C
  • c#
  • C#
  • HTML/CSS
  • Java
  • JavaScript
  • Node.js
  • Python
  • React
  • Security
  • SQL Server
  • TypeScript
© 2026 Code2Night. All Rights Reserved.
Made with for developers  |  Privacy  ·  Terms
Translate Page
We use cookies to improve your experience and analyze site traffic. By clicking Accept, you consent to our use of cookies. Privacy Policy