Sunday 8 December 2013

Structures

# include<iostream>
using namespace std;
struct student
{
char name[10];
int r;
float m;
};
void main()
{
student s;
cout<<"Enter name"<<endl;
cin>>s.name;
cout<<"Enter Roll number"<<endl;
cin>>s.r;
cout<<"Enter Marks"<<endl;
cin>>s.m;
cout<<"Name is"<<s.name<<endl;
cout<<"Roll number is"<<s.r<<endl;
cout<<"Marks is"<<s.m<<endl;
}

In this program,we will discuss Structures........!!

First,What is the Structure is??Why we need it??

Structures:-
Structures are a way of storing many different values in variables of potentially different types under the same name. This makes it a more modular program, which is easier to modify because its design makes things more compact. Structs are generally useful whenever a lot of data needs to be grouped together--for instance, they can be used to hold records from a database or to store information about contacts in an address book. In the contacts example, a struct could be used that would hold all of the information about a single contact--name, address, phone number, and so forth.

I think now,you got is what the structure is......!!

Syntax:-
struct structurename
{
only data types not functions
};

Note:-
before using structure,you will first make it and then use it........!!It will be not make in any function...!!



In this program,we will make a student structure and make dattypes of  name,roll number and marks.....!!
In main,we will make an object of student(structurename) and enter name and other things in it......!!
s.name mean using s we will assign name,and so on......!!

Then,after we will printing name and other datatypes using s.......!!


Here,you will make your own Datatype like int,float but in your datatype student there is one char,one int and one float........!!

I think you got it.........!!!

Feel free to give suggestions in comment box.......! 


0 comments: