Startertutorials Blog
Tutorials and articles related to programming, computer science, technology and others.
Subscribe to Startertutorials.com's YouTube channel for different tutorial and lecture videos.
Home » Programming » C Programming » Programs » Structures and Unions » C program to demonstrate how to use a typedef struct in c
Suryateja Pericherla Categories: Structures and Unions. No Comments on C program to demonstrate how to use a typedef struct in c
0
(0)

In this article we will learn to implement a C program to demonstrate how to use a typedef struct in c. A C program is provided below which illustrates how to use typedef along with a structure.

 

Program is as follows:

/*
 * C program to demonstrate typedef usage with a structure
 * Author: P.S.SuryaTeja
*/
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

typedef struct
{
	int id;
	char name[20];
}student;

int main(int argc, char **argv)
{
	student *stp;
	student st;
	stp = &st;
	printf("Enter student id: ");
	scanf("%d", &stp->id);  //&stp->id is same as writing &(*stp).id
	fflush(stdin);
	printf("Enter student name: ");
	gets(stp->name);
	printf("\n***Student Details***");
	printf("\nStudent id: %d", stp->id);
	printf("\nStudent name: ");
	puts(stp->name);
    getch();
    return 0;
}

 

Input and output for the above program is as follows:

Enter student id: 101
Enter student name: teja

***Student Details***
Student id: 101
Student name: teja

 

How useful was this post?

Click on a star to rate it!


Subscribe to our monthly newsletter. Get notified about latest articles, offers and contests.


We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Reply

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

Facebook
Twitter
Pinterest
Youtube
Instagram
Blogarama - Blog Directory