C++ Structure and Class:user-defined data type

A user-defined data types is a data type which the programmer or user can define according to his needs.In built-in data type the properties and size are limited to what is hard coded in the compiler .With user-defined data types however,the size can be limitless(as long the size of your memory is limitless) since the user-defined data type can consists of many built-in data type and act as a single type.C and C++ have their own user-defined data types but since C is part of C++ we can also use the C user-defined data type in C++,so including the C user defined data type there are two types in C++ :class and structure.Below we will discuss the two types in brief.

Note:Detail discussion of the two types will be done in different chapters.

C++ Structure

Structure is a user-defined data types included in C.The keyword for this data type is struct.How to declare such type is shown below.

struct Ai
/* Declare built-in data type here
/*For instance */

int i;
char c;
} ;     ///Don’t forget the ;(semi-colon) here

The name of the structure shown above is Ai and it consists of one int(i) and one char(c) built-in data type.How to manipulate the built-in type and how to implement the structure Ai in our program will be shown in the next chapter.For now knowing how to declare the structure correctly is good enough.


Stop wasting time,earn money($$$) from your website-Join Now!

C++ Class

Class is a user-defined data type introduced in C++. It has the same characteristic as the structure but with the addition of some new properties allowing the user to make it more secure and implement them better in the program.The keyword for this type is class.It will be declared in the same way as the structure.

class Love
    //Declare built-in type here
    int ii ;
    string str;
} ;     ///Don’t forget the ;(semi-colon) here>

The class name is Love and an extra public is added here.What this public stands for and how to implement class in our program will be discussed in detail in chapter 3.

Related Link

->Using wchar_t to print out Japanese,Chinese,Russian in Console.