Home   |   About   |   Terms   |   Contact    
A platform for writers

What is a Member Function in C++?


☯ All C++ Articles     ☯ All Articles

Popular Google Pages:

◕ Send your story to RiyaButu.com and get ₹ 500/- Details..

◕ Bengali Story writing competition. Details..

◕ This article is regarding What is a Member Function in C++?
Last updated on: .

◕ Let an example first.

#include <iostream>
using namespace std;
char state = 'T';
int main()
cout << "Displaying char constant using Member Function, cout.put(): " << endl;
return 0;

The output of this program is:
Displaying char constant using Member Function, cout.put():

- Here cout.put() is a Member Function.

- A Member Function belongs to a class and it describes a method to manipulating the class data.
Here ostream class has a put() Member Function that is designed to output character constant such as 'T'.
Here put() is the class Member Function and cout is the class object.

- We can use a Member Function only with a particular object of that class. Here the cout is that object.

- To use a class Member Function with an object, we need a period (. full stop) to combine the object name with the function name.
This period is called the Membership Operator.

In this cout.put() Member Function we used a period sign as the membership operator.

- The cout.put() Member Function is an alternative of the << operator to display a character constant.

So why we need cout.put()?
- Because cout.put() was used in the old version of the C++ for displaying char constant such as 'A', 'B' etc.

Related articles:
Bits & Bytes
Integer Type in C++
Rules for Variable Names
Variable in C++
Fundamental Data Types & Compound Data Types

Top of the page

Amazon & Flipkart Special Products


Top of the page