The document discusses different data types in C programming language including primary, derived, and user-defined data types. It explains what structures are and how to define, declare, and access structure variables. Structures allow grouping of different data types under a single name to represent complex user-defined data types like a record. The document provides examples of defining simple and nested structures, arrays of structures, and accessing structure members using pointers. It also discusses some common programming problems that can be solved using structures.
Data Structure & Algorithm - Self Referentialbabuk110
The document discusses structures in C programming. It defines a structure as a collection of logically related data items of different datatypes grouped together under a single name. Some key points discussed include:
- Structures allow user-defined datatypes that can group different data types together.
- Structures are defined using the struct keyword followed by the structure name and members.
- Structure variables are declared to use the structure datatype. Arrays of structures can also be defined.
- Members of a structure can be accessed using the dot (.) operator or arrow (->) operator for pointers to structures.
The document provides examples of defining, declaring, and accessing structure variables and members.
Easy Understanding of Structure Union Typedef Enum in C Language.pdfsudhakargeruganti
This document discusses various C programming concepts related to structures, unions, enumerations, and typedef. It provides definitions and examples of each concept. Structures allow grouping of different data types under a single name. Unions share the same memory location for members. Enumerations define a user-defined data type of integer constants. Typedef allows defining an alias for existing data types. The document also discusses accessing structure members, nested structures, arrays of structures, passing structures to functions, self-referential structures, and bit fields.
data structure and c programing conceptskavitham66441
A structure allows grouping of different data types under a single name. It can be used to represent a record by defining members for each attribute. Structures support defining arrays of structures to group multiple records together. Unions share memory between members and only one member can be accessed at a time, while structures have independent memory for each member. Pointers store the address of a variable and allow dynamic memory allocation by changing which variable an address points to.
Structures-Declaring and Initializing, Nested structure, Array of Structure, Passing Structures to functions, Unions, typedef, enum, Bit fields.
Pointers: Declarations, Pointer arithmetic, Pointers and functions, call by value, Call by reference, Pointers and Arrays, Arrays of Pointers, Pointers and Structures. Meaning of static and dynamic memory allocation, Memory allocation functions.
Files: File modes, File functions, and File operations, Text and Binary files, Command Line arguments Preprocessor directives. Macros: Definition, types of Macros, Creating and implementing user defined header files
COURSE TITLE: SOFTWARE DEVELOPMENT VI
COURSE CODE: VIT 351
TOPICS COVERED:
USER DEFINED DATATYPES
STRUCTURE
UNION
TYPEDEF
DIFFERENCE BETWEEN STRUCTURE AND UNION
ENUMERATION (ENUM)
QUIZ SET 4
The document discusses structures and unions in C programming. It defines a structure as a user-defined data type that allows storing heterogeneous data under a single name. Structures contain members that can be accessed using the dot operator. Arrays of structures allow storing multiple records of the same type. Structures can be nested by defining a structure member within another structure. Unions allow storing different types of data in the same memory location, but only one member can be accessed at a time. Examples are provided to demonstrate defining, declaring, and accessing structure and union variables as well as nested structures.
This document discusses using structures in C programming to store student records. It defines a student structure with roll number, name, and marks members. A program is provided that uses a structure array to store records for 10 students, reading input and then displaying the stored information. The key aspects of defining structures, declaring structure variables, accessing structure members, and allocating structure memory are explained. Sample problems are given to practice using structures to store book information and add distances.
The document discusses structures and unions in C programming. It defines a structure as a user-defined data type that groups together related data of different types under a single name. A union is similar to a structure but can only store one data member at a time as it allocates memory for the largest data type. The key points covered include declaring and initializing structures and unions, accessing structure members, arrays of structures, structures within structures, and comparing structures and unions.
Data Structure & Algorithm - Self Referentialbabuk110
The document discusses structures in C programming. It defines a structure as a collection of logically related data items of different datatypes grouped together under a single name. Some key points discussed include:
- Structures allow user-defined datatypes that can group different data types together.
- Structures are defined using the struct keyword followed by the structure name and members.
- Structure variables are declared to use the structure datatype. Arrays of structures can also be defined.
- Members of a structure can be accessed using the dot (.) operator or arrow (->) operator for pointers to structures.
The document provides examples of defining, declaring, and accessing structure variables and members.
Easy Understanding of Structure Union Typedef Enum in C Language.pdfsudhakargeruganti
This document discusses various C programming concepts related to structures, unions, enumerations, and typedef. It provides definitions and examples of each concept. Structures allow grouping of different data types under a single name. Unions share the same memory location for members. Enumerations define a user-defined data type of integer constants. Typedef allows defining an alias for existing data types. The document also discusses accessing structure members, nested structures, arrays of structures, passing structures to functions, self-referential structures, and bit fields.
data structure and c programing conceptskavitham66441
A structure allows grouping of different data types under a single name. It can be used to represent a record by defining members for each attribute. Structures support defining arrays of structures to group multiple records together. Unions share memory between members and only one member can be accessed at a time, while structures have independent memory for each member. Pointers store the address of a variable and allow dynamic memory allocation by changing which variable an address points to.
Structures-Declaring and Initializing, Nested structure, Array of Structure, Passing Structures to functions, Unions, typedef, enum, Bit fields.
Pointers: Declarations, Pointer arithmetic, Pointers and functions, call by value, Call by reference, Pointers and Arrays, Arrays of Pointers, Pointers and Structures. Meaning of static and dynamic memory allocation, Memory allocation functions.
Files: File modes, File functions, and File operations, Text and Binary files, Command Line arguments Preprocessor directives. Macros: Definition, types of Macros, Creating and implementing user defined header files
COURSE TITLE: SOFTWARE DEVELOPMENT VI
COURSE CODE: VIT 351
TOPICS COVERED:
USER DEFINED DATATYPES
STRUCTURE
UNION
TYPEDEF
DIFFERENCE BETWEEN STRUCTURE AND UNION
ENUMERATION (ENUM)
QUIZ SET 4
The document discusses structures and unions in C programming. It defines a structure as a user-defined data type that allows storing heterogeneous data under a single name. Structures contain members that can be accessed using the dot operator. Arrays of structures allow storing multiple records of the same type. Structures can be nested by defining a structure member within another structure. Unions allow storing different types of data in the same memory location, but only one member can be accessed at a time. Examples are provided to demonstrate defining, declaring, and accessing structure and union variables as well as nested structures.
This document discusses using structures in C programming to store student records. It defines a student structure with roll number, name, and marks members. A program is provided that uses a structure array to store records for 10 students, reading input and then displaying the stored information. The key aspects of defining structures, declaring structure variables, accessing structure members, and allocating structure memory are explained. Sample problems are given to practice using structures to store book information and add distances.
The document discusses structures and unions in C programming. It defines a structure as a user-defined data type that groups together related data of different types under a single name. A union is similar to a structure but can only store one data member at a time as it allocates memory for the largest data type. The key points covered include declaring and initializing structures and unions, accessing structure members, arrays of structures, structures within structures, and comparing structures and unions.
This document discusses structures in C programming. It defines a structure as a collection of different data types grouped together. Each element in a C structure is called a member. Structures allow storing of different data types under one name. Some key points covered include declaring and initializing structures, accessing structure members, nested structures, array of structures, passing structures to functions, and using structures with pointers and typedef. Examples are provided to demonstrate these concepts.
The document discusses structures in C programming. It defines structures as a way to pack together logically related data items of different types. Some key points:
- Structures allow defining custom data types that group together members of integer, float, character, and other standard types.
- Structure variables are declared and members accessed using the dot operator. Arrays of structures can also be defined.
- Structures can be initialized in various ways and passed to functions by value or by reference.
- Nested structures, where one structure is defined as a member of another, are also supported.
The document also covers arrays of structures, passing structures to functions, user-defined data types using typedef and enums,
The document provides an overview of object-oriented programming concepts in C++. It discusses key OOP concepts like objects, classes, encapsulation, inheritance and polymorphism. It also covers procedural programming in C++ and compares it with OOP. Examples are provided to demonstrate creating classes, objects, functions, constructors and destructors. The document contains information on basic C++ programming concepts needed to understand and implement OOP principles in C++ programs.
The document discusses features of object identity, the role of OIDs, value and type constructors, and provides examples of valid time tables, transaction time tables, and bitemporal tables. It also discusses creating tables with employee data and calculating salaries, and compares intelligent databases with temporal databases.
Structures allow users to define custom data types that can store multiple related data items under one name. Structures are useful for storing records like student records that contain related fields. Structures can contain basic data types as well as other structures, allowing for nested structures. Structures can be passed to functions by passing individual fields or the entire structure. Macros provide a way to define symbolic constants and perform simple text substitution before compilation.
This document provides an overview of the C++ programming language. It discusses key C++ concepts like classes, objects, functions, and data types. Some key points:
- C++ is an object-oriented language that is an extension of C with additional features like classes and inheritance.
- Classes allow programmers to combine data and functions to model real-world entities. Objects are instances of classes.
- The document defines common C++ terms like keywords, identifiers, constants, and operators. It also provides examples of basic programs.
- Functions are described as modular and reusable blocks of code. Parameter passing techniques like pass-by-value and pass-by-reference are covered.
- Other concepts covered include
Structures allow the grouping of different data types together under one name. They are useful for storing records with multiple related data fields, like a student record with a name, roll number, and marks. Structures can be initialized, passed to functions by value or reference, and used to create arrays of records. Unions share the same memory location for different member types, while structures allocate separate memory for each member.
- A structure in C is a user-defined data type that allows storing multiple data types together under one name.
- Structures can store different attributes like name, roll number, marks of a student entity together rather than separate arrays.
- Structures are defined using the struct keyword followed by the structure name and members.
- Structure variables can access members using dot (.) operator.
- Arrays of structures can store information of multiple entities. Structures can also be nested to store sub-parts of an attribute together.
pointer, structure ,union and intro to file handlingRai University
This document provides information on structures in C programming language. It defines a structure called "employee" to store details of employees like ID, name, salary etc. It demonstrates how to declare and initialize structure variables, access structure members, pass structures to functions, return structures from functions, and create arrays of structures. The full code for a sample program implementing structures to store and print details of two employees is also provided.
This document discusses nested structures and arrays of structures in C programming. It begins by explaining how one structure can be nested within another using separate or embedded structures. It then discusses how to access members of nested structures. The document also explains that an array of structures declares multiple elements of the same structure type. Elements can be accessed and initialized similarly to fundamental data types. It provides examples of declaring, defining, and accessing elements of nested structures and arrays of structures in C code.
Diploma ii cfpc- u-5.3 pointer, structure ,union and intro to file handlingRai University
The document discusses C programming concepts including data types, structures, unions, pointers, and file handling. It provides examples of defining and using structures and unions to organize related data. Structures allow grouping of different data types under one name, while unions allocate space of the largest member. Pointers and arrays of structures are also demonstrated. Functions can pass, return, and access values in structures.
● Concept of Structure and Union
● Declaration and Initialization of structure and union
● Nested structures
● Array of Structures
● Passing structure to functions
1. The document discusses different ways of creating custom data types in C++, including classes, structures, unions, enumerations, and typedef. Structures are collections of variables that can be referenced under one name.
2. Technically, there is no difference between a structure and a class in C++ - structures are classes with members that are public by default, while classes have private members by default.
3. Structures allow logically related elements to be treated as a single unit, for example to store student information. Arrays can contain elements of a structure type.
Introduction to structures in c lang.pptshivani366010
Structures allow grouping of related data types together under one name. Structures can contain members of different data types. Structures are defined using the struct keyword and variables of structure types can be declared. Members of a structure are accessed using the dot (.) operator. Pointers to structures allow dynamic allocation of structures and accessing structure members using the arrow (->) operator. Arrays of structures help organize collections of related data records. Structures and pointers are useful for implementing linked lists and trees.
Structures allow grouping related data together under one name. Structures can contain members of different types. Struct members are accessed using the dot operator. Arrays of structures allow storing multiple struct records. Pointers to structures allow dynamically allocating struct records and accessing them using the arrow operator. Dynamic memory allocation functions like malloc() are used to allocate memory for structures from the heap at runtime.
Structures allow grouping of different data types under one name. To define a structure, the struct keyword is used followed by the structure tag name and a list of member variables enclosed in curly braces. Structures can be used to represent records in a database. Arrays of structures allow storing multiple records as array elements. Pointers to structures can be defined and used to access structure members using the arrow operator ->. Nested structures allow creating complex data types by defining one structure as a member of another structure.
The document discusses arrays and classes in C#. It describes that arrays are sequences of data of the same type that can be accessed by index. Classes define common behaviors and attributes with members that must have access modifiers. The document also explains properties of arrays like length, rank, and methods; and string class methods such as insert, length, copy, and compare.
The document discusses various topics in C programming including structures, unions, pointers, I/O statements, debugging, and testing techniques. It provides examples to explain structures as a way to represent records by combining different data types. Unions allow storing different data types in the same memory location. Pointers are variables that store memory addresses. I/O statements like printf and scanf are used for input and output. Debugging methods include detecting incorrect program behavior and fixing bugs. Testing and verification ensure programs are built correctly according to requirements.
The document discusses different data structures in C++ including structures, nested structures, typedef, enumerated data types, and macros. It explains that a structure allows grouping of related data types under one name and can be treated as a user-defined data type. It provides examples of declaring structure variables, defining members, and accessing members. Nested structures allow structures to be members of other structures. Typedef provides an alternative name for standard data types. Enumerated data types define a set of names mapped to integer constants. Macros allow defining symbolic names and constants using the #define preprocessor directive.
This document discusses structures in C programming. It defines a structure as a collection of different data types grouped together. Each element in a C structure is called a member. Structures allow storing of different data types under one name. Some key points covered include declaring and initializing structures, accessing structure members, nested structures, array of structures, passing structures to functions, and using structures with pointers and typedef. Examples are provided to demonstrate these concepts.
The document discusses structures in C programming. It defines structures as a way to pack together logically related data items of different types. Some key points:
- Structures allow defining custom data types that group together members of integer, float, character, and other standard types.
- Structure variables are declared and members accessed using the dot operator. Arrays of structures can also be defined.
- Structures can be initialized in various ways and passed to functions by value or by reference.
- Nested structures, where one structure is defined as a member of another, are also supported.
The document also covers arrays of structures, passing structures to functions, user-defined data types using typedef and enums,
The document provides an overview of object-oriented programming concepts in C++. It discusses key OOP concepts like objects, classes, encapsulation, inheritance and polymorphism. It also covers procedural programming in C++ and compares it with OOP. Examples are provided to demonstrate creating classes, objects, functions, constructors and destructors. The document contains information on basic C++ programming concepts needed to understand and implement OOP principles in C++ programs.
The document discusses features of object identity, the role of OIDs, value and type constructors, and provides examples of valid time tables, transaction time tables, and bitemporal tables. It also discusses creating tables with employee data and calculating salaries, and compares intelligent databases with temporal databases.
Structures allow users to define custom data types that can store multiple related data items under one name. Structures are useful for storing records like student records that contain related fields. Structures can contain basic data types as well as other structures, allowing for nested structures. Structures can be passed to functions by passing individual fields or the entire structure. Macros provide a way to define symbolic constants and perform simple text substitution before compilation.
This document provides an overview of the C++ programming language. It discusses key C++ concepts like classes, objects, functions, and data types. Some key points:
- C++ is an object-oriented language that is an extension of C with additional features like classes and inheritance.
- Classes allow programmers to combine data and functions to model real-world entities. Objects are instances of classes.
- The document defines common C++ terms like keywords, identifiers, constants, and operators. It also provides examples of basic programs.
- Functions are described as modular and reusable blocks of code. Parameter passing techniques like pass-by-value and pass-by-reference are covered.
- Other concepts covered include
Structures allow the grouping of different data types together under one name. They are useful for storing records with multiple related data fields, like a student record with a name, roll number, and marks. Structures can be initialized, passed to functions by value or reference, and used to create arrays of records. Unions share the same memory location for different member types, while structures allocate separate memory for each member.
- A structure in C is a user-defined data type that allows storing multiple data types together under one name.
- Structures can store different attributes like name, roll number, marks of a student entity together rather than separate arrays.
- Structures are defined using the struct keyword followed by the structure name and members.
- Structure variables can access members using dot (.) operator.
- Arrays of structures can store information of multiple entities. Structures can also be nested to store sub-parts of an attribute together.
pointer, structure ,union and intro to file handlingRai University
This document provides information on structures in C programming language. It defines a structure called "employee" to store details of employees like ID, name, salary etc. It demonstrates how to declare and initialize structure variables, access structure members, pass structures to functions, return structures from functions, and create arrays of structures. The full code for a sample program implementing structures to store and print details of two employees is also provided.
This document discusses nested structures and arrays of structures in C programming. It begins by explaining how one structure can be nested within another using separate or embedded structures. It then discusses how to access members of nested structures. The document also explains that an array of structures declares multiple elements of the same structure type. Elements can be accessed and initialized similarly to fundamental data types. It provides examples of declaring, defining, and accessing elements of nested structures and arrays of structures in C code.
Diploma ii cfpc- u-5.3 pointer, structure ,union and intro to file handlingRai University
The document discusses C programming concepts including data types, structures, unions, pointers, and file handling. It provides examples of defining and using structures and unions to organize related data. Structures allow grouping of different data types under one name, while unions allocate space of the largest member. Pointers and arrays of structures are also demonstrated. Functions can pass, return, and access values in structures.
● Concept of Structure and Union
● Declaration and Initialization of structure and union
● Nested structures
● Array of Structures
● Passing structure to functions
1. The document discusses different ways of creating custom data types in C++, including classes, structures, unions, enumerations, and typedef. Structures are collections of variables that can be referenced under one name.
2. Technically, there is no difference between a structure and a class in C++ - structures are classes with members that are public by default, while classes have private members by default.
3. Structures allow logically related elements to be treated as a single unit, for example to store student information. Arrays can contain elements of a structure type.
Introduction to structures in c lang.pptshivani366010
Structures allow grouping of related data types together under one name. Structures can contain members of different data types. Structures are defined using the struct keyword and variables of structure types can be declared. Members of a structure are accessed using the dot (.) operator. Pointers to structures allow dynamic allocation of structures and accessing structure members using the arrow (->) operator. Arrays of structures help organize collections of related data records. Structures and pointers are useful for implementing linked lists and trees.
Structures allow grouping related data together under one name. Structures can contain members of different types. Struct members are accessed using the dot operator. Arrays of structures allow storing multiple struct records. Pointers to structures allow dynamically allocating struct records and accessing them using the arrow operator. Dynamic memory allocation functions like malloc() are used to allocate memory for structures from the heap at runtime.
Structures allow grouping of different data types under one name. To define a structure, the struct keyword is used followed by the structure tag name and a list of member variables enclosed in curly braces. Structures can be used to represent records in a database. Arrays of structures allow storing multiple records as array elements. Pointers to structures can be defined and used to access structure members using the arrow operator ->. Nested structures allow creating complex data types by defining one structure as a member of another structure.
The document discusses arrays and classes in C#. It describes that arrays are sequences of data of the same type that can be accessed by index. Classes define common behaviors and attributes with members that must have access modifiers. The document also explains properties of arrays like length, rank, and methods; and string class methods such as insert, length, copy, and compare.
The document discusses various topics in C programming including structures, unions, pointers, I/O statements, debugging, and testing techniques. It provides examples to explain structures as a way to represent records by combining different data types. Unions allow storing different data types in the same memory location. Pointers are variables that store memory addresses. I/O statements like printf and scanf are used for input and output. Debugging methods include detecting incorrect program behavior and fixing bugs. Testing and verification ensure programs are built correctly according to requirements.
The document discusses different data structures in C++ including structures, nested structures, typedef, enumerated data types, and macros. It explains that a structure allows grouping of related data types under one name and can be treated as a user-defined data type. It provides examples of declaring structure variables, defining members, and accessing members. Nested structures allow structures to be members of other structures. Typedef provides an alternative name for standard data types. Enumerated data types define a set of names mapped to integer constants. Macros allow defining symbolic names and constants using the #define preprocessor directive.
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...Social Samosa
The Modern Marketing Reckoner (MMR) is a comprehensive resource packed with POVs from 60+ industry leaders on how AI is transforming the 4 key pillars of marketing – product, place, price and promotions.
Open Source Contributions to Postgres: The Basics POSETTE 2024ElizabethGarrettChri
Postgres is the most advanced open-source database in the world and it's supported by a community, not a single company. So how does this work? How does code actually get into Postgres? I recently had a patch submitted and committed and I want to share what I learned in that process. I’ll give you an overview of Postgres versions and how the underlying project codebase functions. I’ll also show you the process for submitting a patch and getting that tested and committed.
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...Kaxil Naik
Navigating today's data landscape isn't just about managing workflows; it's about strategically propelling your business forward. Apache Airflow has stood out as the benchmark in this arena, driving data orchestration forward since its early days. As we dive into the complexities of our current data-rich environment, where the sheer volume of information and its timely, accurate processing are crucial for AI and ML applications, the role of Airflow has never been more critical.
In my journey as the Senior Engineering Director and a pivotal member of Apache Airflow's Project Management Committee (PMC), I've witnessed Airflow transform data handling, making agility and insight the norm in an ever-evolving digital space. At Astronomer, our collaboration with leading AI & ML teams worldwide has not only tested but also proven Airflow's mettle in delivering data reliably and efficiently—data that now powers not just insights but core business functions.
This session is a deep dive into the essence of Airflow's success. We'll trace its evolution from a budding project to the backbone of data orchestration it is today, constantly adapting to meet the next wave of data challenges, including those brought on by Generative AI. It's this forward-thinking adaptability that keeps Airflow at the forefront of innovation, ready for whatever comes next.
The ever-growing demands of AI and ML applications have ushered in an era where sophisticated data management isn't a luxury—it's a necessity. Airflow's innate flexibility and scalability are what makes it indispensable in managing the intricate workflows of today, especially those involving Large Language Models (LLMs).
This talk isn't just a rundown of Airflow's features; it's about harnessing these capabilities to turn your data workflows into a strategic asset. Together, we'll explore how Airflow remains at the cutting edge of data orchestration, ensuring your organization is not just keeping pace but setting the pace in a data-driven future.
Session in https://budapestdata.hu/2024/04/kaxil-naik-astronomer-io/ | https://dataml24.sessionize.com/session/667627
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...Aggregage
This webinar will explore cutting-edge, less familiar but powerful experimentation methodologies which address well-known limitations of standard A/B Testing. Designed for data and product leaders, this session aims to inspire the embrace of innovative approaches and provide insights into the frontiers of experimentation!
1. Data Types
C language has built-in datatypes like primary and derived data types.
But, still not all real world problems can be solved using those data types.
We need custom datatype for different situation.
Data types are defined as the data storage format that a variable can store a data.
Data types in C
Primary Data type
(int, float, char)
Secondary Data type
Derived Data type
(array, pointer)
User defined Data type
(structure, union, enum)
2. User Defined Datatype
We need combination of various datatypes to understand different entity/object.
Example-1:
Book Title: Let Us C Datatype: char / string
Author: Yashavant Kanetkar Datatype: char / string
Page: 320 Datatype: int
Price: 255.00 Datatype: float
Example-2:
Student Name: ABC Datatype: char / string
Roll_No: 180540107001 Datatype: int
CPI: 7.46 Datatype: float
Backlog: 01 Datatype: int
3. What is Structure?
Structure is a collection of logically related data items of different datatypes
grouped together under single name.
Structure is a user defined datatype.
Structure helps to build a complex datatype which is more meaningful than an
array.
But, an array holds similar datatype record, when structure holds different
datatypes records.
Two fundamental aspects of Structure:
Declaration of Structure Variable
Accessing of Structure Member
4. Syntax to Define Structure
To define a structure, we need to use struct keyword.
This keyword is reserved word in C language. We can only use it for structure and
its object declaration.
structure_name is name of custom type
memberN_declaration is individual member
declaration
Members can be normal variables, pointers, arrays or other structures.
Member names within the particular structure must be distinct from one another.
struct structure_name
{
member1_declaration;
member2_declaration;
. . .
memberN_declaration;
};
1
2
3
4
5
6
7
Syntax
5. Example to Define Structure
You must terminate structure definition with semicolon ;.
You cannot assign value to members inside the structure definition, it will cause
compilation error.
struct student
{
char name[30]; // Student Name
int roll_no; // Student Roll No
float CPI; // Student CPI
int backlog; // Student Backlog
};
1
2
3
4
5
6
7
struct student
{
char name[30] = “ABC”; // Student Name
. . .
};
1
2
3
4
5
Example
Example
6. Create Structure variable
A data type defines various properties about data stored in memory.
To use any type we must declare its variable.
Hence, let us learn how to create our custom structure type objects also known
as structure variable.
In C programming, there are two ways to declare a structure variable:
1. Along with structure definition
2. After structure definition
7. Create Structure Variable – Cont.
1. Declaration along with the structure definition
struct structure_name
{
member1_declaration;
member2_declaration;
. . .
memberN_declaration;
} structure_variable;
1
2
3
4
5
6
7
struct student
{
char name[30]; // Student Name
int roll_no; // Student Roll No
float CPI; // Student CPI
int backlog; // Student Backlog
} student1;
1
2
3
4
5
6
7
Example
Syntax
8. Create Structure Variable – Cont.
2. Declaration after Structure definition
struct structure_name structure_variable;
1
struct student
{
char name[30]; // Student Name
int roll_no; // Student Roll No
float CPI; // Student CPI
int backlog; // Student Backlog
};
struct student student1; // Declare structure variable
1
2
3
4
5
6
7
8
Example
Syntax
9. Access Structure member (data)
Structure is a complex data type, we cannot assign any value directly to it
using assignment operator.
We must assign data to individual structure members separately.
C supports two operators to access structure members, using a structure variable.
1. Dot/period operator (.)
2. Arrow operator (->)
10. Access Structure member (data) – Cont.
1. Dot/period operator (.)
It is known as member access operator. We use dot operator to access members of simple
structure variable.
2. Arrow operator (->)
In C language it is illegal to access a structure member from a pointer to structure variable
using dot operator.
We use arrow operator to access structure member from pointer to structure.
structure_variable.member_name;
1 // Assign CPI of student1
student1.CPI = 7.46;
1
2
pointer_to_structure->member_name;
1 // Student1 is a pointer to student type
student1 -> CPI = 7.46;
1
2
Syntax
Syntax
Example
Example
11. WAP to print Odd numbers between 1 to n
#include <stdio.h>
struct student
{
char name[40]; // Student name
int roll; // Student enrollment
float CPI; // Student mobile number
int backlog;
};
int main()
{
struct student student1; // Simple structure variable
// Input data in structure members using dot operator
printf("Enter Student Name:");
scanf("%s", student1.name);
printf("Enter Student Roll Number:");
scanf("%d", &student1.roll);
printf("Enter Student CPI:");
scanf("%f", &student1.CPI);
printf("Enter Student Backlog:");
scanf("%d", &student1.backlog);
// Display data in structure members using dot operator
printf("nStudent using simple structure variable.n");
printf("Student name: %sn", student1.name);
printf("Student Enrollment: %dn", student1.roll);
printf("Student CPI: %fn", student1.CPI);
printf("Student Backlog: %in", student1.backlog);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Enter Student Name:aaa
Enter Student Roll Number:111
Enter Student CPI:7.89
Enter Student Backlog:0
Student using simple structure variable.
Student name: aaa
Student Enrollment: 111
Student CPI: 7.890000
Student Backlog: 0
Program Output
Write a program to read and display student information using structure.
12. WAP to print Odd numbers between 1 to n
#include<stdio.h>
struct time {
int hours;
int minutes;
int seconds;
};
int main() {
struct time t1,t2;
int h, m, s;
//1st time
printf ("Enter 1st time.");
printf ("nEnter Hours: ");
scanf ("%d",&t1.hours);
printf ("Enter Minutes: ");
scanf ("%d",&t1.minutes);
printf ("Enter Seconds: ");
scanf ("%d",&t1.seconds);
printf ("The Time is
%d:%d:%d",t1.hours,t1.minutes,t1.seconds);
//2nd time
printf ("nnEnter the 2nd time.");
printf ("nEnter Hours: ");
scanf ("%d",&t2.hours);
printf ("Enter Minutes: ");
scanf ("%d",&t2.minutes);
printf ("Enter Seconds: ");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Enter 1st time.
Enter Hours: 1
Enter Minutes: 20
Enter Seconds: 20
The Time is 1:20:20
Enter the 2nd time.
Enter Hours: 2
Enter Minutes: 10
Enter Seconds: 10
The Time is 2:10:10
Sum of the two time's is 3:30:30
Program
Output
Write a program to declare time structure and read two different time period and display sum of it.
scanf ("%d",&t2.seconds);
printf ("The Time is
%d:%d:%d",t2.hours,t2.minutes,t2.seco
nds);
h = t1.hours + t2.hours;
m = t1.minutes + t2.minutes;
s = t1.seconds + t2.seconds;
printf ("nSum of the two time's is
%d:%d:%d",h,m,s);
return 0;
}
27
28
29
30
31
32
33
34
35
36
37
13. Array of Structure
It can be defined as the collection of multiple structure variables where each
variable contains information about different entities.
The array of structures in C are used to store information about multiple entities of
different data types.
struct structure_name
{
member1_declaration;
member2_declaration;
...
memberN_declaration;
} structure_variable[size];
1
2
3
4
5
6
7
Syntax
14. WAP to print Odd numbers between 1 to n
#include<stdio.h>
struct student {
char name[20];
int rollno;
float cpi;
};
int main( ) {
int i,n;
printf("Enter how many records u want to store : ");
scanf("%d",&n);
struct student sarr[n];
for(i=0; i<n; i++)
{
printf("nEnter %d record : n",i+1);
printf("Enter Name : ");
scanf("%s",sarr[i].name);
printf("Enter RollNo. : ");
scanf("%d",&sarr[i].rollno);
printf("Enter CPI : ");
scanf("%f",&sarr[i].cpi);
}
printf("ntNametRollNotMarkstn");
for(i=0; i<n; i++) {
printf("t%stt%dtt%.2ftn", sarr[i].name,
sarr[i].rollno, sarr[i].cpi);
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Enter how many records u want to store : 3
Enter 1 record :
Enter Name : aaa
Enter RollNo. : 111
Enter CPI : 7.89
Enter 2 record :
Enter Name : bbb
Enter RollNo. : 222
Enter CPI : 7.85
Enter 3 record :
Enter Name : ccc
Enter RollNo. : 333
Enter CPI : 8.56
Name RollNo Marks
aaa 111 7.89
bbb 222 7.85
ccc 333 8.56
Program
Output
Write a program to read and display N student information using array of structure.
15. WAP to print Odd numbers between 1 to n
#include<stdio.h>
struct Time {
int hours;
int minutes;
int seconds;
};
struct Time input(); // function declaration
int main()
{
struct Time t;
t=input();
printf("Hours : Minutes : Secondsn %d : %d :
%d",t.hours,t.minutes,t.seconds);
return 0;
}
struct Time input() // function definition
{
struct Time tt;
printf ("Enter Hours: ");
scanf ("%d",&tt.hours);
printf ("Enter Minutes: ");
scanf ("%d",&tt.minutes);
printf ("Enter Seconds: ");
scanf ("%d",&tt.seconds);
return tt; // return structure variable
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Enter Hours: 1
Enter Minutes: 20
Enter Seconds: 20
Hours : Minutes : Seconds
1 : 20 : 20
Program
Output
Write a program to declare time structure and read two different time period and display sum of it using function.
16. Structure using Pointer
Reference/address of structure object is passed as function argument to the definition of function.
#include <stdio.h>
struct student {
char name[20];
int rollno;
float cpi;
};
int main()
{
struct student *studPtr, stud1;
studPtr = &stud1;
printf("Enter Name: ");
scanf("%s", studPtr->name);
printf("Enter RollNo: ");
scanf("%d", &studPtr->rollno);
printf("Enter CPI: ");
scanf("%f", &studPtr->cpi);
printf("nStudent Details:n");
printf("Name: %sn", studPtr->name);
printf("RollNo: %d", studPtr->rollno);
printf(”nCPI: %f", studPtr->cpi);
return 0;
}
Enter Name: ABC
Enter RollNo: 121
Enter CPI: 7.46
Student Details:
Name: ABC
RollNo: 121
CPI: 7.460000
Program Output
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
17. Nested Structure
When a structure contains another structure, it is called nested structure.
For example, we have two structures named Address and Student. To make Address nested
to Student, we have to define Address structure before and outside Student structure and
create an object of Address structure inside Student structure.
struct structure_name1
{
member1_declaration;
member2_declaration;
...
memberN_declaration;
};
struct structure_name2
{
member1_declaration;
member2_declaration;
...
struct structure1 obj;
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Syntax
18. #include<stdio.h>
struct Address
{
char HouseNo[25];
char City[25];
char PinCode[25];
};
struct Student
{
char name[25];
int roll;
float cpi;
struct Address Add;
};
int main()
{
int i;
struct Student s;
printf("ntEnter Student Name : ");
scanf("%s",s.name);
printf("ntEnter Student Roll Number : ");
scanf("%d",&s.roll);
printf("ntEnter Student CPI : ");
scanf("%f",&s.cpi);
printf("ntEnter Student House No : ");
scanf("%s",s.Add.HouseNo);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Details of Students
Student Name : aaa
Student Roll Number : 111
Student CPI : 7.890000
Student House No : 39
Student City : rajkot
Student Pincode : 360001
Program
Output
Write a program to read and display student information using nested of structure.
printf("ntEnter Student City : ");
scanf("%s",s.Add.City);
printf("ntEnter Student Pincode : ");
scanf("%s",s.Add.PinCode);
printf("nDetails of Students");
printf("ntStudent Name : %s",s.name);
printf("ntStudent Roll Number :
%d",s.roll);
printf("ntStudent CPI : %f",s.cpi);
printf("ntStudent House No :
%s",s.Add.HouseNo);
printf("ntStudent City :
%s",s.Add.City);
printf("ntStudent Pincode :
%s",s.Add.PinCode);
return 0;
}
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
19. Practice Programs
1. Define a structure data type called time_struct containing three member’s integer hours, minutes, second.
Develop a program that would assign values to individual member and display the time in following format :
HH:MM:SS
2. WAP to create structure of book with book title, author name, publication, and price. Read data of n books
and display them.
3. Define a structure Person that would contain person name, date of joining, and salary using this structure to
read this information of 5 people and print the same on screen.
4. Define a structure time_struct containing three member’s integer hour, integer minute and integer second.
WAP that would assign values to the individual number and display the time in the following format: 16: 40:
51.
5. Define a structure cricket that will describe the following information:
Player name
Team name
Batting average
6. Using cricket, declare an array player with 50 elements and WAP to read the information about all the 50
players and print team wise list containing names of players with their batting average.
7. Define a structure student_record to contain name, branch, and total marks obtained. WAP to read data for
10 students in a class and print them.