Programming C/C++ on Eclipe Trình bày : Ths HungNM C/C++ Training.

Slides:



Advertisements
Similar presentations
Classes & Objects INTRODUCTION : This chapter introduces classes ; explains data hiding, abstraction & encapsulation and shows how a class implements these.
Advertisements

UNIT IV.
StructuresStructures Systems Programming. Systems Programming: Structures 2 Systems Programming: 2 StructuresStructures Structures Structures Typedef.
EASTERN MEDITERRANEAN UNIVERSITY EENG212 ALGORITHMS & DATA STRUCTURES Structures in C.
Chapter 10 C Structures, Unions, Bit Manipulations and Enumerations Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc.
Programming in C Chapter 10 Structures and Unions
CSC141- Introduction to Computer Programming
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
C Structures and Memory Allocation There is no class in C, but we may still want non- homogenous structures –So, we use the struct construct struct for.
1 Structures. 2 User-Defined Types C provides facilities to define one’s own types. These may be a composite of basic types ( int, double, etc) and other.
Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
Programming and Data Structure
Structure.
Structures Spring 2013Programming and Data Structure1.
Structures in C.
CSC141- Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 25 Thanks for Lecture Slides: Dr. Sadaf Tanveer Dr. Sadaf Tanveer,
Programming C/C++ on Eclipe Trình bày : Ths HungNM C/C++ Training.
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.
ECE 353: Lab C Pointers and Structs. Basics A pointer holds an address to some variable Notation: – Dereferencing operator: * int *x is a declaration.
Programming C/C++ on Eclipe Trình bày : Ths HungNM C/C++ Training.
Introduction to C Programming CE Lecture 10 Data Structures typedef and struct.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
Programming C/C++ on Eclipe C Training Trình bày : Ths HungNM.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MCA, MSc[IT], MTech[IT],MPhil (Comp.Sci), PGDCA, ADCA, Dc. Sc. & Engg.
Learners Support Publications Pointers, Virtual Functions and Polymorphism.
Structs. Structures We already know that arrays are many variables of the same type grouped together under the same name. Structures are like arrays except.
DCT1063 Programming 2 CHAPTER 5 ADVANCED DATA TYPE (part 1) Mohd Nazri Bin Ibrahim Faculty of Computer Media and Technology TATi University College
Understanding Structures tMyn1 Understanding Structures In order to describe virtually anything in the real world, you need to define several values that.
Advanced Data types and Sorting
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 10 - C Structures, Unions, Bit Manipulations,
Learners Support Publications Classes and Objects.
Structures in C++ UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) 1 ADNAN BABAR MT14028 CR.
Structured Programming Instructor: Prof. K. T. Tsang Lecture 11: Structure and Union 1.
1 Pointers to structs. 2 A pointer to a struct is used in the same way as a pointer to a simple type, such as an int. Pointers to structs were introduced.
1 Chapter 11 Structured Data. 2 Topics 10.1 Abstract Data Types 10.2 Combining Data into Structures 10.3 Accessing Structure Members 10.4 Initializing.
Array, Structure and Union
Structures Combining data types into a logical groupings.
Structures. Structures (1) u Structures are C’s way of grouping collections of data into a single manageable unit. –This is also the fundamental element.
Structured Data Chapter 11. Combining Data Into Structures Structure: C++ construct that allows multiple variables to be grouped together Format: struct.
Programming Fundamentals. Today’s Lecture The Conditional Operator Logical Operators Structures Enumerations.
ECE 103 Engineering Programming Chapter 49 Structures Unions, Part 1 Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE.
 Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create.
Chapter 13: Structures. In this chapter you will learn about: – Single structures – Arrays of structures – Structures as function arguments – Linked lists.
1 C Language Structures. 2 Topics Concept of a structure Concept of a structure Structures in c Structures in c Structure declaration Structure declaration.
Pointers. Pointer Variable Declarations and Initialization Pointer variables – Contain memory addresses as their values – Normal variables contain a specific.
+ Structures and Unions. + Introduction We have seen that arrays can be used to represent a group of data items that belong to the same type, such as.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Structured Programming Approach Module VIII - Additional C Data Types Structures Prof: Muhammed Salman Shamsi.
Introduction to Object-Oriented Programming Lesson 2.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI N305 Structures Declarations.
1. 2 Introduction Structure Definitions and Declarations Initializing Structures Operations on Structures Members Structures as Functions Parameters Array.
1 Structures. 2 What is a Structure? Used for handling a group of logically related data items  Examples: Student name, roll number, and marks Real part.
Introduction to Computers and Programming Class 24 Structures (structs) Professor Avi Rosenfeld.
CCSA 221 Programming in C CHAPTER 11 POINTERS ALHANOUF ALAMR 1.
STRUCTURES. INTRODUCTION A structure is same as that of records. It stores related information about an entity. Structure is basically a user defined.
1 Structures. 2 What is a Structure? Used for handling a group of logically related data items  Examples: Student name, roll number, and marks Real part.
Chapter 11 Structures, Unions and Typedef 11.1 Structures Structures allow us to group related data items of different types under a common name. The individual.
Lecture 10: Structures. Outline Introduction Structure Definitions and declarations Initializing Structures Operations on Structures members Structures.
1 Structures & Unions. 2 User-Defined Types C provides facilities to define one’s own types. These may be a composite of basic types ( int, double, etc)
Lecture 3 (UNIT -1) SUNIL KUMAR CIT-UPES.
Chapter 10-1: Structure.
Pointers, Enum, and Structures
Lecture 9 Structure 1. Concepts of structure Pointers of structures
C Structures, Unions, and Enumerations
Derived types.
Classes and Objects.
Structures In C Programming By Rajanikanth B.
Structures, Unions, and Enumerations
Structures Declarations CSCI 230
Programming Fundamental
Presentation transcript:

Programming C/C++ on Eclipe Trình bày : Ths HungNM C/C++ Training

Training C/C++EcoSoftware 2 Structure Data o Introduction Structure data. o Defining a Structure. o Declaring Structure Variables. o Accessing Structure Members o Initializing Structures. o Assignment Statements with structure o Array of Structures. o Pointers to Structures o Union

Training C/C++EcoSoftware 3 Introduction Structure data. o A structure consists of a number of data items, which need not be of the same data type, grouped together. o The structure could hold as many of these items as desired. 1 Variable ILLUSIONBACH1 Name of the bookAuthor Edition I L L U S I O N Array

Training C/C++EcoSoftware 4 Defining a Structure o A structure definition forms a template for creating structure variables o The variables in the structure are called structure elements or structure members o Example: … … number name on_hand

Training C/C++EcoSoftware 5 Declaring Structure Variables o Once the structure has been defined, one or more variables of that type can be declared o Example: struct cat book; o The statement sets aside enough memory to hold all items in the structure struct cat books1, books2; or struct cat books1; struct cat books2; struct cat { char bk_name[25]; char author[20]; float price; } books1, books2;

Training C/C++EcoSoftware 6 Accessing Structure Members  Structure elements are referenced through the use of the dot operator (.), also known as the membership operator  Syntax:  structure_name.element_name  Example:  scanf(“%s”, books1.bk_name);

Training C/C++EcoSoftware 7 Initializing Structures o Like variables and arrays, structure variables can be initialized at the point of declaration struct employee {int no; char name [20]; }; o Variables emp1 and emp2 of the type employee can be declared and initialized as: struct employee emp1 = {346, “Abraham”}; struct employee emp2 = {347, “John”};

Training C/C++EcoSoftware 8 Assignment Statements Used with Structures-1 o It is possible to assign the values of one structure variable to another variable of the same type using a simple assignment statement o For example :  if books 1 and books2 are structure variables of the same type, the following statement is valid books2 = books1;

Training C/C++EcoSoftware 9 Assignment Statements Used with Structures - 2 o In cases where direct assignment is not possible, the in- built function memcpy() can be used o Syntax: memcpy (char * destn, char &source, int nbytes); o Example: memcpy (&books2, &books1, sizeof(struct cat));

Training C/C++EcoSoftware 10 Structures within Structures  It is possible to have one structure within another structure. A structure cannot be nested within itself  To access the elements of the structure the format will be similar to the one used with normal structures, struct issue { char borrower [20]; char dt_of_issue[8]; struct cat books; }issl; issl.borrower  To access elements of the structure cat, which is a part of another structure issue, issl.books.author

Training C/C++EcoSoftware 11 Passing Structures as Arguments o A structure variable can be passed as an argument to a function o This facility is used to pass groups of logically related data items together instead of passing them one by one o The type of the argument should match the type of the parameter

Training C/C++EcoSoftware 12 Array of Structures o A common use of structures is in arrays of structures o A structure is first defined, and then an array variable of that type is declared o Example:  struct cat books[50]; o To the access the variable author of the fourth element of the array books:  books[4].author

Training C/C++EcoSoftware 13 Initialization of Structure Arrays o Structure arrays are initialized by enclosing the list of values of its elements within a pair of braces o Example: struct unit { char ch; int i; }; struct unit series [3] = {{‘a’, 100} {‘b’, 200} {‘c’, 300} };

Training C/C++EcoSoftware 14 Pointers to Structures o Structure pointers are declared by placing an asterisk(*) in front of the structure variable’s name o The -> operator is used to access the elements of a structure using a pointer o Example: struct cat *ptr_bk; ptr_bk = &books; printf(“%s”, ptr_bk->author); o Structure pointers passed as arguments to functions enable the function to modify the structure elements directly

Training C/C++EcoSoftware 15 The typedef keyword o A new data type name can be defined by using the keyword typedef o It does not create a new data type, but defines a new name for an existing type o Syntax:  typedef type name; o Example:  typedef float deci; o typedef cannot be used with storage classes

Training C/C++EcoSoftware 16 Union o Allows the same memory area to be shared by a number of different variables. o Syntax  Declaring a union is similar to that used for structures union cat books1, books2; or union cat books1; union cat books2; union cat { char bk_name[25]; char author[20]; float price; } books1, books2;

Training C/C++EcoSoftware 17 Example Union

Training C/C++EcoSoftware 18 Pointers to Unions o define a pointer to a union with a statement such as :  union u_example *pU;  pU = &U2;  U1.decval = pU->decval;

Training C/C++EcoSoftware 19 Thank You End