Home Tutorial Datastructure Pointer and Structure in C

 
 

Share on Google+Share on Google+
Pointer and Structure in C
Posted on: April 29, 2010 at 12:00 AM
Advertisement
Structures in C defines the group of contiguous (adjacent) fields, such as records or control blocks. A structure is a collection of variables grouped together under a single name. It provides an elegant and powerful way for keeping related data together.

Description:

In this tutorial you will see how pointer is used with structure. This is a very important example because all data-structure program work on this principle.

Code:

#include <stdio.h>
#include <conio.h>

struct record
{
char name[20];
int roll;
};
struct record r,*p;

void main()
{
p=&r;
clrscr();
printf("\nEnter the name\n");
scanf("\n%s",&p->name);
printf("\nEnter the roll no\n");
scanf("%d",&p->roll);
printf("\n%s",p->name);
printf("\n%d",p->roll);
}

Code Description:

p=&r assign the address of object to p
*p allow the pointer to access the objects
*p.roll is same as p->roll like used in example.

Output:

Download this code
Advertisement

Related Tags for Pointer and Structure in C:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 29, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com