C++ Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
C++ Tutorial
C++ Language Tutorial - Object Oriented Programing - OOPs History of C++
C++ Language Tutorial - Object Oriented Programing - OOPs Structure of C++
C++ Language Tutorial - Object Oriented Programing - OOPs C++ Datatypes
C++ Language Tutorial - Object Oriented Programing - OOPs Variables
C++ Language Tutorial - Object Oriented Programing - OOPs Constants
C++ Language Tutorial - Object Oriented Programing - OOPs Operators
C++ Language Tutorial - Object Oriented Programing - OOPs Control Structures
C++ Language Tutorial - Object Oriented Programing - OOPs Arrays
C++ Language Tutorial - Object Oriented Programing - OOPs Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Class
C++ Language Tutorial - Object Oriented Programing - OOPs Predefined Functions
C++ Language Tutorial - Object Oriented Programing - OOPs I/O Functions
C++ Language Tutorial - Object Oriented Programing - OOPs String, Character Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Mathematical Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Time Date Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Dynamic Allocation
C++ Language Tutorial - Object Oriented Programing - OOPs Utility Functions
C++ Language Tutorial - Object Oriented Programing - OOPs OOP's Concept
C++ Language Tutorial - Object Oriented Programing - OOPs Special Topics
C++ Language Tutorial - Object Oriented Programing - OOPs Type casting
C++ Language Tutorial - Object Oriented Programing - OOPs Feedback
C++ Language Tutorial - Object Oriented Programing - OOPs Ask Your Doubts
 





Functions in C++


Tutorials Cpp

Topic

Using Functions in C++?



Explanation

A Function is a set of statements that can be used anywhere in the program. Main reason for using it is to strcuture the programmming by creating function for repetitive tasks.

Syntax:
    return-type function-name(parameter list)
     {
      Statements
     }

In the above syntax the "return-type" defines the data type of the value returned by the functions, the "function-name", unique name used to call a function. The "Parameters" are seperated by commas that consist of the data type along with identfiers for the parameters.

Example:

   #include<iostream.h>
   int x,y,z,a,b,r;
   addition(int a, int b)
     {
       r = a + b;
       return (r);
     }
   int main()
     {
       cout << "Enter the first integer::"; cin >> x;
       cout << "Enter the second integer::"; cin >> y;
       z = addition(x,y);
       cout << "Sum of X and Y is::" << z << '\n';
     }

Result:
   Enter the first integer::10 
   Enter the second integer::20
   Sum of X and Y is:: 30 

In the above example a function "addition()" is used to add two numbers.










Note
C++ is one of the most used programming languages in the world. Also known as "C with Classes". Hope you enjoy this tutorial. Do send your feedback or suggestions on this C++ tutorial. This is a copyright content.

Other Links

web hosting