Industrial internet of things IOT Week-3.pptxKNaveenKumarECE
Call For Papers - 17th International Conference on Wireless & Mobile Networks...hosseinihamid192023
FUNDAMENTALS OF COMPUTER ORGANIZATION AND ARCHITECTUREShabista Imam
Ad
Structures-in-C programming with examples
2. 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 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.
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.
3. Suppose you want to store record of Student which consists of name,
address, roll number and age.
Structure is used to represent a record.
Suppose you want to store record of Book which consists of book
name, pages, price & author name.
4. 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. We use ‘struct’ keyword to define a structure in C.
struct structureName
{
datatype variableName1;
datatype variableName2;
.
.
};
Syntax New Datatype name
Structure must end with
semicolon
Structure
Members
6. Suppose you want to store record of Student which consists of name,
address, roll number and age.
struct Student
{
char studName[15];
chat address[30];
int rollNumber;
int age;
};
Example
New Datatype name
7. Suppose you want to store record of Book which consists of book
name, pages, price & author name.
struct Book
{
char bookName[15];
chat author[30];
int pages;
float price;
};
Example
New Datatype name
8. Suppose you want to store record of Employee which consists of
name, ID, salary, address & dept.
struct Employee
{
int emp_id;
char empName[15];
chat address[30];
char dept[3]
float salary;
};
Example
New Datatype name