-moz-user-select:none; -webkit-user-select:none; -khtml-user-select:none; -ms-user-select:none; user-select:none;

Monday, 1 June 2015

Simple example of structures

Feeling difficulty in understanding the concept of structures in C++?
Simply e mail me at "G.A.Mujtaba11@gmail.com".

Today I am here with a simple example of structures in C++.Before explaining the example,let me tell you a very important concept about structures,"member access operator/dot operator".

Dot operator/Member access operator

If you want to access a variable in structures,then you should use "dot operator".
For example,
struct structure
{
int data
};
As you see in the above example that a structure is declared that contains a variable named as "data".
Suppose if you want to access that variable in main( ) function,then you should use dot operator as given below

structure s1;  //////s1 has data type structure
s1.data;   ///////this "." is pointing to the variable being declared in the structure.

Hope you understand this concept.Now below is the simple example of structures in C++.

Source code

structures example in C++

Output



Remember that the data type of employ is "database" in the above example.I am not taking any input from the user in the above program.In my next blog, I will inshallah (if Allah Almighty wants) concentrate on little complex program in which I will take inputs from the user.

I will recommend you to practice this simple code which will help you to better you concepts of structures in C++.

No comments:

Post a Comment