Type Definition. C Types. Derived. Function Array Pointer Structure Union Enumerated. EE 1910 Winter 2017/18
|
|
- Morgan Andrews
- 6 years ago
- Views:
Transcription
1 Enum and Struct
2 Type Definition C Types Derived Function Array Pointer Structure Union Enumerated 2 tj
3 Type Definition Typedef Define a new Type Inherits members and operations from a standard or previously defined derived type Typically done in global area so all parts of the program will recognize it typedef type IDENTIFIER; typedef int AGE; // define a new type called AGE // that acts like an int 3 tj
4 Enumerated Types Enum Declare a new Type Define its name and its members (enumerate them) Members are mapped to integer values Normally 0 - n enum typename {idenitifier list}; enum wirecolor {RED, BLUE, BLACK, WHITE}; 4 tj
5 Enumerated Types Enum Create variables enum wirecolor power; enum wirecolor gnd; enum wirecolor signal; power, gnd, and signal can only have 4 values (RED, BLUE, BLACK, WHITE) 5 tj
6 Enumerated Types Enum Assign values power = BLACK; gnd = WHITE; signal = RED; enum wirecolor input; input = signal; // input now RED 6 tj
7 Enumerated Types Enum operations Enumerated types are integers All integer operations can be applied to an enumerated type No checking is done to ensure the result is valid enum month {JAN, FEB, MAR, NOV, DEC}; enum month birthmonth; // create a variable of // type month if (birthmonth == MAY){ 7 tj
8 Enumerated Types Enum enum month {JAN, FEB, MAR, enum month birthmonth; enum month currentmonth; if (birthmonth > currentmonth){ NOV, DEC}; switch(currentmonth){ case JAN: // case 0 case FEB: // case 1 8 tj
9 Enumerated Types Enum enum month {JAN, FEB, MAR, NOV, DEC}; suppose we d like the member numbers to match some other pattern enum month {JAN=1, FEB, MAR, NOV, DEC}; 9 tj
10 Enumerated Types Enum Anonymous Enumeration enum {OFF, ON}; // assign OFF the value 0, ON: 1 enum {SPACE =, COMMA =,, COLON = : }; 10 tj
11 Enumerated Types /* * enum_types.c * * Created on: Feb 8, 2018 * Author: johnsontimoj */ // examples of enumerated types // #include <stdio.h> // define type and declare variables // in global area so all parts of the // program can see them enum wire_color {RED, WHITE, BLUE, BLACK}; enum wire_color gnd; enum wire_color vcc; enum wire_color sig; int main(void){ setbuf(stdout, NULL); // initialize variables gnd = WHITE; vcc = BLACK; sig = RED; printf("gnd value is %i\n", gnd); printf("vcc value is %i\n", vcc); printf("sig value is %i\n", sig); enum wire_color tmp; tmp = sig; printf("tmp value is %i\n", tmp); enum month {JAN = 1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC}; enum month birth_month; birth_month = JUL; printf("birth month is %i\n", birth_month); birth_month++; printf("birth month is %i\n", birth_month); if(birth_month > APR) printf("birth month is after april\n"); else printf("birth month is before or equal to april\n"); birth_month -= 3; printf("birth month is %i\n", birth_month); birth_month = birth_month << 3; printf("birth month is %i\n", birth_month); const char* month_name[] = {"err", "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"}; birth_month = 5; printf("birth month is %s\n", month_name[birth_month]); return 0; } // end main 11 tj
12 Enumerated Types /* * enum_types.c * * Created on: Feb 8, 2018 * Author: johnsontimoj */ // examples of enumerated types // #include <stdio.h> // define type and declare variables // in global area so all parts of the // program can see them enum wire_color {RED, WHITE, BLUE, BLACK}; enum wire_color gnd; enum wire_color vcc; enum wire_color sig; int main(void){ setbuf(stdout, NULL); // initialize variables gnd = WHITE; vcc = BLACK; sig = RED; printf("gnd value is %i\n", gnd); printf("vcc value is %i\n", vcc); printf("sig value is %i\n", sig); enum wire_color tmp; tmp = sig; printf("tmp value is %i\n", tmp); gnd value is 1 vcc value is 3 sig value is 0 tmp value is 0 enum month {JAN = 1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC}; enum month birth_month; birth_month = JUL; printf("birth month is %i\n", birth_month); birth_month++; printf("birth month is %i\n", birth_month); if(birth_month > APR) printf("birth month is after april\n"); else printf("birth month is before or equal to april\n"); birth_month -= 3; printf("birth month is %i\n", birth_month); birth_month = birth_month << 3; printf("birth month is %i\n", birth_month); const char* month_name[] = {"err", "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"}; birth_month = 5; printf("birth month is %s\n", month_name[birth_month]); return 0; } // end main birth month is 7 birth month is 8 birth month is after april birth month is 5 birth month is 40 birth month is may 12 tj
13 Type Definition C Types Derived Function Array Pointer Structure Union Enumerated 13 tj
14 Structure Collection of related elements Not necessarily the same type Sharing a single name 14 tj
15 Structure Elemental unit is called a Field Looks just like a variable has a type takes up memory space can be assigned values can be read Only difference is that a Field is part of a Structure 15 tj
16 Structure numerator denominator fraction ID name GPA student 16 tj
17 Structure TAG definition struct TAG{ field list }; struct STUDENT{ char ID[10]; char name[26]; float GPA; }; 17 tj
18 Structure TypeDef definition defines a new type new elements of the structure type can be created via declaration typedef struct{ field list } TYPE; typedef struct{ char ID[10]; char name[26]; float GPA; } STUDENT; // type definition name 18 tj
19 Structure TypeDef definition typedef struct{ char ID[10]; char name[26]; float GPA; } STUDENT; // type definition name int foo; STUDENT student1; STUDENT student2; 19 tj
20 Structure TypeDef definition Initialization int foo; STUDENT student1 = {12A56B, Joe Smith, 3.45}; STUDENT student2 = {12A56B, Joe Smith}; GPA defaults to 0.0 If not specified, int and float fields default to 0, 0.0 char fields default to null - \0 20 tj
21 Structure Access structure.field student1.id student1.name student1.gpa 21 tj
22 Structure Access student2.gpa = 2.5; if(student1.gpa >= 3.5){ } printf( student GPA: %.2f, student2.gpa); scanf( %f, &student1.gpa); 22 tj
23 Structure Manipulation Only one operation assignment student2 = student1; 23 tj
24 Structure Pointers typedef struct{ char ID[10]; char name[26]; float GPA; } STUDENT; STUDENT* student_ptr; student_ptr = &student1; // define a pointer of STUDENT type // student_ptr now points to student1 24 tj
25 Structure Pointers STUDENT* student_ptr; student_ptr = &student1; // define a pointer of STUDENT type // student_ptr now points to student1 (*student_ptr).gpa = 3.66; student_ptr->gpa = 3.66; // dereference // indirect selection 25 tj
26 #include <stdio.h> #include <unistd.h> // Type definitions typedef struct{ // define a type: CLOCK int hr; int min; int sec; } CLOCK; // Function prototypes void increment (CLOCK* clock); void display (CLOCK clock); int main(void){ setbuf(stdout, NULL); // disable buffering // Local variables CLOCK clock = {11, 59, 57}; // Operation for(; ; ){ increment(&clock); display(clock); sleep(1); } return 0; } void increment(clock* clock){ (clock->sec)++; // increment seconds if (clock->sec == 60){ clock->sec = 0; (clock->min)++; // increment minutes if(clock->min == 60){ clock->min = 0; (clock->hr)++; if(clock->hr == 12){ clock->hr = 0; } // end if hr } // end if min } } // end if sec return; Pointer to structure pointer notation for fields structure passed structure notation for fields void display(clock clock){ printf("%02d:%02d:%02d\n", clock.hr, clock.min, clock.sec); return; } 11:59:56 11:59:57 11:59:58 11:59:59 00:00:00 00:00: :00:02 tj
27 P3->OUT location of all I/Os #define P3 ((DIO_PORT_Odd_Interruptable_Type*) (DIO_BASE + 0x0020)) structure type name location of P3 defines a pointer to a structure located in a specific spot 27 tj
28 P3->OUT IO uint8_t OUT; /*!< Port Output */ accesses an element in a structure pointer typedef struct { I uint8_t IN; /*!< Port Input */ uint8_t RESERVED0; IO uint8_t OUT; /*!< Port Output */ uint8_t RESERVED1; IO uint8_t DIR; /*!< Port Direction */ uint8_t RESERVED2; IO uint8_t REN; /*!< Port Resistor Enable */ uint8_t RESERVED3; IO uint8_t DS; /*!< Port Drive Strength */ uint8_t RESERVED4; IO uint8_t SEL0; /*!< Port Select 0 */ uint8_t RESERVED5; IO uint8_t SEL1; /*!< Port Select 1 */ uint8_t RESERVED6; I uint16_t IV; /*!< Port Interrupt Vector Value */ uint8_t RESERVED7[6]; IO uint8_t SELC; /*!< Port Complement Select */ uint8_t RESERVED8; IO uint8_t IES; /*!< Port Interrupt Edge Select */ uint8_t RESERVED9; IO uint8_t IE; /*!< Port Interrupt Enable */ uint8_t RESERVED10; IO uint8_t IFG; /*!< Port Interrupt Flag */ uint8_t RESERVED11; } DIO_PORT_Odd_Interruptable_Type; 28 tj
29 location of all I/Os #define P3 ((DIO_PORT_Odd_Interruptable_Type*) (DIO_BASE + 0x0020)) P3->OUT location of P3 IO uint8_t OUT; /*!< Port Output */ typedef struct { I uint8_t IN; /*!< Port Input */ uint8_t RESERVED0; IO uint8_t OUT; /*!< Port Output */ uint8_t RESERVED1; IO uint8_t DIR; /*!< Port Direction */ uint8_t RESERVED2; IO uint8_t REN; /*!< Port Resistor Enable */ uint8_t RESERVED3; IO uint8_t DS; /*!< Port Drive Strength */ uint8_t RESERVED4; IO uint8_t SEL0; /*!< Port Select 0 */ uint8_t RESERVED5; IO uint8_t SEL1; /*!< Port Select 1 */ uint8_t RESERVED6; I uint16_t IV; /*!< Port Interrupt Vector Value */ uint8_t RESERVED7[6]; IO uint8_t SELC; /*!< Port Complement Select */ uint8_t RESERVED8; IO uint8_t IES; /*!< Port Interrupt Edge Select */ uint8_t RESERVED9; IO uint8_t IE; /*!< Port Interrupt Enable */ uint8_t RESERVED10; IO uint8_t IFG; /*!< Port Interrupt Flag */ uint8_t RESERVED11; } DIO_PORT_Odd_Interruptable_Type; 29 tj
C Structures, Unions, Bit Manipulations, and Enumerations
C Structures, Unions, Bit Manipulations, and Enumerations Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline 10.2 Structure Definitions 10.4
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 informationOBJECT ORIENTED PROGRAMMING USING C++
OBJECT ORIENTED PROGRAMMING USING C++ Chapter 10 - Structures, Unions, Bit Manipulations, and Enumerations Outline 10.1 Introduction 10.2 Structure Definitions 10.3 Initializing Structures 10.4 Accessing
More informationIntroduction. Structures, Unions, Bit Manipulations, and Enumerations. Structure. Structure Definitions
Introduction Structures, Unions, Bit Manipulations, and Enumerations In C, we can create our own data types If programmers do a good job of this, the end user does not even have to know what is in the
More informationArrays. C Types. Derived. Function Array Pointer Structure Union Enumerated. EE 1910 Winter 2017/18
C Types Derived Function Array Pointer Structure Union Enumerated 2 tj Arrays Student 0 Student 1 Student 2 Student 3 Student 4 Student 0 Student 1 Student 2 Student 3 Student 4 Student[0] Student[1] Student[2]
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 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 informationHigh Performance Computing
High Performance Computing MPI and C-Language Seminars 2009 Photo Credit: NOAA (IBM Hardware) High Performance Computing - Seminar Plan Seminar Plan for Weeks 1-5 Week 1 - Introduction, Data Types, Control
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 informationCS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation
CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;
More informationScope. Scope. Region of a program in which a defined object is visible. Defined Objects. Two types of regions. Variables Functions
Scope & Repetition Scope Scope Region of a program in which a defined object is visible Defined Objects Variables Functions Two types of regions Blocks Not in a block 2 tj Scope Program Prototype Blocks
More informationLecture 14. Dynamic Memory Allocation
Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 14-1 Lecture 14. Dynamic Memory Allocation The number of variables and their sizes are determined at compile-time before a program runs /*
More informationCompiling and Running a C Program in Unix
CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 95 ] Compiling and Running a C Program in Unix Simple scenario in which your program is in a single file: Suppose you want to name
More informationData Types. 9. Types. a collection of values and the definition of one or more operations that can be performed on those values
Data Types 1 data type: a collection of values and the definition of one or more operations that can be performed on those values C++ includes a variety of built-in or base data types: short, int, long,
More informationBBM#101# #Introduc/on#to# Programming#I# Fall$2013,$Lecture$12$
BBM#101# #Introduc/on#to# Programming#I# Fall$2013,$Lecture$12$ Instructors:!Aykut!Erdem,!Erkut!Erdem,!Fuat!Akal! Today#! Structures#! Structure#Defini/ons#! Ini/alizing#Structures#! Accessing#Members#of#Structures#!
More informationDefinition: Data Type A data type is a collection of values and the definition of one or more operations on those values.
Data Types 1 Definition: Data Type A data type is a collection of values and the definition of one or more operations on those values. Base Data Types All the values of the type are ordered and atomic.
More informationFile I/O. Last updated 10/30/18
Last updated 10/30/18 Input/Output Streams Information flow between entities is done with streams Keyboard Text input stream data stdin Data Text output stream Monitor stdout stderr printf formats data
More informationRecursion Enums. Basics of Programming 1. Department of Networked Systems and Services G. Horváth, A.B. Nagy, Z. Zsóka, P. Fiala, A.
Recursion The enumerated type Recursion Enums Basics of Programming 1 Department of Networked Systems and Services G. Horváth, A.B. Nagy, Z. Zsóka, P. Fiala, A. Vitéz 31 October, 2018 based on slides by
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 informationFile Handling in C. EECS 2031 Fall October 27, 2014
File Handling in C EECS 2031 Fall 2014 October 27, 2014 1 Reading from and writing to files in C l stdio.h contains several functions that allow us to read from and write to files l Their names typically
More informationCMIS 102 Hands-On Lab
CMIS 10 Hands-On Lab Week 8 Overview This hands-on lab allows you to follow and experiment with the critical steps of developing a program including the program description, analysis, test plan, and implementation
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 informationSystems Programming. 05. Structures & Trees. Alexander Holupirek
Systems Programming 05. Structures & Trees Alexander Holupirek Database and Information Systems Group Department of Computer & Information Science University of Konstanz Summer Term 2008 Schedule for Today
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 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 informationMore Arrays. Last updated 2/6/19
More Last updated 2/6/19 2 Dimensional Consider a table 1 2 3 4 5 6 5 4 3 2 12 11 13 14 15 19 17 16 3 1 4 rows x 5 columns 2 tj 2 Dimensional Consider a table 1 2 3 4 5 6 5 4 3 2 12 11 13 14 15 19 17 16
More informationCS Programming I: Arrays
CS 200 - Programming I: Arrays Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624 Array Basics
More informationTypes, Operators and Expressions
Types, Operators and Expressions CSE 2031 Fall 2011 9/11/2011 5:24 PM 1 Variable Names (2.1) Combinations of letters, numbers, and underscore character ( _ ) that do not start with a number; are not a
More informationData Types H&K Chapter 7. Instructor - Andrew S. O Fallon CptS 121 (October 17, 2018) Washington State University
Data Types H&K Chapter 7 Instructor - Andrew S. O Fallon CptS 121 (October 17, 2018) Washington State University Data Types We already know that: Data type = set of values + set of operations on those
More informationTypes, Operators and Expressions
Types, Operators and Expressions EECS 2031 18 September 2017 1 Variable Names (2.1) l Combinations of letters, numbers, and underscore character ( _ ) that do not start with a number; are not a keyword.
More informationRegister Access. Common - Last updated 7/25/18
Common - Last updated 7/25/18 Peripheral Each peripheral has a series of registers Configuration Control Inputs Outputs Registers are memory mapped Accessed via memory addresses 2 tj Peripheral TI / Code
More informationTypes. C Types. Floating Point. Derived. fractional part. no fractional part. Boolean Character Integer Real Imaginary Complex
Types C Types Void Integral Floating Point Derived Boolean Character Integer Real Imaginary Complex no fractional part fractional part 2 tj Types C Types Derived Function Array Pointer Structure Union
More informationMore Binary Search Trees AVL Trees. CS300 Data Structures (Fall 2013)
More Binary Search Trees AVL Trees bstdelete if (key not found) return else if (either subtree is empty) { delete the node replacing the parents link with the ptr to the nonempty subtree or NULL if both
More informationFundamentals of Programming Session 25
Fundamentals of Programming Session 25 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2013 These slides have been created using Deitel s slides Sharif University of Technology Outlines
More informationMore BSTs & AVL Trees bstdelete
More BSTs & AVL Trees bstdelete if (key not found) return else if (either subtree is empty) { delete the node replacing the parents link with the ptr to the nonempty subtree or NULL if both subtrees are
More informationC Concepts - I/O. Lecture 19 COP 3014 Fall November 29, 2017
C Concepts - I/O Lecture 19 COP 3014 Fall 2017 November 29, 2017 C vs. C++: Some important differences C has been around since around 1970 (or before) C++ was based on the C language While C is not actually
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 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 informationby: Lizawati, Norhidayah & Muhammad Noorazlan Shah Computer Engineering, FKEKK, UTeM
by: Lizawati, Norhidayah & Muhammad Noorazlan Shah Computer Engineering, FKEKK, UTeM At the end of this chapter, the students should be able to: understand and apply typedef understand and apply structure
More informationC Programming Language: C ADTs, 2d Dynamic Allocation. Math 230 Assembly Language Programming (Computer Organization) Thursday Jan 31, 2008
C Programming Language: C ADTs, 2d Dynamic Allocation Math 230 Assembly Language Programming (Computer Organization) Thursday Jan 31, 2008 Overview Row major format 1 and 2-d dynamic allocation struct
More informationScientific Programming in C X. More features & Fortran interface
Scientific Programming in C X. More features & Fortran interface Susi Lehtola 20 November 2012 typedef typedefs are a way to make shorthand for data types, and possibly also make the code more general
More informationHistory. used in early Mac development notable systems in Pascal Skype TeX embedded systems
Overview The Pascal Programming Language (with material from tutorialspoint.com) Background & History Features Hello, world! General Syntax Variables/Data Types Operators Conditional Statements Functions
More informationData Structures and Algorithms (DSA) Course 4. Iulian Năstac
Data Structures and Algorithms (DSA) Course 4 Iulian Năstac 10. Functions for dynamic memory allocation (recapitulation) Dynamic allocation is a specific characteristic allowed by some computing languages,
More informationCMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 11, FALL 2012
CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 11, FALL 2012 TOPICS TODAY Characters & Strings in C Structures in C CHARACTERS & STRINGS char type C supports the char data type
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 informationECSE 321 Assignment 2
ECSE 321 Assignment 2 Instructions: This assignment is worth a total of 40 marks. The assignment is due by noon (12pm) on Friday, April 5th 2013. The preferred method of submission is to submit a written
More informationProgramming Language B
Programming Language B Takako Nemoto (JAIST) 28 January Takako Nemoto (JAIST) 28 January 1 / 20 Today s quiz The following are program to print each member of the struct Student type object abe. Fix the
More informationCprE 288 Introduction to Embedded Systems Exam 1 Review. 1
CprE 288 Introduction to Embedded Systems Exam 1 Review http://class.ece.iastate.edu/cpre288 1 Overview of Today s Lecture Announcements Exam 1 Review http://class.ece.iastate.edu/cpre288 2 Announcements
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 informationChapter 2: Data Types and Arithmetic Expressions TRUE/FALSE
Chapter 2: Data Types and Arithmetic Expressions TRUE/FALSE 1. Data can take many forms, including numbers, individual alphabetic characters, strings of alphabetic characters, and numbers with specific
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 informationC Primer Plus 5/e 1.1 C
C Primer Plus 5/e 1.1 C C C 2 2 C int main() // traditional rules int doors; int dogs; doors = 5; dogs = 3; // other statements int main() // C99 rules // some statements int doors; doors = 5; // first
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 informationWriting an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and
Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and #include The Use of printf() and scanf() The Use of printf()
More informationLecture 10: Boolean Expressions
Lecture 10: Boolean Expressions CS1068+ Introductory Programming in Python Dr Kieran T. Herley Department of Computer Science University College Cork 2017-2018 KH (12/10/17) Lecture 10: Boolean Expressions
More informationArrays III and Enumerated Types
Lecture 15 Arrays III and Enumerated Types Multidimensional Arrays & enums CptS 121 Summer 2016 Armen Abnousi Multidimensional Arrays So far we have worked with arrays with one dimension. Single dimensional
More informationHigh Performance Computing in C and C++
High Performance Computing in C and C++ Rita Borgo Computer Science Department, Swansea University Summary Introduction to C Writing a simple C program Compiling a simple C program Running a simple C program
More informationFunction I/O. Last Updated 10/30/18
Last Updated 10/30/18 Program Structure Includes Function Declarations void main(void){ foo = fun1(a, b); fun2(2, c); if(fun1(c, d)) { } } Function 1 Definition Function 2 Definition 2 tj Function Input
More informationFunction I/O. Function Input and Output. Input through actual parameters. Output through return value. Input/Output through side effects
Function Input and Output Input through actual parameters Output through return value Only one value can be returned Input/Output through side effects printf scanf 2 tj Function Input and Output int main(void){
More informationUniversity of Calgary Department of Electrical and Computer Engineering ENCM 335 Instructor: Steve Norman
page 1 of 6 University of Calgary Department of Electrical and Computer Engineering ENCM 335 Instructor: Steve Norman Fall 2018 MIDTERM TEST Thursday, November 1 6:30pm to 8:30pm Please do not write your
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 informationOperator overloading: extra examples
Operator overloading: extra examples CS319: Scientific Computing (with C++) Niall Madden Week 8: some extra examples, to supplement what was covered in class 1 Eg 1: Points in the (x, y)-plane Overloading
More informationa data type is Types
Pointers Class 2 a data type is Types Types a data type is a set of values a set of operations defined on those values in C++ (and most languages) there are two flavors of types primitive or fundamental
More informationRecap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam
Multimedia Programming 2004 Lecture 2 Erwin M. Bakker Joachim Rijsdam Recap Learning C++ by example No groups: everybody should experience developing and programming in C++! Assignments will determine
More informationCA341 - Comparative Programming Languages
CA341 - Comparative Programming Languages and David Sinclair Data, Values and Types In 1976 Niklaus Wirth (inventor of Pascal, Modula, Oberon, etc) wrote a book called Algorithms + Data Structures = Programs
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 informationOUTLINE. Review Functions Pointers Function calls Array Pointers Pointer Arrays Data Structures and dynamic Memory Function Pointers quicksort example
OUTLINE Review Functions Pointers Function calls Array Pointers Pointer Arrays Data Structures and dynamic Memory Function Pointers quicksort example FUNCTIONS Functions enable grouping of commonly used
More informationC-LANGUAGE CURRICULAM
C-LANGUAGE CURRICULAM Duration: 2 Months. 1. Introducing C 1.1 History of C Origin Standardization C-Based Languages 1.2 Strengths and Weaknesses Of C Strengths Weaknesses Effective Use of C 2. C Fundamentals
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 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 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 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 informationHPE Security Data Security. HPE SecureData. Product Lifecycle Status. End of Support Dates. Date: April 20, 2017 Version:
HPE Security Data Security HPE SecureData Product Lifecycle Status End of Support Dates Date: April 20, 2017 Version: 1704-1 Table of Contents Table of Contents... 2 Introduction... 3 HPE SecureData Appliance...
More informationThis report is based on sampled data. Jun 1 Jul 6 Aug 10 Sep 14 Oct 19 Nov 23 Dec 28 Feb 1 Mar 8 Apr 12 May 17 Ju
0 - Total Traffic Content View Query This report is based on sampled data. Jun 1, 2009 - Jun 25, 2010 Comparing to: Site 300 Unique Pageviews 300 150 150 0 0 Jun 1 Jul 6 Aug 10 Sep 14 Oct 19 Nov 23 Dec
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 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 informationC LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS
C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS Manish Dronacharya College Of Engineering, Maharishi Dayanand University, Gurgaon, Haryana, India III. Abstract- C Language History: The C programming language
More informationParameter passing. Programming in C. Important. Parameter passing... C implements call-by-value parameter passing. UVic SEng 265
Parameter passing Programming in C UVic SEng 265 Daniel M. German Department of Computer Science University of Victoria 1 SEng 265 dmgerman@uvic.ca C implements call-by-value parameter passing int a =
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 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 informationCSE 341 Section Handout #6 Cheat Sheet
Cheat Sheet Types numbers: integers (3, 802), reals (3.4), rationals (3/4), complex (2+3.4i) symbols: x, y, hello, r2d2 booleans: #t, #f strings: "hello", "how are you?" lists: (list 3 4 5) (list 98.5
More informationProject 1 System Calls
Project 1 System Calls Introduction In this project, you will become familiar with: 1. Using the xv6 Makefile 2. Using conditional compilation. 3. The xv6 system call invocation path. 4. Implementing a
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 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 informationSolved Exercises from exams: Midterm(1)
Solved Exercises from exams: Midterm(1) 1431-1432 1. What is the output of the following program: #include void fun(int *b) *b = *b+10; main() int a=50; fun(&a); cout
More informationC Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee
C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,
More information( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING UNIT V 2 MARKS
( Word to PDF Converter - Unregistered ) http://www.word-to-pdf-converter.net FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING FUNCTIONS AND POINTERS UNIT V Handling of Character Strings User-defined Functions
More informationToday s class. Finish review of C Process description and control. Informationsteknologi. Tuesday, September 18, 2007
Today s class Finish review of C Process description and control Computer Systems/Operating Systems - Class 6 1 Finish review of C Review in class exercise 3 #1: game cptr is 5004 #2: The value of c is
More informationCS1100 Introduction to Programming
CS1100 Introduction to Programming Arrays Madhu Mutyam Department of Computer Science and Engineering Indian Institute of Technology Madras Course Material SD, SB, PSK, NSN, DK, TAG CS&E, IIT M 1 An Array
More informationType Conversion. and. Statements
and Statements Type conversion changing a value from one type to another Void Integral Floating Point Derived Boolean Character Integer Real Imaginary Complex no fractional part fractional part 2 tj Suppose
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 informationPointer Arithmetic and Lexical Scoping. CS449 Spring 2016
Pointer Arithmetic and Lexical Scoping CS449 Spring 2016 Review Pitfall 1 from previous lecture void foo(char *s) { s = "World"; int main() { char *str = "Hello"; foo(str); printf("%s\n", str); return
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 informationCharacter Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Uppercase Alphabets Lowercase Alphabets Character Set A, B, C, Y, Z a, b, c, y, z Digits
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 informationCS 141, Introduction to Computer Science Fall Midterm Exam
CS 141, Introduction to Computer Science Fall 2006 Midterm Exam Name: Student ID: 1 (12 points) Data Types Where possible give 3 examples of possible values for each of the following data types. Use proper
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 informationPropedéutico de Programación
Propedéutico de Programación Coordinación de Ciencias Computacionales 2/13 Material preparado por: Dra. Pilar Gómez Gil Chapter 10 Simple Data Types: Built-In and User-Defined Dale/Weems C++ Simple Data
More information