21 August 2015 1 (B.V.Patel institute of BMC & IT) STRUCTURE AND UNIONS.

Slides:



Advertisements
Similar presentations
2007 Pearson Education, Inc. All rights reserved C Structures, Unions, Bit Manipulations and Enumerations.
Advertisements

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Introduction Structures –Collections of related.
Chapter 10 C Structures, Unions, Bit Manipulations and Enumerations Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc.
Chapter 10 C Structures, Unions, Bit Manipulations, and Enumerations.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
Enumerated data type & typedef. Enumerated Data Type An enumeration consists of a set of named integer constants. An enumeration type declaration gives.
ENUMERATED, typedef. ENUMERATED DATA TYPES An enumeration consists of a set of named integer constants. An enumeration type declaration gives the name.
Line Efficiency     Percentage Month Today’s Date
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 10 - C Structures, Unions, Bit Manipulations,
 2000 Prentice Hall, Inc. All rights reserved. Chapter 10 - Structures, Unions, Bit Manipulations, and Enumerations Outline 10.1Introduction 10.2Structure.
1 CSC103: Introduction to Computer and Programming Lecture No 26.
Macros. There are three basic phases for C programming. preprocessing, compiling, and linking. C input file is first passed to a preprocessing program.
Structures in C++ UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) 1 ADNAN BABAR MT14028 CR.
 2007 Pearson Education, Inc. All rights reserved C Structures, Unions, Bit Manipulations and Enumerations.
Ch Chapter 4 Basic Data Types and Variables 4.1 Basic Data Types In C TABLE 4.1 Introduction to Basic Data Types in C Type SizeDescription char 1.
Chapter 10 Structures, Unions, Bit Manipulations, and Enumerations Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering.
CCSA 221 Programming in C CHAPTER 9 WORKING WITH STRUCTURES 1.
Structures and Enumerations Introduction Structure definitions Nested structure Referring and initializing structure elements Passing structures to a function.
1 EPSII 59:006 Spring HW’s and Solutions on WebCT.
C PREPROCESSOR. Introduction  It is a program that processes our source program before it is passed to the compiler.  Preprocessor commands (often known.
MayJunJulAugSepOctNovDec2016 Milestone 1 May 10 Milestone 2 Jun 7 Milestone 3 Jul 21 Milestone 4 Aug 12 Milestone 5 Sep 20 Milestone 6 Oct 30 Milestone.
What do I need to Know For My Assignment?. C Pointer Review To declare a pointer, we use the * operator. This is similar to but different from using *
Jan 2016 Solar Lunar Data.
Chapter 10-1: Structure.
Structure, Unions, typedef and enumeration
Primary Longman Elect 3A Chapter 5 Asking about dates.
C Structures, Unions, Bit Manipulations and Enumerations
Payroll Calendar Fiscal Year
Q1 Jan Feb Mar ENTER TEXT HERE Notes


Project timeline # 3 Step # 3 is about x, y and z # 2
Average Monthly Temperature and Rainfall
C Structures, Unions, and Enumerations
C Structures, Unions, Bit Manipulations and Enumerations
GANTT CHARTS Example Text Text Here Text Here Text Here Text Here
Preprocessor.
2017 Jan Sun Mon Tue Wed Thu Fri Sat
Timeline PowerPoint Template

Gantt Chart Enter Year Here Activities Jan Feb Mar Apr May Jun Jul Aug
Q1 Q2 Q3 Q4 PRODUCT ROADMAP TITLE Roadmap Tagline MILESTONE MILESTONE
Free PPT Diagrams : ALLPPT.com
Chapter 1: Introduction to Data Structures(8M)

Step 3 Step 2 Step 1 Put your text here Put your text here
Jan Sun Mon Tue Wed Thu Fri Sat
Sun Mon Tue Wed Thu Fri Sat
C Structures, Unions, Bit Manipulations and Enumerations
CS 240 – Lecture 7 Boolean Operations, Increment and Decrement Operators, Constant Types, enum Types, Precedence.
Sun Mon Tue Wed Thu Fri Sat
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Q1 Q2 Q3 Q4 PRODUCT ROADMAP TITLE Roadmap Tagline MILESTONE MILESTONE
Free PPT Diagrams : ALLPPT.com

Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
2016 | 10 OCT SUN MON TUE WED THU FRI SAT
Text for section 1 1 Text for section 2 2 Text for section 3 3
Sun Mon Tue Wed Thu Fri Sat
Text for section 1 1 Text for section 2 2 Text for section 3 3
Project timeline # 3 Step # 3 is about x, y and z # 2
TIMELINE NAME OF PROJECT Today 2016 Jan Feb Mar Apr May Jun
SEESIM 14 Timeline Jan Feb Mar Apr May Jun Jul Aug Sep Oct
Q1 Q2 Q3 Q4 PRODUCT ROADMAP TITLE Roadmap Tagline MILESTONE MILESTONE
Presentation transcript:

21 August (B.V.Patel institute of BMC & IT) STRUCTURE AND UNIONS

21 August Defining a structure Struct book_bank { char title [20]; char author[15]; int pages; float price; }; A structure is convenient tool for handling a group of logically related different data items. for ex.customer(address,id,name)

 Struct book_bank  {  char title [20];  char author[15];  int pages;  float price;  } book_bank book1;

 The link between member and variable is establish using dot operator For ex.book1.pages=250;  Another method for ex. Strcpy(book1.author,”balagurusamy”);  Another method we cal also scanf to values scanf(“%d\n”,&book1.pages);

 Compile time main() { struct student { char name[20]; int marks; }stud; stud. marks={50}; …………… }

 Rum time Scanf (“%d \n ”,&stud. marks);

 Structure can be initialize within main or outside the main main() { struct student { char name[20]; int marks; }stud; stud. marks={50}; …………… } struct student { char name[20]; int marks; }stud; Main() { stud. marks={50); }

 If(stud1.number == 111) { float sum=stud1.marks+stud2.marks; stud2.marks *=0.5; }

 Struct marks { int sub1; int sub2; int sub3; }marks student main() { Struct marks student[3]={{45,34,61}, {23,55,67},{44,66,55}}; }

 student[0].subject1=45; student[0].subject2=34; ………………… student[2].subject3= 55 ;

 Struct marks { int number; float subject[3]; }student[2]; here the member subject contains three elements subejct[0], subejct[1], subejct[2]. these elements can be accessed using appropriate subscript like student[1].subject[2] refer marks obtain in third subject by second student.

 Struct salary { char name; char dept; Struct { int houserent; int da; } allowance; } Employee; Now for refer member we can use employee.allowance.houserent

 Union item { int m; float x; char c; }code; code.m=379;

 It is like structure but main difference is in term of storage C M X

 ENUM is closely related to the #define preprocessor.#define  It allows you to define a list of aliases which represent integer numbers. For example if you find yourself coding something like:  #define MON 1  #define TUE 2  #define WED 3  You could use enum as below.  enum week { Mon=1, Tue, Wed, Thu, Fri Sat, Sun} days; or  enum boolean { FALSE = 0, TRUE }; 21 August

int main() { /* * Define a list of aliases */ enum months {Jan=1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec}; enum months month; /* define 'month' variable of type 'months‘ */ printf("%d\n", month=Sep); /* Assign integer value via an alias * This will return a 9 */ } 21 August

21 August  int main() { /* * Define a list of aliases */ enum days {Jan=31, Feb=28, Mar=31, Apr=30, May=31, Jun=30, Jul=31, Aug=31, Sep=30, Oct=31, Nov=30, Dec=31}; printf("%d\n", month=Feb); /* Assign integer value via an alias * This will return 28 */ }

 It is a program that processes our source program before it is passed to the complier.  The preprocessor offers several features called preprocessor directives. Each of these preprocessor directives begins with # symbol. The directives can be placed anywhere in the program but most often placed at the beginning of program. There are four types of preprocessor directives as follow.   Macro expansion  File inclusion  Conditional compilation  Miscellaneous directives 21 August

 #define PI  The above statement is called macro definition or macro. During preprocessing the processor replaces every occurrence of PI in program with It is also called macro templates whereas are called macro expansions 21 August

 This preprocessor directive causes one file to be included in another. The preprocessor command for file inclusion looks like this:  #include “filename”  and it simply easy causes the entire contents of filename to be inserted into the source code at that point in the program 21 August

 if we want, have the compiler skip over part of a source code by inserting the preprocessing commands #ifdef and #endif, which have the general form: #ifdef macroname statement 1; statement 2; statement 3; #endif  If macroname has been #defined, the block will be processed as usual; otherwise not 21 August

 There are two more preprocessor directives available, though they are not very commonly used. They are:   #undef  #pragma 21 August

23