Downloaded S. from Kiran, PGT (CS) KV, Malleswaram STRUCTURES. Downloaded from

Similar documents
Chapter-14 STRUCTURES

CS561 Manju Muralidharan Priya Structures in C CS200 STRUCTURES. Manju Muralidharan Priya

The syntax of structure declaration is. struct structure_name { type element 1; type element 2; type element n;

IV Unit Second Part STRUCTURES

CLASSES AND OBJECT CHAPTER 04 CLASS XII

6.096 Introduction to C++

Object Oriented Pragramming (22316)

Exercises 1. class member { int membernum = 25; float memberpay; public void Input(cin >> membernum >> memberpay); void Output; }

UNIT-V. Structures. The general syntax of structure is given below: Struct <tagname> { datatype membername1; datatype membername2; };

Chapter-11 POINTERS. Important 3 Marks. Introduction: Memory Utilization of Pointer: Pointer:

Multi-Dimensional arrays

Syntax to define a Structure: struct structurename { datatype membername1; datatype membername2;... } ; For Example:

Structures. Lecture 15 COP 3014 Spring April 16, 2018

CS 31 Discussion 1A, Week 8. Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50 a.m.

Darshan Institute of Engineering & Technology for Diploma Studies Unit 5

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE

Lecture 3 Tao Wang 1

structs // variable declarations

11/28/11. Structures. structs. struct Definition. Chapter 11. structs store a collection of data elements of different data types

Example: Structure, Union. Syntax. of Structure: struct book { char title[100]; char author[50] ]; float price; }; void main( )

Kapi ap l S e S hgal P T C p t u er. r S. c S ienc n e A n A k n leshw h ar ar Guj u arat C C h - 8

Chapter-8 DATA TYPES. Introduction. Variable:

struct structure_name { //Statements };


Unit 8. Structures and Unions. School of Science and Technology INTRODUCTION

CSCI 1370 APRIL 26, 2017

Subject: Fundamental of Computer Programming 2068

CS31 Discussion. Jie(Jay) Wang Week8 Nov.18

Chapter-6 Classes and Objects. stud.execute(); getch();} Output:

Darshan Institute of Engineering & Technology for Diploma studies Unit 4

Classes. Logical method to organise data and functions in a same structure. Also known as abstract data type (ADT).

Tin học cơ sở 4$ Structures!

struct Definition Structure Declaration (7.1) Chapter 7 - Introduction to Classes and Objects

Structure, Union. Ashishprajapati29.wordpress.com. 1 What is structure? How to declare a Structure? Explain with Example

12 CREATING NEW TYPES

To understand the concept of candidate and primary keys and their application in table creation.

ARRAYS. Part II Answers to all the questions (2 Marks):

UNIT - V STRUCTURES AND UNIONS

Pointers, Dynamic Data, and Reference Types

Structs. Comp Sci 1570 Introduction to C++ Introduction. Aggregate data. Example. General syntax Object initialization Initialization and access

.:: UNIT 1 ::. INTRODUCTION TO ALGORITHM & DATA STRUCTURES

I SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK a) What is the difference between Hardware and Software? Give one example for each.

OBJECTS. An object is an entity around us, perceivable through our senses. Types of Object: Objects that operate independently.

F4104 ALGORITHM & DATA STRUCTURE

3.3 Structures. Department of CSE

Arrays, Pointers and Memory Management

Functions, Arrays & Structs

6. Pointers, Structs, and Arrays. March 14 & 15, 2011

Solution: A pointer is a variable that holds the address of another object (data item) rather than a value.

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ ARRAYS POINTERS POINTER ARITHMETIC. Problem Solving with Computers-I

Data Representation and Storage

CS 2530 INTERMEDIATE COMPUTING

Programming Fundamentals (CS-302 )

MCA Semester 1. MC0061 Computer Programming C Language 4 Credits Assignment: Set 1 (40 Marks)

6. Pointers, Structs, and Arrays. 1. Juli 2011

CS 31 Discussion ABDULLAH-AL-ZUBAER IMRAN WEEK 6: C-STRINGS, STRUCT, CLASS AND PROJECT4

Chapter 7 - Notes User-Defined Functions II

Downloaded from

! Pass by value: when an argument is passed to a. ! It is implemented using variable initialization. ! Changes to the parameter in the function body

COMPUTER SCIENCE (083)

Week 8. Muhao Chen

a data type is Types

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 11: Records (structs)

typedef int Array[10]; String name; Array ages;

Chapter 11: Structured Data

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

C++ 8. Constructors and Destructors

Lecture 3. Variables. Variables

Simple vs Structured Data

Functions, Arrays & Structs

Pointer Data Type and Pointer Variables

DELHI PUBLIC SCHOOL TAPI

INTERNATIONAL INDIAN SCHOOL, RIYADH. Ch 1 C++ Revision tour

CSCI2467: Systems Programming Concepts

Outline. Introduction. Arrays declarations and initialization. Const variables. Character arrays. Static arrays. Examples.

Arrays. int Data [8] [0] [1] [2] [3] [4] [5] [6] [7]

CSc Introduction to Computing

Problem 1 Short Answers Why use the reserved words new or delete? Why use dynamic memory allocation?

(a) Differentiate between a call by value and call by reference method.

C++ Structures Programming Workshop 2 (CSCI 1061U)

Static Members. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

First of all, it is a variable, just like other variables you studied

Chapter 10 C Structures, Unions, Bit Manipulations

Object Reference and Memory Allocation. Questions:


CS349/SE382 A1 C Programming Tutorial

Arrays in C++ Instructor: Andy Abreu

ALQUDS University Department of Computer Engineering

CHAPTER 13 STRUCTURES

Programs as Models. Procedural Paradigm. Class Methods. CS256 Computer Science I Kevin Sahr, PhD. Lecture 11: Objects

by: Lizawati, Norhidayah & Muhammad Noorazlan Shah Computer Engineering, FKEKK, UTeM

Structures in C. Rab Nawaz Jadoon DCS. Assistant Professor. Department of Computer Science. COMSATS IIT, Abbottabad Pakistan

Downloaded from

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Complex data types Structures Defined types Structures and functions Structures and pointers (Very) brief introduction to the STL

You must declare all variables before they can be used. Following is the basic form of a variable declaration:

Chapter 11: Structured Data

OBJECT ORIENTED PROGRAMMING. Ms. Ajeta Nandal C.R.Polytechnic,Rohtak

[0569] p 0318 garbage

Transcription:

Downloaded S. from Kiran, www.studiestoday.com PGT (CS) KV, STRUCTURES

WHAT IS A STRUCTURE? Structure is a collection of logically related data. It is also a collection of dissimilar datatype.

Downloaded from S. www.studiestoday.com Kiran, PGT (CS) KV, WHY DO WE NEED A STRUCTURE? For instance, if we want to store the information of 50 employees. Such as employee number, name, age and basic.

Using arrays, the declaration would be as follows: int empno[50]; char name[50][20]; int age[50]; float basic[50] And the memory allocation would be as follows

empno Name 0............49 0,0 age 49,0 0............49

DRAWBACKS OF USING ARRAY In the declaration made above if we want to search for a particular employee detail say for e.g. emp who is stored in index no. 30. it has to make 30 searches to get empno, 30 searches to get name, 30 searches to get age and 30 searches to find basic.

Downloaded from S. www.studiestoday.com Kiran, PGT (CS) KV, So altogether to fetch one employee detail the system has to make 30+30+30+30 i.e. 120 searches. Which doesn t make the program efficient and makes the process of data retrieval and access very slow. This drawback is over come by using the user defined datatype - STRUCTURES

STRUCTURE DECLARATION Syntax : struct structure tag / name { datatype variablename; datatype variablename; datatype variablename; };

EXAMPLE : Structure name struct student { int stdno; char name[20]; int age; float total; char grade; }; Structure elements Remember structure declaration ends with a ;

MEMORY ALLOCATION No memory is allocated at the time of structure declaration. Memory is allocated only when a structure variable is declared.

STRUCT VARIABLE DECLARATION For the structure declaration made abovethe variable would be defined as follows : Syntax: structname variable ; For eg: student s ; Structure variable Structure name

MEMORY REPRESENTATION For a single structure variable memory is allocated as follows : stdn o name age total grade

Downloaded from S. www.studiestoday.com Kiran, PGT (CS) KV, REFERENCING STRUCTURE ELEMENTS The elements in a structure are referenced using dot operator. Eg., student s; s.stdno; s.name;

Downloaded from S. www.studiestoday.com Kiran, PGT (CS) KV, STRUCTURE AS ARRAY struct emp { int empno; char name[20]; float basic: } e[10]; Here an array to store 10 employee details is created.

Downloaded from S. www.studiestoday.com Kiran, PGT (CS) KV, MEMORY ALLOCATION FOR STRUCTURE EMPNO Name basic 0,0........ 9,0

Program: struct emp cin>>e[i].empno; { cout<< Enter Emp. Name ; int empno; cin>>e[i].name; char ename[20]; cout<< Enter Basic ; float basic; }e[10]; } void main() Downloaded from S. www.studiestoday.com Kiran, PGT (CS) KV, { } clrscr(); cout<< Enter emp details ; for(int i=0; i<10; i++) { cout<< Employee No ; cin>>e[i].basic; getch();

RECAPITULATION

Downloaded from S. www.studiestoday.com Kiran, PGT (CS) KV, What is the difference between an array and structure? What are the drawbacks of using an array? When is memory allocated for structure datatypes? How do we refer the elements of the structure?