Group Discounts available for 3+ students and Corporate Clients

Functions in C++


  • Inline functions
  • Function default arguments
  • Function overloading
  • Pass by value


Classes and Objects  in C++


Class is a data type or user defined data type.

It is a collection of members, these members are 2 types.

Data members

Member functions

In object oriented application development data is represent in the form of object


Difference between class & structure


class in c++  Structure in ‘C’
It is a collection of variables and functions structure is a collection of variables
Contents is private, protected or public Contents is public / global
It provide security for data It does not provide security for data
It support polymorphism and inheritance It does not support polymorphism and inheritance



Syntax of class in C++

class  class-type-name


private :



public :


member functions;



What is data member ?

Variable declared inside class is called data member

Data member define state of the object or value hold by object.


Member function in C++

Function defined inside a class is called member function

Binding data members with member function inside a class called as

Member function define behavior of object or operation performed on the object

Private, public and protected are called as access specifier.

Default members of class are private

Default members of structure are global/ public


Access specifier/ access neighbours

Access specifier define visibility on accessibility of members declared within class.

C++ provide 3 access specifiers

  1. private
  2. protected
  3. public



Default members of class are private

Private member are accessible within class or members of the same class

Private members are not accessible within non members on members of other classes.





Data hiding in object oriented is achieved by declaring data members within class as private


Protected member access by members of same class and derived class

Protected members cannot access by non members and members of other classes.








These  members access by members of some class, derived class, non members and members of other classes.





Summary of Access Specifiers


  with in class Non members Member of derived class Member of Other class
Private Yes No No No
Protected Yes No Yes No
Public Yes Yes Yes Yes



Object in C++

  • It is a instance of class
  • A variable of type class is called object
  • On creation of object memory is allocated for data members of class.


Class –name object –name, object-name,….

class defined structure of object


Program (Write a program to find area of triangular)

# include <iostream.h>                   [ writing a class within main- local

class triangle                                             classes & vice versa]


private :

float base, height;                 // data members

public :

void read()


cout<<”\n input base height”;



void find area ()


float area=0.5*base*height;



Size of the class is equal to some of data member size

On creation of object memory is allocated for data members of class but not member functions

Member functions operators on one or more than one object.


“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at, we will update the article in 24 hours.”

0 Responses on Functions in C++"

Leave a Message

Your email address will not be published. Required fields are marked *


Please Enter Your Details and Query.
Three + 6