SlideShare a Scribd company logo
Lecturer, B V Patel Inst. of BMC & IT, GopalVidyanagar




                       STRUCTURE IN ‘C’
Prakash Khaire
Prakash Khaire   Lecturer, B V Patel Inst. of BMC & IT, GopalVidyanagar
Structure in C
●Array is collection of items with identical data type
●C Supports a constructed data type known as
structure
●It is user-defined data type
●It wraps different data type
●It is way of extending new programming language

    Prakash
    Prakash Khaire   Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar
                     Lecturer, B V Patel Inst. of IT, GopalVidyanagar
    Khaire
Definition - Structure
●A structure is collections of more than one variables with
different data type like int, float & char
Example :
char name[25];
int sci, eng, maths;
float per;



Prakash
Prakash Khaire   Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar
                 Lecturer, B V Patel Inst. of IT, GopalVidyanagar
Khaire
Defining a structure
●General form or syntax
struct tag_name                                  Structure tag name
{
    datatype variable;
    datatype variable;
        datatype variable;                 structure elements
        ---------------------
        ---------------------
} list of variables;                            Structure Variables



Prakash
Prakash Khaire   Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar
                 Lecturer, B V Patel Inst. of IT, GopalVidyanagar
Khaire
Example
struct book_bank                   void main()
{                                  {
     char title[20];                 struct book_bank x,y, MyBooks[5];
                                     int i,j;
   char author[15];                  clrscr();
   int pages;                        ---------------
   float price;                      ---------------
                                     ---------------
};                                   getch();
                                   }

Prakash
Prakash Khaire   Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar
                 Lecturer, B V Patel Inst. of IT, GopalVidyanagar
Khaire
Declaring structure variables
   We can declare a structure variable only when a structure is
   ●

defined
   Declaration of structure variable is similar to the declaration
   ●

of variable of any other data type
   It includes following points.
   ●
       ●The keyword struct
       ●The structure tag name

       ●List of variable names separated by commas

       ●A terminating semicolon


   ●For example
       struct book_bank book1, book2, book3;
       ●




Prakash
Prakash Khaire   Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar
                 Lecturer, B V Patel Inst. of IT, GopalVidyanagar
Khaire
Structures in C
●Members of the structure are themselves not a
variable. They do not occupy any memory and
till associate with structure variable as book.
●A structure is usually defines before main along
with macro definitions.
●  In such cases the structure assumes global
status and all the functions can access the
structure.
Prakash
Prakash Khaire   Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar
                 Lecturer, B V Patel Inst. of IT, GopalVidyanagar
Khaire
Accessing Structure Members
The link between a member and a variable is established using the
●


member operator ‘.’ Which is known as dot operator or period operator.
For example:
Book1.price

Is the variable representing the price of book1 and can be treated like any
●


other ordinary variable. We can use scanf statement to assign values like

scanf(“%s”,book1.file);
scanf(“%d”,&book1.pages);

Prakash
Prakash Khaire   Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar
                 Lecturer, B V Patel Inst. of IT, GopalVidyanagar
Khaire
Accessing Structure Members
We can assign variables to the members of book1
●




strcpy(book1.title,”Programming ANSI C”);
strcpy(book1.author,”Balagurusamy”);
book1.pages=250;
book1.price=28.50;



Prakash
Prakash Khaire   Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar
                 Lecturer, B V Patel Inst. of IT, GopalVidyanagar
Khaire
Structure Initialization
Like other data type we can initialize structure when we declare them
●


   A structure variable can be initialized at compile time
    struct book_bank
    {
           char title[20];
        char author[15];
        int pages;
        float price;
     } book1={“ANSI C”,”Balaguruswamy”,430,200.0};
    or struct book_bank book1 = {“ANSI C”,”Balaguruswamy”,430,200.0};



Prakash
Prakash Khaire   Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar
                 Lecturer, B V Patel Inst. of IT, GopalVidyanagar
Khaire
Structure Initialization
C language does not permit the initialization of individual
●


structure members within the template.
At compile time initialization of structure variable must
●


have the following elements
1. The Keyword struct
2. The structure tag name
3. The name of the variable to be declared
4. The assignment operator
5. A set of values for the members of the structure variable, separated by commas and enclosed in
braces
6. A terminating semicolon

Prakash
Prakash Khaire     Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar
                   Lecturer, B V Patel Inst. of IT, GopalVidyanagar
Khaire
Rules for initializing structure
●We cannot initialize individual members inside the structure template
●The order of values enclosed in braces must match the order of
members in the structure definition
●It is permitted to have partial initilization. We can initialize only the first
few members and leave the remaining blank. The uninitialized
members should be only at the end of the list.
●The uninitialized members will be assigned default values as follows.
●Zero for integer and floating point numbers

●‘0’ for characters and strings




Prakash
Prakash Khaire   Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar
                 Lecturer, B V Patel Inst. of IT, GopalVidyanagar
Khaire
Copying and Comparing Structure
Variables
Two variables of the same structure type can be
●


copied the same way as ordinary variables
book1 = book2;
There is no way to compare entire structure, we
●


can only compare element by element
/* this is not allowed */
if(book1==book2) /* this is not allowed */;
/* where as we can compare element by element */
if(book1.pages == book2.pages);
Prakash
Prakash Khaire   Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar
                 Lecturer, B V Patel Inst. of IT, GopalVidyanagar
Khaire
Structure in C
  Entire structures (not just pointers to structures)
   ●


may be passed as function arguments, assigned to
variables, etc.
  Interestingly, they cannot be compared using ==
   ●


  Unlike arrays, structures must be defined before, its
   ●


variable are used


Prakash
Prakash Khaire   Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar
                 Lecturer, B V Patel Inst. of IT, GopalVidyanagar
Khaire
Array of structure
●Like array of int, float or char, we can also have array of structure
●We can use single-dimensional or multi-dimensional arrays
●Example
struct student
{                                      Subject contains three elements,
    char name[20];                          subject[0], subject[1] and subject[2].
      char city[15];                        These elements can be accessed as
      int subject[3];                       followed
      float per;                            stud[1].subject[2]
}stud[10];                                  This will refer to the marks of third
                                            subject of second student


Prakash Khaire   Lecturer, B V Patel Inst. of BMC & IT, GopalVidyanagar
Structures within structure
Structure within structure is known as nested structure
●



     struct date                                            struct company
     { // members of structure                              {
          int day;                                               char name[20];
          int month;                                             long int employee_id;
          int year;                                              char sex[5];
     };                                                          int age;
     struct company
     {                                                           struct
         char name[20];                                          {
         long int employee_id;                                       int day;
         char sex[5];                                                int month;
         int age;                                                    int year;
         struct date dob;                                       }dob;
     };                                                     }employee;
Prakash Khaire      Lecturer, B V Patel Inst. of BMC & IT, GopalVidyanagar
Structure within structure
An inner most member in a nested structure
●


can be accessed by chaining all the
concerned structure variables with the
member using dot operator.

Example
●




employee.dob.day
employee.dob.month
employee.dob.year


Prakash Khaire   Lecturer, B V Patel Inst. of BMC & IT, GopalVidyanagar
typedef Declaration
It stands for "type definition"
●


keyword allows the programmer to create new
●


names for types such as int or, more
It refers to definition of data types which can be
●


used by the users to declare their own data
definitions names.

Prakash
Prakash Khaire   Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar
                 Lecturer, B V Patel Inst. of IT, GopalVidyanagar
Khaire
syntax
●So, how do you actually declare a typedef? All you must do is provide
the old type name followed by the type that should represent it
throughout the code. Here's how you would declare size_t to be an
unsigned integer
●   typedef unsigned int size_t;




Prakash
Prakash Khaire   Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar
                 Lecturer, B V Patel Inst. of IT, GopalVidyanagar
Khaire

More Related Content

What's hot

Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures
topu93
 
Structure & Union in C++
Structure & Union in C++Structure & Union in C++
Structure & Union in C++
Davinder Kaur
 
Structure in C
Structure in CStructure in C
Structure in C
Kamal Acharya
 
Structure & union
Structure & unionStructure & union
Structure & union
Rupesh Mishra
 
Structures
StructuresStructures
Structures
archikabhatia
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
tanmaymodi4
 
C programing -Structure
C programing -StructureC programing -Structure
C programing -Structure
shaibal sharif
 
C# program structure
C# program structureC# program structure
Structures
StructuresStructures
Structure in c
Structure in cStructure in c
Structure in c
Samsil Arefin
 
C Structures And Unions
C  Structures And  UnionsC  Structures And  Unions
C Structures And Unions
Ram Sagar Mourya
 
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Smit Shah
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
Rai University
 
CPU : Structures And Unions
CPU : Structures And UnionsCPU : Structures And Unions
CPU : Structures And Unions
Dhrumil Patel
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture
topu93
 
Structures and Pointers
Structures and PointersStructures and Pointers
Structures and Pointers
Prabu U
 
Structure in c#
Structure in c#Structure in c#
Structure in c#
Dr.Neeraj Kumar Pandey
 

What's hot (20)

Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures
 
Structure & Union in C++
Structure & Union in C++Structure & Union in C++
Structure & Union in C++
 
Structure in C
Structure in CStructure in C
Structure in C
 
Structure & union
Structure & unionStructure & union
Structure & union
 
Structures
StructuresStructures
Structures
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
C programing -Structure
C programing -StructureC programing -Structure
C programing -Structure
 
C# program structure
C# program structureC# program structure
C# program structure
 
Structures
StructuresStructures
Structures
 
Structure in c
Structure in cStructure in c
Structure in c
 
Unit4 C
Unit4 C Unit4 C
Unit4 C
 
C Structures And Unions
C  Structures And  UnionsC  Structures And  Unions
C Structures And Unions
 
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
 
CPU : Structures And Unions
CPU : Structures And UnionsCPU : Structures And Unions
CPU : Structures And Unions
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture
 
Structures and Pointers
Structures and PointersStructures and Pointers
Structures and Pointers
 
Structures in c++
Structures in c++Structures in c++
Structures in c++
 
Structures,pointers and strings in c Programming
Structures,pointers and strings in c ProgrammingStructures,pointers and strings in c Programming
Structures,pointers and strings in c Programming
 
Structure in c#
Structure in c#Structure in c#
Structure in c#
 

Viewers also liked

Structure in c
Structure in cStructure in c
Structure in c
Prabhu Govind
 
structure and union
structure and unionstructure and union
structure and unionstudent
 
C Structures & Unions
C Structures & UnionsC Structures & Unions
C Structures & Unions
Ram Sagar Mourya
 
Array in c language
Array in c languageArray in c language
Array in c languagehome
 
Basic C concepts.
Basic C concepts.Basic C concepts.
Basic C concepts.
Farooq Mian
 
Lecture 01 2017
Lecture 01 2017Lecture 01 2017
Lecture 01 2017
Jesmin Akhter
 
Lecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.pptLecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.ppt
eShikshak
 
Lecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.pptLecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.ppt
eShikshak
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
eShikshak
 
Html phrase tags
Html phrase tagsHtml phrase tags
Html phrase tags
eShikshak
 
Lecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operatorsLecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operators
eShikshak
 
Mesics lecture 3 c – constants and variables
Mesics lecture 3   c – constants and variablesMesics lecture 3   c – constants and variables
Mesics lecture 3 c – constants and variables
eShikshak
 
Lecture7relationalandlogicaloperators 110823181038-phpapp02
Lecture7relationalandlogicaloperators 110823181038-phpapp02Lecture7relationalandlogicaloperators 110823181038-phpapp02
Lecture7relationalandlogicaloperators 110823181038-phpapp02eShikshak
 
CHAPTER 3
CHAPTER 3CHAPTER 3
CHAPTER 3
mohd_mizan
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'
eShikshak
 
Algorithm
AlgorithmAlgorithm
Algorithm
eShikshak
 
Array within a class
Array within a classArray within a class
Array within a class
AAKASH KUMAR
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
eShikshak
 
Unit 1.3 types of cloud
Unit 1.3 types of cloudUnit 1.3 types of cloud
Unit 1.3 types of cloud
eShikshak
 
Mesics lecture 7 iteration and repetitive executions
Mesics lecture 7   iteration and repetitive executionsMesics lecture 7   iteration and repetitive executions
Mesics lecture 7 iteration and repetitive executions
eShikshak
 

Viewers also liked (20)

Structure in c
Structure in cStructure in c
Structure in c
 
structure and union
structure and unionstructure and union
structure and union
 
C Structures & Unions
C Structures & UnionsC Structures & Unions
C Structures & Unions
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Basic C concepts.
Basic C concepts.Basic C concepts.
Basic C concepts.
 
Lecture 01 2017
Lecture 01 2017Lecture 01 2017
Lecture 01 2017
 
Lecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.pptLecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.ppt
 
Lecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.pptLecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.ppt
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 
Html phrase tags
Html phrase tagsHtml phrase tags
Html phrase tags
 
Lecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operatorsLecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operators
 
Mesics lecture 3 c – constants and variables
Mesics lecture 3   c – constants and variablesMesics lecture 3   c – constants and variables
Mesics lecture 3 c – constants and variables
 
Lecture7relationalandlogicaloperators 110823181038-phpapp02
Lecture7relationalandlogicaloperators 110823181038-phpapp02Lecture7relationalandlogicaloperators 110823181038-phpapp02
Lecture7relationalandlogicaloperators 110823181038-phpapp02
 
CHAPTER 3
CHAPTER 3CHAPTER 3
CHAPTER 3
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
Array within a class
Array within a classArray within a class
Array within a class
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
 
Unit 1.3 types of cloud
Unit 1.3 types of cloudUnit 1.3 types of cloud
Unit 1.3 types of cloud
 
Mesics lecture 7 iteration and repetitive executions
Mesics lecture 7   iteration and repetitive executionsMesics lecture 7   iteration and repetitive executions
Mesics lecture 7 iteration and repetitive executions
 

Similar to Lecture18 structurein c.ppt

Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structures
Krishna Nanda
 
User defined data types.pptx
User defined data types.pptxUser defined data types.pptx
User defined data types.pptx
Ananthi Palanisamy
 
CP Handout#10
CP Handout#10CP Handout#10
CP Handout#10
trupti1976
 
Cs1123 12 structures
Cs1123 12 structuresCs1123 12 structures
Cs1123 12 structuresTAlha MAlik
 
358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7
sumitbardhan
 
Programming in C
Programming in CProgramming in C
Programming in C
MalathiNagarajan20
 
Structures
StructuresStructures
Structures
selvapon
 
Unit-V.pptx
Unit-V.pptxUnit-V.pptx
Unit-V.pptx
Mehul Desai
 
Lecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.pptLecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.ppt
eShikshak
 
CP01.pptx
CP01.pptxCP01.pptx
CP01.pptx
Pankaj Debbarma
 
Data Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self ReferentialData Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self Referential
babuk110
 
C programming structures & union
C programming structures & unionC programming structures & union
C programming structures & union
Bathshebaparimala
 
COM1407: Structures, Unions & Dynamic Memory Allocation
COM1407: Structures, Unions & Dynamic Memory Allocation COM1407: Structures, Unions & Dynamic Memory Allocation
COM1407: Structures, Unions & Dynamic Memory Allocation
Hemantha Kulathilake
 
Chapter 13.1.9
Chapter 13.1.9Chapter 13.1.9
Chapter 13.1.9patcha535
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2rohassanie
 
CHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptxCHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptx
GebruGetachew2
 
Structures
StructuresStructures
Structures
Mitali Chugh
 
Structures in C
Structures in CStructures in C
Structures in C
Nimrita Koul
 

Similar to Lecture18 structurein c.ppt (20)

Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structures
 
User defined data types.pptx
User defined data types.pptxUser defined data types.pptx
User defined data types.pptx
 
CP Handout#10
CP Handout#10CP Handout#10
CP Handout#10
 
Cs1123 12 structures
Cs1123 12 structuresCs1123 12 structures
Cs1123 12 structures
 
358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Structures
StructuresStructures
Structures
 
Unit-V.pptx
Unit-V.pptxUnit-V.pptx
Unit-V.pptx
 
Lecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.pptLecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.ppt
 
CP01.pptx
CP01.pptxCP01.pptx
CP01.pptx
 
Data Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self ReferentialData Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self Referential
 
C programming structures & union
C programming structures & unionC programming structures & union
C programming structures & union
 
Ch7 structures
Ch7 structuresCh7 structures
Ch7 structures
 
L6 structure
L6 structureL6 structure
L6 structure
 
COM1407: Structures, Unions & Dynamic Memory Allocation
COM1407: Structures, Unions & Dynamic Memory Allocation COM1407: Structures, Unions & Dynamic Memory Allocation
COM1407: Structures, Unions & Dynamic Memory Allocation
 
Chapter 13.1.9
Chapter 13.1.9Chapter 13.1.9
Chapter 13.1.9
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2
 
CHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptxCHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptx
 
Structures
StructuresStructures
Structures
 
Structures in C
Structures in CStructures in C
Structures in C
 

More from eShikshak

Modelling and evaluation
Modelling and evaluationModelling and evaluation
Modelling and evaluation
eShikshak
 
Operators in python
Operators in pythonOperators in python
Operators in python
eShikshak
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
eShikshak
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
eShikshak
 
Introduction to e commerce
Introduction to e commerceIntroduction to e commerce
Introduction to e commerce
eShikshak
 
Chapeter 2 introduction to cloud computing
Chapeter 2   introduction to cloud computingChapeter 2   introduction to cloud computing
Chapeter 2 introduction to cloud computing
eShikshak
 
Unit 1.4 working of cloud computing
Unit 1.4 working of cloud computingUnit 1.4 working of cloud computing
Unit 1.4 working of cloud computing
eShikshak
 
Unit 1.2 move to cloud computing
Unit 1.2   move to cloud computingUnit 1.2   move to cloud computing
Unit 1.2 move to cloud computing
eShikshak
 
Unit 1.1 introduction to cloud computing
Unit 1.1   introduction to cloud computingUnit 1.1   introduction to cloud computing
Unit 1.1 introduction to cloud computing
eShikshak
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
eShikshak
 
Mesics lecture 4 c operators and experssions
Mesics lecture  4   c operators and experssionsMesics lecture  4   c operators and experssions
Mesics lecture 4 c operators and experssionseShikshak
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’eShikshak
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
eShikshak
 
Lecture13 control statementswitch.ppt
Lecture13 control statementswitch.pptLecture13 control statementswitch.ppt
Lecture13 control statementswitch.ppt
eShikshak
 
Lecturer23 pointersin c.ppt
Lecturer23 pointersin c.pptLecturer23 pointersin c.ppt
Lecturer23 pointersin c.ppteShikshak
 
Lecture19 unionsin c.ppt
Lecture19 unionsin c.pptLecture19 unionsin c.ppt
Lecture19 unionsin c.ppteShikshak
 
Program development cyle
Program development cyleProgram development cyle
Program development cyle
eShikshak
 
Language processors
Language processorsLanguage processors
Language processorseShikshak
 
Computer programming programming_langugages
Computer programming programming_langugagesComputer programming programming_langugages
Computer programming programming_langugages
eShikshak
 

More from eShikshak (19)

Modelling and evaluation
Modelling and evaluationModelling and evaluation
Modelling and evaluation
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Introduction to e commerce
Introduction to e commerceIntroduction to e commerce
Introduction to e commerce
 
Chapeter 2 introduction to cloud computing
Chapeter 2   introduction to cloud computingChapeter 2   introduction to cloud computing
Chapeter 2 introduction to cloud computing
 
Unit 1.4 working of cloud computing
Unit 1.4 working of cloud computingUnit 1.4 working of cloud computing
Unit 1.4 working of cloud computing
 
Unit 1.2 move to cloud computing
Unit 1.2   move to cloud computingUnit 1.2   move to cloud computing
Unit 1.2 move to cloud computing
 
Unit 1.1 introduction to cloud computing
Unit 1.1   introduction to cloud computingUnit 1.1   introduction to cloud computing
Unit 1.1 introduction to cloud computing
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
 
Mesics lecture 4 c operators and experssions
Mesics lecture  4   c operators and experssionsMesics lecture  4   c operators and experssions
Mesics lecture 4 c operators and experssions
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
 
Lecture13 control statementswitch.ppt
Lecture13 control statementswitch.pptLecture13 control statementswitch.ppt
Lecture13 control statementswitch.ppt
 
Lecturer23 pointersin c.ppt
Lecturer23 pointersin c.pptLecturer23 pointersin c.ppt
Lecturer23 pointersin c.ppt
 
Lecture19 unionsin c.ppt
Lecture19 unionsin c.pptLecture19 unionsin c.ppt
Lecture19 unionsin c.ppt
 
Program development cyle
Program development cyleProgram development cyle
Program development cyle
 
Language processors
Language processorsLanguage processors
Language processors
 
Computer programming programming_langugages
Computer programming programming_langugagesComputer programming programming_langugages
Computer programming programming_langugages
 

Recently uploaded

From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 

Recently uploaded (20)

From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 

Lecture18 structurein c.ppt

  • 1. Lecturer, B V Patel Inst. of BMC & IT, GopalVidyanagar STRUCTURE IN ‘C’ Prakash Khaire Prakash Khaire Lecturer, B V Patel Inst. of BMC & IT, GopalVidyanagar
  • 2. Structure in C ●Array is collection of items with identical data type ●C Supports a constructed data type known as structure ●It is user-defined data type ●It wraps different data type ●It is way of extending new programming language Prakash Prakash Khaire Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar Lecturer, B V Patel Inst. of IT, GopalVidyanagar Khaire
  • 3. Definition - Structure ●A structure is collections of more than one variables with different data type like int, float & char Example : char name[25]; int sci, eng, maths; float per; Prakash Prakash Khaire Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar Lecturer, B V Patel Inst. of IT, GopalVidyanagar Khaire
  • 4. Defining a structure ●General form or syntax struct tag_name Structure tag name { datatype variable; datatype variable; datatype variable; structure elements --------------------- --------------------- } list of variables; Structure Variables Prakash Prakash Khaire Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar Lecturer, B V Patel Inst. of IT, GopalVidyanagar Khaire
  • 5. Example struct book_bank void main() { { char title[20]; struct book_bank x,y, MyBooks[5]; int i,j; char author[15]; clrscr(); int pages; --------------- float price; --------------- --------------- }; getch(); } Prakash Prakash Khaire Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar Lecturer, B V Patel Inst. of IT, GopalVidyanagar Khaire
  • 6. Declaring structure variables We can declare a structure variable only when a structure is ● defined Declaration of structure variable is similar to the declaration ● of variable of any other data type It includes following points. ● ●The keyword struct ●The structure tag name ●List of variable names separated by commas ●A terminating semicolon ●For example struct book_bank book1, book2, book3; ● Prakash Prakash Khaire Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar Lecturer, B V Patel Inst. of IT, GopalVidyanagar Khaire
  • 7. Structures in C ●Members of the structure are themselves not a variable. They do not occupy any memory and till associate with structure variable as book. ●A structure is usually defines before main along with macro definitions. ● In such cases the structure assumes global status and all the functions can access the structure. Prakash Prakash Khaire Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar Lecturer, B V Patel Inst. of IT, GopalVidyanagar Khaire
  • 8. Accessing Structure Members The link between a member and a variable is established using the ● member operator ‘.’ Which is known as dot operator or period operator. For example: Book1.price Is the variable representing the price of book1 and can be treated like any ● other ordinary variable. We can use scanf statement to assign values like scanf(“%s”,book1.file); scanf(“%d”,&book1.pages); Prakash Prakash Khaire Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar Lecturer, B V Patel Inst. of IT, GopalVidyanagar Khaire
  • 9. Accessing Structure Members We can assign variables to the members of book1 ● strcpy(book1.title,”Programming ANSI C”); strcpy(book1.author,”Balagurusamy”); book1.pages=250; book1.price=28.50; Prakash Prakash Khaire Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar Lecturer, B V Patel Inst. of IT, GopalVidyanagar Khaire
  • 10. Structure Initialization Like other data type we can initialize structure when we declare them ● A structure variable can be initialized at compile time struct book_bank { char title[20]; char author[15]; int pages; float price; } book1={“ANSI C”,”Balaguruswamy”,430,200.0}; or struct book_bank book1 = {“ANSI C”,”Balaguruswamy”,430,200.0}; Prakash Prakash Khaire Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar Lecturer, B V Patel Inst. of IT, GopalVidyanagar Khaire
  • 11. Structure Initialization C language does not permit the initialization of individual ● structure members within the template. At compile time initialization of structure variable must ● have the following elements 1. The Keyword struct 2. The structure tag name 3. The name of the variable to be declared 4. The assignment operator 5. A set of values for the members of the structure variable, separated by commas and enclosed in braces 6. A terminating semicolon Prakash Prakash Khaire Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar Lecturer, B V Patel Inst. of IT, GopalVidyanagar Khaire
  • 12. Rules for initializing structure ●We cannot initialize individual members inside the structure template ●The order of values enclosed in braces must match the order of members in the structure definition ●It is permitted to have partial initilization. We can initialize only the first few members and leave the remaining blank. The uninitialized members should be only at the end of the list. ●The uninitialized members will be assigned default values as follows. ●Zero for integer and floating point numbers ●‘0’ for characters and strings Prakash Prakash Khaire Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar Lecturer, B V Patel Inst. of IT, GopalVidyanagar Khaire
  • 13. Copying and Comparing Structure Variables Two variables of the same structure type can be ● copied the same way as ordinary variables book1 = book2; There is no way to compare entire structure, we ● can only compare element by element /* this is not allowed */ if(book1==book2) /* this is not allowed */; /* where as we can compare element by element */ if(book1.pages == book2.pages); Prakash Prakash Khaire Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar Lecturer, B V Patel Inst. of IT, GopalVidyanagar Khaire
  • 14. Structure in C Entire structures (not just pointers to structures) ● may be passed as function arguments, assigned to variables, etc. Interestingly, they cannot be compared using == ● Unlike arrays, structures must be defined before, its ● variable are used Prakash Prakash Khaire Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar Lecturer, B V Patel Inst. of IT, GopalVidyanagar Khaire
  • 15. Array of structure ●Like array of int, float or char, we can also have array of structure ●We can use single-dimensional or multi-dimensional arrays ●Example struct student { Subject contains three elements, char name[20]; subject[0], subject[1] and subject[2]. char city[15]; These elements can be accessed as int subject[3]; followed float per; stud[1].subject[2] }stud[10]; This will refer to the marks of third subject of second student Prakash Khaire Lecturer, B V Patel Inst. of BMC & IT, GopalVidyanagar
  • 16. Structures within structure Structure within structure is known as nested structure ● struct date struct company { // members of structure   { int day; char name[20]; int month; long int employee_id; int year; char sex[5]; }; int age; struct company { struct char name[20]; { long int employee_id; int day; char sex[5]; int month; int age; int year; struct date dob; }dob; }; }employee; Prakash Khaire Lecturer, B V Patel Inst. of BMC & IT, GopalVidyanagar
  • 17. Structure within structure An inner most member in a nested structure ● can be accessed by chaining all the concerned structure variables with the member using dot operator. Example ● employee.dob.day employee.dob.month employee.dob.year Prakash Khaire Lecturer, B V Patel Inst. of BMC & IT, GopalVidyanagar
  • 18. typedef Declaration It stands for "type definition" ● keyword allows the programmer to create new ● names for types such as int or, more It refers to definition of data types which can be ● used by the users to declare their own data definitions names. Prakash Prakash Khaire Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar Lecturer, B V Patel Inst. of IT, GopalVidyanagar Khaire
  • 19. syntax ●So, how do you actually declare a typedef? All you must do is provide the old type name followed by the type that should represent it throughout the code. Here's how you would declare size_t to be an unsigned integer ● typedef unsigned int size_t; Prakash Prakash Khaire Lecturer, B V Patel Inst. of BMC & BMC & IT, GopalVidyanagar Lecturer, B V Patel Inst. of IT, GopalVidyanagar Khaire