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