C – Pointers and Structure

After reading this C pointers and structure topic, you will understand its theory and examples also you will able to implement it in C programming.

Pointers pointing structure is known as structure pointer. The example below will show how pointers and structure used in C programming.

Example:

Program (1): To demonstrate the use of structure pointer in C programming.

#include<stdio.h>
#include<conio.h>
void main(void)
{
struct language
{
char name;
int year;
};
struct language dr={'C',1972};
struct language *ptr;
ptr=&dr;
printf("%c %d\n",dr.name,dr.year);
//alternate way to access structure members using operator ->
printf("%c %d\n",ptr->name,ptr->year);
getch();
}

Output (1)

C 1972
C 1972

Published by

Electrical Workbook

We provide tutoring in Electrical Engineering.

Leave a Reply

Your email address will not be published. Required fields are marked *