{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Chapter 10-p - Example 10.1 Define a structure type struct...

This preview shows pages 1–3. Sign up to view the full content.

Example 10.1 Define a structure type, struct personal that would contain person name, date of joining and salary. Using this structure, write a program to read this information for one person from the keyboard and print the same on the screen. Structure definition along with the program is shown in Fig.10.1. The scanf and printf functions illustrate how the member operator `.' is used to link the structure members to the structure variables. The variable name with a period and the member name is used like an ordinary variable. DEFINING AND ASSIGNING VALUES TO STRUCTURE MEMBERS Program struct personal { char name[20]; int day; char month[10]; int year; float salary; }; main() { struct personal person; printf("Input Values\n"); scanf("%s %d %s %d %f", person.name, &person.day, person.month, &person.year, &person.salary); printf("%s %d %s %d %f\n", person.name, person.day, person.month, person.year, person.salary); }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Output Input Values M.L.Goel 10 January 1945 4500 M.L.Goel 10 January 1945 4500.00 Fig.10.1 Defining and accessing structure members Example 10.2 Write a program to illustrate the comparison of structure variables. The program shown in Fig.10.2 illustrates how a structure variable can be copied into another of the same type. It also performs member-wise comparison to decide whether two structure variables are identical. COMPARISON OF STRUCTURE VARIABLES Program struct class { int number; char name[20]; float marks; }; main() { int x; struct class student1 = {111,"Rao",72.50}; struct class student2 = {222,"Reddy", 67.00}; struct class student3; student3 = student2; x = ((student3.number ==
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 7

Chapter 10-p - Example 10.1 Define a structure type struct...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online