Object Oriented Programming: C++

To understand and switch from C to C++, you need to know some of the basic similarities and differences between the two.

Sample C Program:


void main()
  printf("Welcome To C");

Here stdio.h header file is included inorder to make use of printf and scanf functions.

Sample Cpp Program:


void main()
  cout<<"Welcome To Cpp";

Here iostream.h header file is included inorder to make use of cout and cin objects.

cout is an object of class ostream.
cin is an object of class istream.

Both these ostream and istream classes are present inside iostream.h file.

In both C and C++, execution of the program starts from main() function.

The difference is, printf and scanf are functions; while cout and cin are objects.

<< is called Insertion Operator. To show result on output window.
>> is called Extraction Operator. To get input from the user(keyboard).

Structures In C:

struct Student
  char name[20];
  int age;

To access members of structure:


Video Tutorial: Basics of C++

You need to a flashplayer enabled browser to view this YouTube video

YouTube Link: http://www.youtube.com/watch?v=GuZFpc0diJ4 [Watch the Video In Full Screen.]

Class In Cpp:


class Student
  int a, b, c;

  void read() { cin>>a>>b>>c; }
  void show() { cout<<"\nEntered Numbers are "<<a<<" , "<<b<<" , "<<c; }

int main()
  A a;

  cout<<"\nEnter 3 nums\n";



member functions are accessed with the help of objects.


This way data binding is done and a level of security is imparted to the data.

Binding of Data and method into a single unit is called ENCAPSULATION.