by: Lizawati, Norhidayah & Muhammad Noorazlan Shah Computer Engineering, FKEKK, UTeM
|
|
- Antony Wells
- 5 years ago
- Views:
Transcription
1 by: Lizawati, Norhidayah & Muhammad Noorazlan Shah Computer Engineering, FKEKK, UTeM
2 At the end of this chapter, the students should be able to: understand and apply typedef understand and apply structure (struct) understand and apply Enumeration (enum) understand and apply union
3 User Define Data Type (typedef) Structured Type definition, initialization, assignment pointer to structures nested structures arrays of structures structures and functions Enumerated Type Union Type
4 Derived Types Arrays Pointers Structure Enumerated Union Chapter 5 Chapter 7
5 creating synonyms for previously defined data type names is defined using the keyword typedef and the syntax is: typedef daya_type variable_name;
6 Example: typedef int LENGTH; /*LENGTH is a synonym for the data type int*/ LENGTH a, b, len; LENGTH numbers[10];
7 Structure is a collection of variables that are functionally related to each other group of related values the group is treated as a single unit each member of structure is a field each field of the structure has a specific type different fields may have either the same or different types
8 Group Field1 Field2 Field3 Field4 Field 1 Field 2 id name CGPA Field 3 student Structure
9 Declaration & definition: keyword struct Most common declaration method describe as follows: 1. Declaring a tag name and then using the tag name to declare actual variables This form is more commonly used, especially for a large program struct tagname type 1 fieldname 1 ; type 2 fieldname 2 ; type n fieldname n ; }; struct tagname varname; struct STUDENT int id; char name[30]; float CGPA; }; struct STUDENT benc, bene; benc & bene is declared as variable of type struct STUDENT with 3 members, id, name and CGPA
10 2. Declaring a structure without a tag name This form is useful if the structure is used only in one place struct type 1 fieldname 1 ; type 2 fieldname 2 ; type n fieldname n ; } varname; struct int id; char name[30]; float CGPA; }benc, bene;
11 3. Declaring a structure with a tag name and variables struct tagname type 1 fieldname 1 ; type 2 fieldname 2 ; type n fieldname n ; } varname; struct STUDENT int id; char name[30]; float CGPA; }benc, bene; benc & bene is declared as variable of type struct STUDENT
12 typedef of structure declaration & definition: typedef struct tagname type 1 fieldname 1 ; type 2 fieldname 2 ; type n fieldname n ; } typename; typename varname; typedef struct STUDENT int id; char name[30]; float CGPA; } stud; stud benc, bene; Create a data type call stud. benc & bene is declared as variable of typedef stud. Keyword struct can be ignore since stud is not normal structure
13 Initialization: struct tagname varname = fieldval 1, fieldval 2,..., fieldval n }; struct STUDENT char id[8]; char name[30]; float CGPA; }; struct STUDENT stud1= 0123, Anne, 3.98}; 0123 Anne 3.98 id name CGPA struct STUDENT stud2= 0123 }; 0123 id \0 name 0.0 CGPA
14 Accessing Structures: dot (.) form to refer to field of a structure each field treated as an individual variable varname.fieldname typedef struct DATE int month, day, year; } date; month d1 day year void main() date d1; d1.month = 12; d1.day = 2; d1.year = 1970; }
15 Structure Assignment: variables must be of same type (same name) values are copied one at a time from field to corresponding field typedef struct DATE int month, day, year; } date; month 12 d1 day 2 year 1970 date d1 = 12, 2, 1970 }; date d2; d2 = d1; /* Assignment */ d2.day = d1.day; month 12 d2 day 2 year 1970
16 used to reference structures can only stored the address of a structure struct STUDENT char id[8]; char name[30]; float CGPA; }; struct STUDENT stud1 = 0123, Anne, 3.98}; struct STUDENT *ptr; //declare a pointer ptr = &stud1;//assign address of stud1 ptr 0123 Anne name 3.98 id name CGPA
17 Accessing Pointer Structures: (*pointername). fieldname Or pointername -> fieldname printf ( Student CGPA : %.2f, stud1.cgpa); or printf ( Student CGPA : %.2f, (*ptr).cgpa); or printf ( Student CGPA : %.2f, ptr->cgpa);
18 Example: a group of students and the data stored in a structure Create array of structure: struct STUDENT stuary[30]; Initialize for two students: stuary = 1001, Ahmad, 2.98}, 1002, Siti, 3.01}};
19 Access data for a student: refer to the structure name with an index or a pointer stuary[i] or *pstu
20 Example: compute CGPA of all students float totcgpa; float avrcgpa; int i; struct STUDENT stuary[30]; accessing using index for (i=0; i<30; i++) totcgpa += stuary[i].cgpa; avrcgpa = totcgpa/30; accessing using pointer float totcgpa; float avrcgpa; struct STUDENT *pstu, *plaststu; plaststu = stuary + 29; for (pstu=stuary; pstu<=plaststu; pstu++) totcgpa += (*pstu).cgpa; avrcgpa = totcgpa/30;
21 a structure includes another structure stamp.date.month stamp.time.min month day year hour min sec date time stamp.date stamp stamp.time struct DATE int day; int month; int year; }; struct TIME int hour; int min; int sec; }; struct STAMP struct DATE date; struct TIME time; }; struct STAMP stamp;
22 Accessing nested structures include each level from the highest to the component being referenced stamp stamp.date stamp.date.month stamp.time stamp.time.sec
23 Nested structure initialization: each structure must be initialized completely before proceeding to the next member each structure is enclosed in a set of braces ( }) struct STAMP stamp = 12, 06, 1983}, 23, 35, 05}};
24 Two methods to pass structures as parameters of a function: Passing by value passing a copy of the entire structure suitable if the structure is very small to make sure the called function does not change the structure being passed Passing by reference passing the address of the structure faster and more convenient method
25 #include <stdio.h> struct STUDENT char id[8]; char name[30]; float CGPA; }stud1 = "0123", "Anne", 3.98}; void func(struct STUDENT s, struct STUDENT *sp) printf("s.id = %s\n", s.id); printf("s.name = %s\n", s.name); printf("s.cgpa = %f\n", s.cgpa); } printf("sp->id = %s\n", sp->id); printf("sp->name = %s\n", sp->name); printf("sp->cgpa = %f\n", sp->cgpa);
26 int main() struct STUDENT stud2="0124", "Joe", 3.25}; } //passed structure stud1 and address of stud2 to func() func(stud1, &stud2); return 0;
27 The return type of the function must match the actual returned value One advantage of returning a structure is the ability to return more than one value However, function passing as reference is more commonly used than functions returning structures
28 #include <stdio.h> #include <string.h> struct STUDENT int id; char name[30]; float CGPA; }; /* function returns a structure */ struct STUDENT func(int id) struct STUDENT s1; s1.id = id + 1; strcpy(s1.name, "Anne"); //copy string Anne to s1.name s1.cgpa = 2.98; } return s1;
29 int main() struct STUDENT stud1=1000, "Joe", 3.25}, stud2; stud2 = func(stud1.id); //assign the returned structure to stud2 printf("stud2.id = %d\n", stud1.id); printf("stud2.name = %s\n", stud2.name); printf("stud2.cgpa = %f\n", stud2.cgpa); } return 0;
30 Enumerated types: is derived from the integer type is defined using the keyword enum and the syntax is: enum tag_name name_0, name_1,, name_n }; the names in an enumerated type are replaced by integer values by the compiler
31 the values in an enum start with 0, unless specified otherwise, and are incremented by 1. enum days Mon, Tue, Wed, Thu, Fri, Sat, Sun }; Mon is 0, Tue is 1, Wed is 2, etc give different initial value enum days Mon = 1, Tue, Wed, Thu, Fri, Sat, Sun }; Mon is 1, Tue is 2, Wed is 3, etc
32 give a value for each enum numbers First = 1, Third = 3, Fifth = 5}; Three thoughts about enumerated types: You can assign the same integer to multiple enumeration constants in the same definition enum colors green, blue, purple, yellow = 1}; assign same number to blue and yellow
33 You can assign an enumerated type to an integer enum colors green=2, blue, purple, yellow = 1}; enum colors shirt; int x; shirt = purple; x = purple; //OK. x is 4
34 Example 1: enum days Sun, Mon, Tue, Wed, Thu, Fri, Sat }; int day; for (day = Sun; day <= Sat; day++) if ((day == Sun) (day == Sat)) printf( Weekend\n ); else printf( Weekday\n ); } printf( %d\n, Wed); //Would print 3
35 Example 2: #include<stdio.h> int main() enum sport soccer=3, bowling=5, tenis, badminton}; enum sport game; game = badminton; } switch(game) case (3): printf("soccer"); break; case (5): printf("bowling"); break; case (6): printf("tenis"); break; case (7): printf("badminton"); break; } return 0;
36 Union: like a structure, a union is also a derived data type the members of a union share a single storage space only ONE member of each union can be referenced at a time amount of space allocated for storage is the amount needed for the largest member of the union
37 Union vs. Structure union NUMBER int x; float y; } union NUMBER val; struct NUMBER int x; float y; } struct NUMBER val; 4 byte storage (float) val x or y 6 byte storage (float + int) val x y
38 Example: #include<stdio.h> union number int x; float y; float z; }; void main() union number val; printf ("size of union is %d\n", sizeof(val)); //size of union is 4 val.x = 5; printf("x is %d\n", val.x); //x is 5
39 val.y = ; printf("y is %.2f\n", val.y); //y is val.z = ; printf("z is %.2f\n", val.z); //z is } printf("y is %.2f\n", val.y); //y is
40 Can you differentiate between enum, struct and union? apply enum, struct and union?
12 CREATING NEW TYPES
Lecture 12 CREATING NEW TYPES of DATA Typedef declaration Enumeration Structure Bit fields Uninon Creating New Types Is difficult to solve complex problems by using programs written with only fundamental
More informationIV Unit Second Part STRUCTURES
STRUCTURES IV Unit Second Part Structure is a very useful derived data type supported in c that allows grouping one or more variables of different data types with a single name. The general syntax of structure
More informationProgramming. Structures, enums and unions
Programming Structures, enums and unions Summary } Structures } Declaration } Member access } Function arguments } Memory layout } Array of structures } Typedef } Enums } Unions 2 Idea! } I want to describe
More informationLecture10: Structures, Unions and Enumerations 11/26/2012
Lecture10: Structures, Unions and Enumerations 11/26/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C 1 Administrative Items Assignment #10 on the course webpage r, long double, etc.
More informationBLM2031 Structured Programming. Zeyneb KURT
BLM2031 Structured Programming Zeyneb KURT 1 Contact Contact info office : D-219 e-mail zeynebkurt@gmail.com, zeyneb@ce.yildiz.edu.tr When to contact e-mail first, take an appointment What to expect help
More informationtypedef int Array[10]; String name; Array ages;
Morteza Noferesti The C language provides a facility called typedef for creating synonyms for previously defined data type names. For example, the declaration: typedef int Length; Length a, b, len ; Length
More informationProgramming in C. What is C?... What is C?
C Programming in C UVic SEng 265 Developed by Brian Kernighan and Dennis Ritchie of Bell Labs Earlier, in 1969, Ritchie and Thompson developed the Unix operating system We will be focusing on a version
More informationProgramming in C UVic SEng 265
Programming in C UVic SEng 265 Daniel M. German Department of Computer Science University of Victoria 1 SEng 265 dmgerman@uvic.ca C Developed by Brian Kernighan and Dennis Ritchie of Bell Labs Earlier,
More informationProgramming in C. What is C?... What is C?
Programming in C UVic SEng 265 C Developed by Brian Kernighan and Dennis Ritchie of Bell Labs Earlier, in 1969, Ritchie and Thompson developed the Unix operating system We will be focusing on a version
More informationFeatures of C. Portable Procedural / Modular Structured Language Statically typed Middle level language
1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC
More informationFor each of the following variables named x, specify whether they are static, stack-dynamic, or heapdynamic:
For each of the following variables named x, specify whether they are static, stack-dynamic, or heapdynamic: a) in C++: int* x = new(int); b) in Java: class book { protected string title; book(string x)
More informationLecture 3. The syntax for accessing a struct member is
Lecture 3 Structures: Structures are typically used to group several data items together to form a single entity. It is a collection of variables used to group variables into a single record. Thus a structure
More informationIn this session we will cover the following sub-topics: 1.Identifiers 2.Variables 3.Keywords 4.Statements 5.Comments 6.Whitespaces 7.Syntax 8.
In this session we will cover the following sub-topics: 1.Identifiers 2.Variables 3.Keywords 4.Statements 5.Comments 6.Whitespaces 7.Syntax 8.Semantic www.tenouk.com, 1/16 C IDENTIFIERS 1. Is a unique
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 10 Structures, Unions, Bit Manipulations and Enumerations Department of Computer Engineering
More informationBasic Elements of C. Staff Incharge: S.Sasirekha
Basic Elements of C Staff Incharge: S.Sasirekha Basic Elements of C Character Set Identifiers & Keywords Constants Variables Data Types Declaration Expressions & Statements C Character Set Letters Uppercase
More informationDarshan Institute of Engineering & Technology for Diploma Studies Unit 5
1 What is structure? How to declare a Structure? Explain with Example Structure is a collection of logically related data items of different data types grouped together under a single name. Structure is
More informationUNIT-V. Structures. The general syntax of structure is given below: Struct <tagname> { datatype membername1; datatype membername2; };
UNIT-V Structures Structure is a very useful derived data type supported in c that allows grouping one or more variables of different data types with a single name. The general syntax of structure is given
More informationUnit IV & V Previous Papers 1 mark Answers
1 What is pointer to structure? Pointer to structure: Unit IV & V Previous Papers 1 mark Answers The beginning address of a structure can be accessed through the use of the address (&) operator If a variable
More informationC BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.
C BOOTCAMP DAY 2 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Pointers 2 Pointers Pointers are an address in memory Includes variable addresses,
More informationComputer Systems Principles. C Pointers
Computer Systems Principles C Pointers 1 Learning Objectives Learn about floating point number Learn about typedef, enum, and union Learn and understand pointers 2 FLOATING POINT NUMBER 3 IEEE Floating
More informationChapter 7: Structuring the Data. Lecture7 1
Chapter 7: Structuring the Data Lecture7 1 Topics Introduction to Structures Operations on Structures Using Structures with Arrays Using Structures with Pointers Passing Structures to and from Functions
More informationC Programming Review CSC 4320/6320
C Programming Review CSC 4320/6320 Overview Introduction C program Structure Keywords & C Types Input & Output Arrays Functions Pointers Structures LinkedList Dynamic Memory Allocation Macro Compile &
More informationECET 264 C Programming Language with Applications. Lecture 13. Structures and Unions
ECET 264 C Programming Language with Applications Lecture 13 Structures and Unions Professor Paul I-Hai Lin lin@ipfw.edu http://www.etcs.ipfw.edu/~lin Prof. Paul I. Lin 1 Lecture 13 Structures and Unions
More informationUnit 8. Structures and Unions. School of Science and Technology INTRODUCTION
INTRODUCTION Structures and Unions Unit 8 In the previous unit 7 we have studied about C functions and their declarations, definitions, initializations. Also we have learned importance of local and global
More informationVariables Data types Variable I/O. C introduction. Variables. Variables 1 / 14
C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition
More informationIntroduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types. Record Types. Pointer and Reference Types
Chapter 6 Topics WEEK E FOUR Data Types Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types Union Types Pointer and Reference
More informationA Fast Review of C Essentials Part I
A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types
More informationC PROGRAMMING Lecture 4. 1st semester
C PROGRAMMING Lecture 4 1st semester 2017-2018 Structures Structure: Collection of one or more variables a tool for grouping heterogeneous elements together (different types) Array: a tool for grouping
More informationadvanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef
today advanced data types (1) typedef. mon 23 sep 2002 homework #1 due today homework #2 out today quiz #1 next class 30-45 minutes long one page of notes topics: C advanced data types dynamic memory allocation
More informationMidterm Examination # 2 Wednesday, March 18, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:
Page 1 of 8 School of Computer Science 60-141-01 Introduction to Algorithms and Programming Winter 2015 Midterm Examination # 2 Wednesday, March 18, 2015 ANSWERS Duration of examination: 75 minutes STUDENT
More informationAryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9
Fundamental of C Programming Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Q2. Write down the C statement to calculate percentage where three subjects English, hindi, maths
More informationSyntax and Variables
Syntax and Variables What the Compiler needs to understand your program, and managing data 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line
More informationMemory. What is memory? How is memory organized? Storage for variables, data, code etc. Text (Code) Data (Constants) BSS (Global and static variables)
Memory Allocation Memory What is memory? Storage for variables, data, code etc. How is memory organized? Text (Code) Data (Constants) BSS (Global and static variables) Text Data BSS Heap Stack (Local variables)
More informationUNIT - V STRUCTURES AND UNIONS
UNIT - V STRUCTURES AND UNIONS STRUCTURE DEFINITION A structure definition creates a format that may be used to declare structure variables. Let us use an example to illustrate the process of structure
More informationPROGRAMMAZIONE I A.A. 2017/2018
PROGRAMMAZIONE I A.A. 2017/2018 STRUCTURES STRUCTS Arrays allow to define type of variables that can hold several data items of the same kind. Similarly structure is another user defined data type available
More informationArrays. Systems Programming Concepts
Arrays Systems Programming Concepts Arrays Arrays Defining and Initializing Arrays Array Example Subscript Out-of-Range Example Passing Arrays to Functions Call by Reference Multiple-Subscripted Arrays
More informationUNIT-IV. Structure is a user-defined data type in C language which allows us to combine data of different types together.
UNIT-IV Unit 4 Command Argument line They are parameters/arguments supplied to the program when it is invoked. They are used to control program from outside instead of hard coding those values inside the
More informationCS561 Manju Muralidharan Priya Structures in C CS200 STRUCTURES. Manju Muralidharan Priya
OBJECTIVES: CS200 STRUCTURES Manju Muralidharan Priya By the end of this class you will have understood: 1. Definition of a structure 2. Nested Structures 3. Arrays of structure 4. User defined data types
More informationBinghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program
Syntax What the Compiler needs to understand your program 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line Possibly replacing it with other
More informationThe syntax of structure declaration is. struct structure_name { type element 1; type element 2; type element n;
Structure A structure is a user defined data type. We know that arrays can be used to represent a group of data items that belong to the same type, such as int or float. However we cannot use an array
More information3.3 Structures. Department of CSE
3.3 Structures 1 Department of CSE Objectives To give an introduction to Structures To clearly distinguish between Structures from Arrays To explain the scenarios which require Structures To illustrate
More informationPROGRAMMAZIONE I A.A. 2018/2019
PROGRAMMAZIONE I A.A. 2018/2019 COMMENTS COMMENTS There are two ways to insert a comment in C: üblock comments begin with /* and end with */, and üline comments begin with // and end with the next new
More informationChapter-8 DATA TYPES. Introduction. Variable:
Chapter-8 DATA TYPES Introduction To understand any programming languages we need to first understand the elementary concepts which form the building block of that program. The basic building blocks include
More informationLanguage comparison. C has pointers. Java has references. C++ has pointers and references
Pointers CSE 2451 Language comparison C has pointers Java has references C++ has pointers and references Pointers Values of variables are stored in memory, at a particular location A location is identified
More informationC/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock)
C/Java Syntax 1 Lecture 02 Summary Keywords Variable Declarations Data Types Operators Statements if, switch, while, do-while, for Functions 2 By the end of this lecture, you will be able to identify the
More informationC/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for
C/Java Syntax 1 Lecture 02 Summary Keywords Variable Declarations Data Types Operators Statements if, switch, while, do-while, for Functions 2 1 By the end of this lecture, you will be able to identify
More informationCOMP 2355 Introduction to Systems Programming
COMP 2355 Introduction to Systems Programming Christian Grothoff christian@grothoff.org http://grothoff.org/christian/ 1 Functions Similar to (static) methods in Java without the class: int f(int a, int
More informationALQUDS University Department of Computer Engineering
2013/2014 Programming Fundamentals for Engineers Lab Lab Session # 8 Structures, and Enumeration ALQUDS University Department of Computer Engineering Objective: After completing this lab, the students
More informationITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University
ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 12: Structures Readings: Chapter 11 Structures (1/2) A structure is a collection of one
More informationDepartment of Computer Science and Engineering. Programming for Problem Solving. I Year B.Tech. (I - Sem) Assistant Professor (M.
Website : www.aceec.ac.in ACE Engineering College Ankushapur, Ghatkesar, Telangana 501301 (EAMCET Code: ACEG) NAAC Accridated with A Grade Department of Computer Science and Engineering Programming for
More informationData Type. structure. C Programming Lecture 11 : Structuret. struct union. typedef. A collection of one or more variables
Data Type C Programming Lecture 11 : Structuret struct union enum typedef structure t A collection of one or more variables possibly of different types, grouped together under a single name. ex) employee
More informationFrancesco Nidito. Programmazione Avanzata AA 2007/08
Francesco Nidito in the Programmazione Avanzata AA 2007/08 Outline 1 2 3 in the in the 4 Reference: Micheal L. Scott, Programming Languages Pragmatics, Chapter 7 What is a type? in the What is a type?
More informationA3-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH 'C' LANGUAGE
A3-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH 'C' LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be
More information공학프로그래밍언어 (PROGRAMMING LANGUAGE FOR ENGINEERS) -STRUCTURE- SPRING 2015 SEON-JU AHN, CNU EE
공학프로그래밍언어 (PROGRAMMING LANGUAGE FOR ENGINEERS) -STRUCTURE- SPRING 2015 SEON-JU AHN, CNU EE STRUCTURE Structures are collections of related variables under one name. Structures may contain variables of
More informationCS 61c: Great Ideas in Computer Architecture
Arrays, Strings, and Some More Pointers June 24, 2014 Review of Last Lecture C Basics Variables, functioss, control flow, types, structs Only 0 and NULL evaluate to false Pointers hold addresses Address
More informationStructures Unions and Enumerated Datatypes 224
STRUCTURES, UNIONS AND ENUMERATED DATA TYPES LEARNING OBJECTIVES After reading this chapter, the readers will be able to understand the purpose of the user defined data types Structures, Unions and Enumerated
More informationProgramming for Engineers Structures, Unions
Programming for Engineers Structures, Unions ICEN 200 Spring 2017 Prof. Dola Saha 1 Structure Ø Collections of related variables under one name. Ø Variables of may be of different data types. Ø struct
More informationMain Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University
C Programming Notes Dr. Karne Towson University Reference for C http://www.cplusplus.com/reference/ Main Program #include main() printf( Hello ); Comments: /* comment */ //comment 1 Data Types
More informationARRAYS(II Unit Part II)
ARRAYS(II Unit Part II) Array: An array is a collection of two or more adjacent cells of similar type. Each cell in an array is called as array element. Each array should be identified with a meaningful
More informationProgramming in C - Part 2
Programming in C - Part 2 CPSC 457 Mohammad Reza Zakerinasab May 11, 2016 These slides are forked from slides created by Mike Clark Where to find these slides and related source code? http://goo.gl/k1qixb
More informationPointers and Arrays 1
Pointers and Arrays 1 Pointers and Arrays When an array is declared, The compiler allocates sufficient amount of storage to contain all the elements of the array in contiguous memory locations The base
More informationVariation of Pointers
Variation of Pointers A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before
More informationLecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions
Lecture 02 Summary C/Java Syntax Keywords Variable Declarations Data Types Operators Statements if, switch, while, do-while, for Functions 1 2 By the end of this lecture, you will be able to identify the
More informationType Definition. C Types. Derived. Function Array Pointer Structure Union Enumerated. EE 1910 Winter 2017/18
Enum and Struct Type Definition C Types Derived Function Array Pointer Structure Union Enumerated 2 tj Type Definition Typedef Define a new Type Inherits members and operations from a standard or previously
More informationFundamentals of Programming. Lecture 12: C Structures, Unions, Bit Manipulations and Enumerations
Fundamentals of Programming Lecture 12: C Structures, Unions, Bit Manipulations and Enumerations Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department
More informationSubject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100
Code: DC-05 Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 NOTE: There are 11 Questions in all. Question 1 is compulsory and carries 16 marks. Answer to Q. 1. must be written in the space
More informationTokens, Expressions and Control Structures
3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type
More informationCOMP322 - Introduction to C++
COMP322 - Introduction to C++ Winter 2011 Lecture 2 - Language Basics Milena Scaccia School of Computer Science McGill University January 11, 2011 Course Web Tools Announcements, Lecture Notes, Assignments
More informationM1-R4: Programing and Problem Solving using C (JAN 2019)
M1-R4: Programing and Problem Solving using C (JAN 2019) Max Marks: 100 M1-R4-07-18 DURATION: 03 Hrs 1. Each question below gives a multiple choice of answers. Choose the most appropriate one and enter
More informationLaboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information
Laboratory 2: Programming Basics and Variables Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information 3. Comment: a. name your program with extension.c b. use o option to specify
More informationPointers. Part VI. 1) Introduction. 2) Declaring Pointer Variables. 3) Using Pointers. 4) Pointer Arithmetic. 5) Pointers and Arrays
EE105: Software Engineering II Part 6 Pointers page 1 of 19 Part VI Pointers 1) Introduction 2) Declaring Pointer Variables 3) Using Pointers 4) Pointer Arithmetic 5) Pointers and Arrays 6) Pointers and
More informationFirst of all, it is a variable, just like other variables you studied
Pointers: Basics What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the address (rather than the value)
More informationComputer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary
GATE- 2016-17 Postal Correspondence 1 C-Programming Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts, Analysis
More informationChapter 10 C Structures, Unions, Bit Manipulations
Chapter 10 C Structures, Unions, Bit Manipulations Skipped! Skipped! and Enumerations Skipped! Page 416 In programming languages, Arrays (Chapter 6) allows programmers to group elements of the same type
More informationEM108 Software Development for Engineers
EE108 Section 6 Pointers page 1 of 20 EM108 Software Development for Engineers Section 6 - Pointers 1) Introduction 2) Declaring Pointer Variables 3) Using Pointers 4) Pointer Arithmetic 5) Pointers and
More informationC++: Const Function Overloading Constructors and Destructors Enumerations Assertions
C++: Const Function Overloading Constructors and Destructors Enumerations Assertions Const const float pi=3.14159; const int* pheight; // defines pointer to // constant int value cannot be changed // pointer
More informationChapter 21: Introduction to C Programming Language
Ref. Page Slide 1/65 Learning Objectives In this chapter you will learn about: Features of C Various constructs and their syntax Data types and operators in C Control and Loop Structures in C Functions
More informationCharacter Strings. String-copy Example
Character Strings No operations for string as a unit A string is just an array of char terminated by the null character \0 The null character makes it easy for programs to detect the end char s[] = "0123456789";
More informationMidterm Examination # 2 Wednesday, March 19, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:
Page 1 of 7 School of Computer Science 60-141-01 Introduction to Algorithms and Programming Winter 2014 Midterm Examination # 2 Wednesday, March 19, 2014 ANSWERS Duration of examination: 75 minutes STUDENT
More informationSubject: Fundamental of Computer Programming 2068
Subject: Fundamental of Computer Programming 2068 1 Write an algorithm and flowchart to determine whether a given integer is odd or even and explain it. Algorithm Step 1: Start Step 2: Read a Step 3: Find
More informationIntroduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language
Introduction C++ widely-used general-purpose programming language procedural and object-oriented support strong support created by Bjarne Stroustrup starting in 1979 based on C Introduction to C++ also
More informationCS3157: Advanced Programming. Announcement
CS3157: Advanced Programming Lecture #10 Mar 20 Shlomo Hershkop shlomo@cs.columbia.edu Announcement Welcome back from spring break Hope you ve caught up with your courses Have the exams back, will return
More informationCMPE-013/L. Introduction to C Programming
CMPE-013/L Introduction to C Programming Bryant Wenborg Mairs Spring 2014 What we will cover in 13/L Embedded C on a microcontroller Specific issues with microcontrollers Peripheral usage Reading documentation
More informationDownloaded S. from Kiran, PGT (CS) KV, Malleswaram STRUCTURES. Downloaded from
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
More information3/22/2016. Pointer Basics. What is a pointer? C Language III. CMSC 313 Sections 01, 02. pointer = memory address + type
Pointer Basics What is a pointer? pointer = memory address + type C Language III CMSC 313 Sections 01, 02 A pointer can contain the memory address of any variable type A primitive (int, char, float) An
More informationIntroduction to C++ with content from
Introduction to C++ with content from www.cplusplus.com 2 Introduction C++ widely-used general-purpose programming language procedural and object-oriented support strong support created by Bjarne Stroustrup
More informationM.EC201 Programming language
Power Engineering School M.EC201 Programming language Lecture 13 Lecturer: Prof. Dr. T.Uranchimeg Agenda The union Keyword typedef and Structures What Is Scope? External Variables 2 The union Keyword The
More informationObject-Oriented Principles and Practice / C++
Object-Oriented Principles and Practice / C++ Alice E. Fischer April 20, 2015 OOPP / C++ Lecture 3... 1/23 New Things in C++ Object vs. Pointer to Object Optional Parameters Enumerations Using an enum
More informationStructures and Union. Fall Jinkyu Jeong GEBD029: Basis and Practice in Programming Fall 2014 Jinkyu Jeong
Structures and Union Fall 2014 Jinkyu Jeong (jinkyu@skku.edu) 1 Review Bitwise operations You need them for performance in terms of space and time Shifts are equivalent to arithmetics Enumeration you can
More information10/20/2015. Midterm Topic Review. Pointer Basics. C Language III. CMSC 313 Sections 01, 02. Adapted from Richard Chang, CMSC 313 Spring 2013
Midterm Topic Review Pointer Basics C Language III CMSC 313 Sections 01, 02 1 What is a pointer? Why Pointers? Pointer Caution pointer = memory address + type A pointer can contain the memory address of
More informationBit Manipulation in C
Bit Manipulation in C Bit Manipulation in C C provides six bitwise operators for bit manipulation. These operators act on integral operands (char, short, int and long) represented as a string of binary
More informationEnumerated Types. Mr. Dave Clausen La Cañada High School
Enumerated Types Mr. Dave Clausen La Cañada High School Enumerated Types Enumerated Types This is a new simple type that is defined by listing (enumerating) the literal values to be used in this type.
More informationPROGRAMMAZIONE I A.A. 2017/2018
PROGRAMMAZIONE I A.A. 2017/2018 FUNCTIONS INTRODUCTION AND MAIN All the instructions of a C program are contained in functions. üc is a procedural language üeach function performs a certain task A special
More informationCSE 230 Intermediate Programming in C and C++
CSE 230 Intermediate Programming in C and C++ Unions and Bit Fields Fall 2017 Stony Brook University Instructor: Shebuti Rayana http://www3.cs.stonybrook.edu/~cse230/ Union Like structures, unions are
More informationCOMP322 - Introduction to C++ Lecture 02 - Basics of C++
COMP322 - Introduction to C++ Lecture 02 - Basics of C++ School of Computer Science 16 January 2012 C++ basics - Arithmetic operators Where possible, C++ will automatically convert among the basic types.
More informationStructures. Dr. Donald Davendra Ph.D. (Department of Computing Science, Structures FEI VSB-TU Ostrava)
Structures Dr. Donald Davendra Ph.D. Department of Computing Science, FEI VSB-TU Ostrava 1/18 Derived and Structured Data Types basic data type - part of the standard language, preprocessor - without parameters,
More informationComputer Programming Unit 3
POINTERS INTRODUCTION Pointers are important in c-language. Some tasks are performed more easily with pointers such as dynamic memory allocation, cannot be performed without using pointers. So it s very
More informationC# Fundamentals. Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh
C# Fundamentals Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh Semester 1 2018/19 H-W. Loidl (Heriot-Watt Univ) F20SC/F21SC 2018/19
More informationTechnical Questions. Q 1) What are the key features in C programming language?
Technical Questions Q 1) What are the key features in C programming language? Portability Platform independent language. Modularity Possibility to break down large programs into small modules. Flexibility
More informationReview of the C Programming Language for Principles of Operating Systems
Review of the C Programming Language for Principles of Operating Systems Prof. James L. Frankel Harvard University Version of 7:26 PM 4-Sep-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights
More information