C Programming Lecture-13 Structures

Slides:



Advertisements
Similar presentations
EC-211 DATA STRUCTURES LECTURE 2. EXISTING DATA STRUCTURES IN C/C++ ARRAYS – A 1-D array is a finite, ordered set of homogeneous elements – E.g. int a[100]
Advertisements

Structures. An array allows us to store a collection of variables However, the variables must be of the same type to be stored in an array E.g. if we.
Programming C/C++ on Eclipe Trình bày : Ths HungNM C/C++ Training.
Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common.
More Storage Structures A Data Type Defined by You Characteristics of a variable of a specific ‘data type’ has specific values or range of values that.
Structures and Functions Ghulam Nasir Khan. Important /\/otes Programming is a fundamental course of IT as well as BICSE, so it will be very difficult.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
Object Oriented Programming (OOP) Lecture No. 8. Review ► Class  Concept  Definition ► Data members ► Member Functions ► Access specifier.
CSC241 Object-Oriented Programming (OOP) Lecture No. 4.
Array, Structure and Union
More C++ Features True object initialisation
© Oxford University Press All rights reserved. CHAPTER 8 STRUCTURES.
UNION UNIT -II. Unions A union is another compound datatype like a structure. So what is the properties of structure? Eg: Union exam { int roll_no; Char.
Introduction to Computers and Programming Class 24 Structures (structs) Professor Avi Rosenfeld.
STRUCTURES. INTRODUCTION A structure is same as that of records. It stores related information about an entity. Structure is basically a user defined.
Chapter 5 Arrays F Introducing Arrays F Declaring Array Variables, Creating Arrays, and Initializing Arrays F Passing Arrays to Methods F Copying Arrays.
Computer Programming II
Lecture 3 (UNIT -1) SUNIL KUMAR CIT-UPES.
2 Chapter Classes & Objects.
Chapter 10-1: Structure.
Program to search an element of array using linear search.
Chapter 7: Array.
TMF1414 Introduction to Programming
This technique is Called “Divide and Conquer”.
CS1010 Discussion Group 11 Week 12 – Structured Structures.
Visit for more Learning Resources
CS150 Introduction to Computer Science 1
Prepared By: G.UshaRani B.Pranalini A.S.Lalitha
Functions Dr. Ashish Sasankar. In programming, a function is a segment that groups code to perform a specific task. A C program has at least one function.
Structures.
Buy book Online -
Lecture 9 Structure 1. Concepts of structure Pointers of structures
S. Kiran, PGT (CS) KV, Malleswaram
Pointer to a Structure & Structure Containing a Pointer Difference Lesson xx  In this presentation, we will illustrate the difference between a pointer.
CS150 Introduction to Computer Science 1
Structure ការណែនាំអំពី Structure
Chapter 10: Records (structs)
More About Data Types & Functions
INC 161 , CPE 100 Computer Programming
Windows Programming Lecture 04
Starting to think about objects...
Dr. Bhargavi Dept of CS CHRIST
Local Variables, Global Variables and Variable Scope
Classes and Objects.
Chapter 1: Introduction to Data Structures(8M)
5th Chapter Pointers in C++.
Introduction to Programming
EGR 2261 Unit 12 structs Read Malik, Chapter 9.
Objectives In this chapter, you will: - Learn about records (structs) - Examine operations on a struct - Manipulate data using a struct - Learn about the.
Chapter 10 Structures and Unions
Strings and Pointer Arrays
Structure.
Object oriented programming (OOP) Lecture No. 7
C Programming Lecture-8 Pointers and Memory Management
Structures In C Programming By Rajanikanth B.
Submitted By : Veenu Saini Lecturer (IT)
C Programming Pointers
C Programming Lecture-14 Unions
Object Oriented Programming (OOP) Lecture No. 11
Structure (i.e. struct) An structure creates a user defined data type
CSCE 206 Lab Structured Programming in C
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Chapter 10 C Structures and Unions
User-defined data types
EECE.2160 ECE Application Programming
C Programming Lecture-17 Storage Classes
Object Oriented Programming (OOP) Lecture No. 12
Chapter 11 Structure and Union Types.
Introduction to Pointers
Programming Fundamental
Presentation transcript:

C Programming Lecture-13 Structures $p!derLabWeb C Programming Lecture-13 Structures

What is Structure? We have studied that the array is used to store the values of same datatype but suppose if we to store the data of different datatypes than we can’t use the arrays hence structure helps us to make a collection of data of different datatypes. Therefore, structure is the collection of values of different datatypes.

Defining a Structure To define a structure we use the keyword struct Syntax:- struct structure_name{ // list of variables of different datatypes. }; Eg. struct student{ int roll_no; char[80] name; };

Declaration of variable of defined structure Syntax :- struct structure_name var_name; Eg. struct student s1; // variable of student structure struct student s[5]; // array of student structure struct student *stu; // pointer to student structure

Initialization of variable of defined structure Syntax :- struct structure_name var_name = { list of values }; Eg. struct student s1 = { 1, “justine” }; struct student s1 = { 2, “john” }; struct student s1 = { 3, “monto” };

Accessing the Structure Members To access the variables or members of structure, we have to two ways :- -> when the variable of structure is trying to access the members of structure then we use the dot operator ( . ) Eg. struct student s1; s1.roll_no = 4; s1.name = “aman”;

-> when the pointer to structure is trying to access the members of structure then we use the arrow operator ( -> ). Eg. struct student *stu; stu->roll_no = 5; stu->name = “channi”;

Structure : User Defined Data Types Structure is collection of data of different datatypes so we can make many type of structure according to the requirement. And we are defining the structure with the use of primitive datatypes and then we use this structure to make variables. Hence we can say that structure is being used as the user defined datatypes.

Passing Structures as Function Arguments As structure is user defined datatypes we can use them as the normal datatypes. Hence for passing the structure as function arguments is no different. Syntax:- Return_type func_name ( struct struct_name var_name, list of variables ){ // body of function. }

Pointers to Structures Pointer to structure is the term used to make pointer pointing to structure. Syntax:- struct structure_name *var_name ; Eg. struct student *stu;

Thank you!