..

FreePrograms


C programming Tutorial 

Free C Programs, C Programs Download


Embedded C lang & 8051(Embedded Products)


  CONTACT US   ABOUT US   PRIVACY  DISCLAIMER

FREE C PROGRAMS 

 C Tutorial for beginners
What is C C vs C++ vs Java Program Structure Data Types in C Basic Rules of C & C++
Functions in C If, Else Conditions Loops in C Switch Case Arrays
Pointers Structures in C Strings in C Command Line Arguments Type Casting
Linked Lists Recursion Binary Trees Inheritance Multiple Inheritance
Templates File I/O Object Oriented Programming  Data Structures in C C interview Questions

/*Classes in CPP, Structures vs Classes  C++/CPP Tutorial.*/

 

C++ classes members include variables (including other structures and classes), functions (specific identifiers or overloaded operators) known as methods, constructors and destructors.

Members are declared publicly or privately accessible using the public: and private: access specifiers respectively.

#include <iostream.h>
#include <string.h>
using namespace std;

class employee
{
public:
string name;
int age;
};

int main()
{
employee x, y;
x.name = "ABC";
y.name = "XYZ";
x.age = 25;
y.age = 19;
cout << x.name << ": " << x.age << endl;
cout << y.name << ": " << y.age << endl;
return 0;
}

 

Structures vs. Classes

The only difference between a structure and a class is that, in a class, the member data or function are private by default whereas, in a structure, they are public by default.

The following c++ code
Class sample
{
private:
int x;
public:
void func(void);
};


can be written as:

class sample
{
int x;
public:
void func(void);
};


The keyword private isn't necessary because, in a class, the members are private by default. The code segment can be modified using a structure in the following way:


struct sample
{
void func(void);
private:
int x;
};


The keyword public isn't necessary because the structure members are public by default

 

 

COPYRIGHT 2009 ALL RIGHTS RESERVED FREECPROGRAMS.COM