
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Explain structures using typedef keyword in C language
Typedef
βCβ allows to define new datatype names using the βtypedefβ keyword. Using βtypedefβ, we cannot create a new datatype but define a new name for already existing type.
Syntax
typedef datatype newname;
Example
typedef int bhanu; int a; bhanu a; %d
- This statement tells the compiler to recognize βbhanuβ as another name for βintβ.
- βbhanuβ is used to create another variable βaβ .
- βbhanu a βdeclares βaβ as a variable of type βintβ.
Example
#include <stdio.h> main (){ typedef int hours; hours h; //int h; clrscr (); printf("Enter hoursβ); scanf ("%dβ, &h); printf("Minutes =%dβ, h*60); printf("Seconds = %dβ, h*60*60); getch (); }
Output
Enter hours =1 Minutes = 60 Seconds = 360
Example for typedefining a structure
typedef struct employee{ int eno; char ename[30]; float sal; } emp; main (){ emp e = {10, "ramuβ, 5000}; clrscr(); printf("number = %dβ, e.eno); printf("name = %dβ, e.ename); printf("salary = %dβ, e.sal); getch (); }
Output
Number=10 Name=ramu Salary=5000
Advertisements