1 / 8

Structures

Structures in C programming are user-defined data types that allow you to combine different data types into a single unit. They help to construct complex data types in a meaningful way, similar to arrays. This article provides an introduction to structures, including how to define and use them in C programming.

rcarpenter
Download Presentation

Structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Structures In C Programming By Rajanikanth B

  2. Introduction A structure is a collection of variables under a single name. These variables can be of different types, and each has a name which is used to select it from the structure Structure is some what similar to Array. The only different is that array is used to store collection of similar data types while structure can store collection of any type of data. A structure is a user defined data type that groups logically related data items of different data types into a single unit. Structure is a user-defined data type in C which allows you to combine different data types to store in a new type Structures helps to construct complex data types in more meaningful way.

  3. Introduction Structure is used to represent a record. Suppose you want to store record of Student which consists of name, address, roll number and age. Suppose you want to store record of Book which consists of book name, pages, price & author name.

  4. Introduction All the elements of a structure are stored at contiguous memory locations. A variable of structure type can store multiple data items of different data types under the one name. As the data of employee in company that is name, Employee ID, salary, address, phone number is stored in structure data type.

  5. Defining Structure We use ‘struct’ keyword to define a structure in C. Syntax New Datatype name struct structureName { datatype variableName1; datatype variableName2; . . }; Structure Members Structure must end with semicolon

  6. Defining Structure - Example Suppose you want to store record of Student which consists of name, address, roll number and age. New Datatype name Example struct Student { char studName[15]; chat address[30]; int rollNumber; int age; };

  7. Defining Structure - Example Suppose you want to store record of Book which consists of book name, pages, price & author name. New Datatype name Example struct Book { char bookName[15]; chat author[30]; int pages; float price; };

  8. Defining Structure - Example Suppose you want to store record of Employee which consists of name, ID, salary, address & dept. New Datatype name Example struct Employee { int emp_id; char empName[15]; chat address[30]; char dept[3] float salary; };

More Related