The document explains the difference between arrays and structures in C, highlighting that arrays hold multiple items of the same type while structures can combine different types. It introduces the 'typedef' keyword, which allows users to create descriptive names for standard and user-defined data types. Examples are provided to demonstrate how to use 'typedef' with structures and how to input and display data using these types.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
5 views6 pages
STRUCTURES IN C (C)
The document explains the difference between arrays and structures in C, highlighting that arrays hold multiple items of the same type while structures can combine different types. It introduces the 'typedef' keyword, which allows users to create descriptive names for standard and user-defined data types. Examples are provided to demonstrate how to use 'typedef' with structures and how to input and display data using these types.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6
STRUCTURES: typedef
keyword DIFFERENCE BETWEEN ARRAY & STRUCTURE:
C arrays allow you to define type of variables
that can hold several data items of the same kind but structure is a user defined data type, which allows you to combine data items of different kinds . Typedef: The tydedef keyword allows users to give descriptive names for the standard data types. In other words, an alias type name can be defined for a standard data type. The syntax is: tydedef datatype name; Where, Datatype: any standard data type Name: new name for this type You can also use typedef to give a name to your user defined data types as well. For example, you can use typedef with structure to define a new data type and then use that data type to define structure variables directly
typedef struct student
{ int rollno; char name[20]; int clas; float marks; char grade; }senior; #include<stdio.h> int main() { typedef int marks ; Enter the value marks m; 90 printf("\n enter the value"); 90 scanf("%d",&m); printf("\n%d",m); return 0; } #include<stdio.h> Enter rollno, name,class, marks, grade typedef struct student 4322 { int rollno; John char name[20]; 12 int clas; 78 float marks; B char grade; 4322 }senior; senior stud1; John int main(){ 78 printf("\n Enter rollno, name, class,marks, grade\n"); 12 scanf("%d",&stud1.rollno); B fflush(stdin); gets(stud1.name); scanf("%d",&stud1.clas); scanf("%f",&stud1.marks) ; fflush(stdin); scanf("%c",&stud1.grade); printf("\n %d", stud1.rollno ); printf("\n %s", stud1.name) ; printf("\n %f", stud1.marks) ; printf("\n %d", stud1.clas ); printf("\n %c", stud1.grade) ; return 0; }