Professional Documents
Culture Documents
Structure To Pointer
Structure To Pointer
SAMPLE PROGRAM
#include<stdio.h>
int main()
{
struct comp
{
char workername;
char companyname;
int salary;
};
struct comp c1= {anuj,Ranbaxy,5550};
printf (Name=%u\n,c1.workername);
printf(company name=%u\n,c1.companyname);
printf(salary=%u\n,c1.salary);
return 0;
}
Output will be:
Name=anuj
Companyname=Ranbaxy
salary=5550
POINTERS TO
STRUCTURES
Pointers can be used with structures to make use
of address and
defining structures.
The notation used to pointer to structure is:
(*ptr).number
Example
#include<stdio.h>
#include<conio.h>
struct invent
{
char *name[20];
int number;
float price;
};
void main()
{
struct invent product[3], *ptr;
printf(INPUT\n\n);
for(ptr= product; ptr<product+3; ptr++)
scanf(%s%d%f,&ptr->name, &ptr->number, &ptr->price);
printf(\n OUTPUT\n\n);
ptr= product;
while(ptr < product+3)
{
printf (%-20s %5d %10.2f\n);
ptr->name;
ptr->number;
THANK YOU