Home C-tutorials C Structure Pointer



C Structure Pointer
Posted on: February 6, 2009 at 12:00 AM
This section illustrates you the concept of Structure Pointer in C.

C Structure Pointer

     

This section illustrates you the concept of Structure Pointer in C. You can see in the given example, we want to access the employee's information through structure pointer. For that, we declare the structure type st consisting of members id, name and address. Then we have declared a structure pointer as:

struct st employee, *stptr;

We point the pointer to employee with the expression stptr = &employee. Then access the given members by de-referencing the pointer. For this, we have used another structure selection operator which works on pointers to structures. If p is a pointer to a structure and m is a member of that structure, then p->m. We set the values of specified members as:

stptr->id = 1;
stptr->name = "Angelina";
stptr->address ="Rohini,Delhi";

Here is the code:

STPOINTE.C

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

int main() {
  struct st {
  int id;
  char *name;
  char *address;
  };
  struct st employee, *stptr;
  stptr = &employee;
  stptr->id = 1;
  stptr->name = "Angelina";
  stptr->address ="Rohini,Delhi";
  printf("Employee Information: id=%d\n%s\n%s\n", stptr->id, stptr->name,
  stptr->address);
  getch();
  return 0;
}

Output will be displayed as:

STPOINTE.EXE

Download Source Code:

Related Tags for C Structure Pointer:
cormantformiostructformatpointerstructureintthisforpoiexampletopointexaminformationeilsectioncanceinrminfomnttrwancaesthroughemhrrateratesxaxampseeessatisinfllivmplccstrwantssthconceptstaccessatiinforminformatpleplono


More Tutorials from this section

Ask Questions?    Discuss: C Structure Pointer   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.