Home > Backend Development > C++ > body text

Use the typedef keyword in C language to interpret structures

王林
Release: 2023-08-25 13:25:15
forward
1308 people have browsed it

Use the typedef keyword in C language to interpret structures

Typedef

'C' allows the definition of new data type names using the 'typedef' keyword. Using ‘typedef’ we cannot create a new data type, but define a new name for an already existing type. The Chinese translation of

Syntax

typedef datatype newname;
Copy after login

Example

is:

Example

typedef int bhanu;
int a;
bhanu a; %d
Copy after login
  • 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'.
  • The Chinese translation of

Example

is:

Example

#include <stdio.h>
main (){
   typedef int hours;
   hours h; //int h;
   clrscr ();
   printf("Enter hours&rdquo;);
   scanf ("%d&rdquo;, &h);
   printf("Minutes =%d&rdquo;, h*60);
   printf("Seconds = %d&rdquo;, h*60*60);
   getch ();
}
Copy after login

Output

Enter hours =1
Minutes = 60
Seconds = 360
Copy after login

typedefining example of a structure

typedef struct employee{
   int eno;
   char ename[30];
   float sal;
} emp;
main (){
   emp e = {10, "ramu&rdquo;, 5000};
   clrscr();
   printf("number = %d&rdquo;, e.eno);
   printf("name = %d&rdquo;, e.ename);
   printf("salary = %d&rdquo;, e.sal);
   getch ();
}
Copy after login

Output

Number=10
Name=ramu
Salary=5000
Copy after login

The above is the detailed content of Use the typedef keyword in C language to interpret structures. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template