Pointers CMPE-013/L. Pointers. Pointers What do they do? Pointers What are pointers? Gabriel Hugh Elkaim Winter 2014

Size: px
Start display at page:

Download "Pointers CMPE-013/L. Pointers. Pointers What do they do? Pointers What are pointers? Gabriel Hugh Elkaim Winter 2014"

Transcription

1 CMPE-013/L A Variable's versus A Variable's Value In some situations, we will want to work with a variable's address in memor, rather than the value it contains Gabriel Hugh Elkaim Winter 2014 Variable stored at Variable name from C code int ; Value of variable = A 0123 F00D 0456 of variable = What are ointers? A ointer is a variable or constant that holds the address of another variable or function What do the do? A ointer allows us to indirectl access a variable (just like indirect addressing in assembl language) Variable at Integer Variable: Pointer Variable: 0123 Direct Access via = 00123; * = 00123; Indirect Access via * 005A 0123 F00D 0456 oints to 1

2 Wh would I want to do that? make it ossible to write a ver short loo that erforms the same task on a range of memor locations / variables. Eamle: Data Buffer //Point to RAM buffer starting address char *bufptr = &buffer; while ((DataAvailable) && (ReceivedCharacter!= '\0')) //Read bte from UART and write it to RAM buffer ReadUART(bufPtr); //Point to net available bte in RAM buffer bufptr++; Eamle: Data Buffer RAM buffer allocated over a range of addresses (erhas an arra) Pseudo-code: (1) Point arrow to first address of buffer (2) Write data from UART to location ointed to b arrow (3) Move arrow to oint to net address in buffer (4) Reeat until data from UART is 0, or buffer is full (arrow oints to last address of buffer) Wh would I want to do that? AB CDEF BDF ACE 008BA 008BC 008BE 008C0 008C2 008C4 008C6 008C8 Where else are the used? Used in conjunction with dnamic memor allocation (creating variables at runtime) Provide method to ass arguments b referenceto functions Provide method to ass more than one iece of information into and out of a function A more efficient means of accessing arras and dealing with strings Snta te *trname; Eamle How to Create a Pointer Variable In the contet of a declaration, the *merel indicates that the variable is a ointer teis the te of data the ointer ma oint to Pointer usuall described as a ointer to te int *iptr; // Create a ointer to int float *fptr; // Create a ointer to float 2

3 Snta Eamle How to Create a Pointer Te with tedef tedef te *tename; A ointer variable can now be declared as te tenamewhich is a snonm for te The *is no longer needed since tenameelicitl identifies the variable as a ointer to te tedef int *intptr; // Create ointer to int te intptr ; // Create ointer to int // Equivalent to: int *; No *is used To set a ointer to oint to another variable, we use the &oerator (address of), and the ointer variable is used withoutthe dereference oerator *: This assigns the address of the variable to the ointer (now oints to ) Note: must be declared to oint to the te of (e.g. int ; int *;) Initialization = &; Usage When accessing the variable ointed to b a ointer, we use the ointer withthe dereference oerator *: = *; This assigns to the variable, the value of what is ointing to (from the last slide) Using *, is the same as using the variable it oints to (e.g. ) Eamle int, *; &is a constant ointer Another Wa To Look At The Snta It reresents the address of The address of will never change is a variable ointer to int //int and a ointer to int = &; //Assign the address of * = 5; //Same as = 5; It can be assigned the address of an int It ma be assigned a new address an time 3

4 Eamle int, *; Another Wa To Look At The Snta //1 int, 1 ointer to int = &; //Assign the address of * = 5; //Same as = 5; Contents of Letter (integer literal 5) 5 Another Wa To Look At The Snta * = 5; Contents of the Mailbo (variable or *) of Mailbo (&) *reresents the data ointed to b *ma be used anwhere ou would use *is the dereference oerator, also called the indirection oerator In the ointer declaration, the onl significance of *is to indicate that the variable is a ointer rather than an ordinar variable on Enveloe (ointer ) = &; Bank of Mailboes (memor locations) 105 How Work How Work Eamle Eamle int, ; int *; = 0; = 0; = &; * = 00100; = &; * = 00200; Variable at 008BA 008BC 008BE 008C0 008C2 008C4 008C6 008C8 int, ; int *; = 0; = 0; = &; * = 00100; = &; * = 00200; Variable at 008BA 008BC 008BE 008C0 008C2 008C4 008C6 008C8 4

5 How Work How Work Eamle Eamle int, ; int *; = 0; = 0; = &; * = 00100; = &; * = 00200; Variable at 008BA 008BC 008BE 008C0 008C2 008C4 008C6 008C8 int, ; int *; = 0; = 0; = &; * = 00100; = &; * = 00200; Variable at 08BC 008BA 008BC 008BE 008C0 008C2 008C4 008C6 008C8 How Work How Work Eamle Eamle int, ; int *; = 0; = 0; = &; * = 00100; = &; * = 00200; Variable at BC 008BA 008BC 008BE 008C0 008C2 008C4 008C6 008C8 int, ; int *; = 0; = 0; = &; * = 00100; = &; * = 00200; Variable at BE 008BA 008BC 008BE 008C0 008C2 008C4 008C6 008C8 5

6 Eamle int, ; int *; = 0; = 0; = &; * = 00100; = &; * = 00200; How Work Variable at BE 008BA 008BC 008BE 008C0 008C2 008C4 008C6 008C8 and Arras A Quick Reminder Arra elements occu consecutive memor locations int [3] = 1,2,3; can rovide an alternate method for accessing arra elements and Arras Initializing a Pointer to an Arra The arra name is the same thing as the address of its first (0 th ) element If we declare the following arra and ointer variable: int [5] = 1,2,3,4,5; int *; We can initialize the ointer to oint to the arra using an one of these three methods: = ; //Works onl for arras! = &; //Works for arras or variables = &; //This one is the most obvious Incrementing a ointer will move it to the net element of the arra More on this in just a bit and Arras A Preview of int [3] = 1,2,3; int *; = &; ++; 6

7 and Arras A Preview of Incrementing a ointer will move it to the net element of the arra int [3] = 1,2,3; int *; = &; ++; 0800 and Arras A Preview of Incrementing a ointer will move it to the net element of the arra int [3] = 1,2,3; int *; = &; ++; More on this in just a bit More on this in just a bit Incrementing Incrementing or decrementing a ointer will add or subtract a multile of the number of btes of its te If we have: float ; float * = &; ++; We will get = & + 4since a float variable occuies 4 btes of memor Eamle float *tr; Incrementing tr = &a; tr++; Incrementing trmoves it to the net sequential float arra element Words float a[0] float a[1] float a[2] float a[3] float a[4] float a[5] float a[6] float a[7] float a[8] A 0005C 0005E A 0006C 0006E

8 Larger Jums Larger Jums Adding or subtracting an other number with the ointer will change it b a multile of the number of btes of its te If we have int ; int * = &; += 3; We will get = & + 6since an int variable occuies 2 btes of memor Eamle float *tr; tr = &a; Adding 6 to trmoves it 6 floatarra elements ahead (24 btes ahead) tr += 6; Words float a[0] float a[1] float a[2] float a[3] float a[4] float a[5] float a[6] float a[7] float a[8] A 0005C 0005E A 0006C 0006E Eamle Eamle long [3] = 1,2,3; long * = &; long [3] = 1,2,3; long * = &; * += 4; ++; * = 0; ++; * = 0F1D0F00D; -= 2; * = 0BADF00D1; 0800 * += 4; ++; * = 0; ++; * = 0F1D0F00D; -= 2; * = 0BADF00D1;

9 Eamle Eamle long [3] = 1,2,3; long * = &; long [3] = 1,2,3; long * = &; * += 4; ++; * = 0; ++; * = 0F1D0F00D; -= 2; * = 0BADF00D1; * += 4; ++; * = 0; ++; * = 0F1D0F00D; -= 2; * = 0BADF00D1; Eamle Eamle long [3] = 1,2,3; long * = &; long [3] = 1,2,3; long * = &; * += 4; ++; * = 0; ++; * = 0F1D0F00D; -= 2; * = 0BADF00D1; * += 4; ++; * = 0; ++; * = 0F1D0F00D; -= 2; * = 0BADF00D1; 0005 F00D F1D

10 Eamle Eamle long [3] = 1,2,3; long * = &; long [3] = 1,2,3; long * = &; * += 4; ++; * = 0; ++; * = 0F1D0F00D; -= 2; * = 0BADF00D1; 0005 F00D F1D * += 4; ++; * = 0; ++; * = 0F1D0F00D; -= 2; * = 0BADF00D1; 00D1 BADF F00D F1D Post-Increment/Decrement Snta Rule Post-Increment / Decrement Snta Care must be taken with resect to oerator recedence when doing ointer arithmetic: Snta Oeration Descrition b Eamle *++ *(++) (*)++ Post-Increment Pointer Post-Increment data ointed to b Pointer z = *(++); is equivalent to: z = *; = + 1; z = (*)++; is equivalent to: z = *; * = * + 1; Eamle int [3] = 1,2,3; int ; int * = &; = 5 + *(++); = 5 + (*)++; *(++)is the same as*

11 Post-Increment / Decrement Snta Post-Increment / Decrement Snta Eamle Eamle int [3] = 1,2,3; int ; int * = &; int [3] = 1,2,3; int ; int * = &; = 5 + *(++); = 5 + *(++); = 5 + (*)++; = 5 + (*)++; 0006 *(++)is the same as*++ *(++)is the same as*++ Post-Increment / Decrement Snta Post-Increment / Decrement Snta Eamle Eamle int [3] = 1,2,3; int ; int * = &; int [3] = 1,2,3; int ; int * = &; = 5 + *(++); = 5 + *(++); = 5 + (*)++; 0007 = 5 + (*)++; 0007 *(++)is the same as*++ *(++)is the same as*++ 11

12 Pre-Increment/Decrement Snta Rule Pre-Increment / Decrement Snta Care must be taken with resect to oerator recedence when doing ointer arithmetic: Snta Oeration Descrition b Eamle ++* *(++) ++(*) Pre-Increment Pointer Pre-Increment data ointed to b Pointer z = *(++); is equivalent to: = + 1; z = *; z = ++(*); is equivalent to: * = * + 1; z = *; Eamle int [3] = 1,2,3; int ; int * = &; = 5 + *(++); = (*); *(++)is the same as* Pre-Increment / Decrement Snta Pre-Increment / Decrement Snta Eamle Eamle int [3] = 1,2,3; int ; int * = &; int [3] = 1,2,3; int ; int * = &; = 5 + *(++); = 5 + *(++); = (*); = (*); 0007 *(++)is the same as*++ *(++)is the same as*++ 12

13 Pre-Increment / Decrement Snta Pre-Increment / Decrement Snta Eamle Eamle int [3] = 1,2,3; int ; int * = &; int [3] = 1,2,3; int ; int * = &; = 5 + *(++); = 5 + *(++); = (*); 0007 = (*); 0008 *(++)is the same as*++ *(++)is the same as*++ Pre- and Post- Increment/Decrement Summar The arentheses determine what gets incremented/decremented: Modif the ointer itself *(++)or *++and *(++)or *++ Initialization Ti If a ointer isn't initialized to a secific address when it is created, it is a good idea to initialize it as NUL (ointing to nowhere) This will revent it from unintentionall corruting a memor location if it is accidentall used before it is initialized Modif the value ointed to b the ointer ++(*)and (*)++ Eamle int * = NULL; NULis the character '\0'but NULLis the value of a ointer that oints to nowhere 13

14 Eercise 11 and Pointer Arithmetic Oen the lab Project: Lab 11 and On the class website /Eamles/Lab11.zi -> Load Lab11.X 1 Oen MPLAB X and select Oen Project Icon (Ctrl + Shift + O) Oen the Project listed above. If ou alread have a roject oen in MPLAB X, close it b right clicking on the oen roject and selecting Close Eercise 11 and Solution: Stes 1, 2 and 3 /*############################################################################ # STEP 1: Initialize the ointer with the address of the variable ############################################################################*/ //Point to address of = &; /*############################################################################ # STEP 2: Comlete the following rintf() functions b adding in the # aroriate arguments as described in the control string. ############################################################################*/ rintf("the variable is located at address 0%X\n", &); rintf("the value of is %d\n", ); rintf("the ointer is located at address 0%X\n", &); rintf("the value of is 0%X\n", ); rintf("the value ointed to b * = %d\n", *); /*############################################################################ # STEP 3: Write the int value 10 to the location is currentl ointing to. ############################################################################*/ * = 10; Eercise 11 and Solution: Stes 4 and 5 /*############################################################################ # STEP 4: Increment the value that oints to. ############################################################################*/ //Increment arra element's value (*)++; rintf("[%d] = %d\n", i, *); /*############################################################################ # STEP 5: Increment the ointer so that it oints to the net item. ############################################################################*/ //Increment ointer to net arra element ++; 14

15 Eercise 11 Conclusions are variables that hold the address of other variables make it ossible for the rogram to change which variable is acted on b a articular line of code Incrementing and decrementing ointers will modif the value in multiles of the size of the te the oint to Questions? 15

16 16

17 17

18 18

19 19

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming 1 CMPE 013/L Gabriel Hugh Elkaim Sring 2013 2 A Variable's versus A Variable's Value In some situations, we will want to work with a variable's address in memor, rather than the value it contains Variable

More information

CMPE-013/L. Introduction to C Programming

CMPE-013/L. Introduction to C Programming CMPE-013/L Introduction to C Programming Gabriel Hugh Elkaim Winter 2015 and memory Pointer/array equivalency Pointer arithmetic and the stack and strings Arrays of ointers 1 Syntax tye *trname; How to

More information

Lecture06: Pointers 4/1/2013

Lecture06: Pointers 4/1/2013 Lecture06: Pointers 4/1/2013 Slides modified from Yin Lou, Cornell CS2022: Introduction to C 1 Pointers A ointer is a variable that contains the (memory) address of another variable What is a memory address?

More information

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming 1 2 3 CMPE 013/L and Strings Gabriel Hugh Elkaim Spring 2013 4 Definition are variables that can store many items of the same type. The individual items known as elements, are stored sequentially and are

More information

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming 1 2 3 4 CMPE 013/L Pointers and Functions Gabriel Hugh Elkaim Spring 2013 Pointers and Functions Passing Pointers to Functions Normally, functions operate on copies of the data passed to them (pass by

More information

type arrayname [ size type arrayname [ size ] = { item ,, item size size

type arrayname [ size type arrayname [ size ] = { item ,, item size size CMPE-3/L and Strings Gabriel Hugh Elkaim Winter 24 Definition are variables that can store many items of the same type. The individual items known as elements, are stored sequentially and are uniquely

More information

Assist. Prof. Dr. Caner ÖZCAN

Assist. Prof. Dr. Caner ÖZCAN Assist. Prof. Dr. Caner ÖZCAN Memory Structure When a variable defined it is stored somewhere in memory. Memory can be thought as block consist of cells. When a variable defined, required number of cell

More information

Pointers and Functions Passing Pointers to Functions CMPE-013/L. Pointers and Functions. Pointers and Functions Passing Pointers to Functions

Pointers and Functions Passing Pointers to Functions CMPE-013/L. Pointers and Functions. Pointers and Functions Passing Pointers to Functions CMPE-013/L Gabriel Hugh Elkaim Winter 2014 Passing Pointers to Functions Normally, functions operate on copies of the data passed to them (pass by value) int x = 2, y = 0; Value of variable passed to function

More information

Simple example. Analysis of programs with pointers. Points-to relation. Program model. Points-to graph. Ordering on points-to relation

Simple example. Analysis of programs with pointers. Points-to relation. Program model. Points-to graph. Ordering on points-to relation Simle eamle Analsis of rograms with ointers := 5 tr := @ *tr := 9 := rogram S1 S2 S3 S4 deendences What are the deendences in this rogram? Problem: just looking at variable names will not give ou the correct

More information

CS335 Fall 2007 Graphics and Multimedia. 2D Drawings: Lines

CS335 Fall 2007 Graphics and Multimedia. 2D Drawings: Lines CS335 Fall 007 Grahics and Multimedia D Drawings: Lines Primitive Drawing Oerations Digital Concets of Drawing in Raster Arras PIXEL is a single arra element at x, - No smaller drawing unit exists Px,

More information

Linear Data Structure Linked List

Linear Data Structure Linked List . Definition. Reresenting List in C. Imlementing the oerations a. Inserting a node b. Deleting a node c. List Traversal. Linked imlementation of Stack 5. Linked imlementation of Queue 6. Circular List

More information

Who. Winter Compiler Construction Generic compiler structure. Mailing list and forum. IC compiler. How

Who. Winter Compiler Construction Generic compiler structure. Mailing list and forum. IC compiler. How Winter 2007-2008 Comiler Construction 0368-3133 Mooly Sagiv and Roman Manevich School of Comuter Science Tel-Aviv University Who Roman Manevich Schreiber Oen-sace (basement) Tel: 640-5358 rumster@ost.tau.ac.il

More information

Definition. Pointers. Outline. Why pointers? Definition. Memory Organization Overview. by Ziad Kobti. Definition. Pointers enable programmers to:

Definition. Pointers. Outline. Why pointers? Definition. Memory Organization Overview. by Ziad Kobti. Definition. Pointers enable programmers to: Pointers by Ziad Kobti Deinition When you declare a variable o any tye, say: int = ; The system will automatically allocated the required memory sace in a seciic location (tained by the system) to store

More information

[0569] p 0318 garbage

[0569] p 0318 garbage A Pointer is a variable which contains the address of another variable. Declaration syntax: Pointer_type *pointer_name; This declaration will create a pointer of the pointer_name which will point to the

More information

Shuigeng Zhou. May 18, 2016 School of Computer Science Fudan University

Shuigeng Zhou. May 18, 2016 School of Computer Science Fudan University Query Processing Shuigeng Zhou May 18, 2016 School of Comuter Science Fudan University Overview Outline Measures of Query Cost Selection Oeration Sorting Join Oeration Other Oerations Evaluation of Exressions

More information

Storage Allocation CSE 143. Pointers, Arrays, and Dynamic Storage Allocation. Pointer Variables. Pointers: Review. Pointers and Types

Storage Allocation CSE 143. Pointers, Arrays, and Dynamic Storage Allocation. Pointer Variables. Pointers: Review. Pointers and Types CSE 143 Pointers, Arrays, and Dynamic Storage Allocation [Chater 4,. 148-157, 172-177] Storage Allocation Storage (memory) is a linear array of cells (bytes) Objects of different tyes often reuire differing

More information

CS 548: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE

CS 548: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE CS 548: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 05 DR. MICHAEL J. REALE OPENGL POINTS AND LINES OPENGL POINTS AND LINES In OenGL, there are different constants used to indicate what ind of rimitive

More information

Introduction to Computer Science Midterm 3 Fall, Points

Introduction to Computer Science Midterm 3 Fall, Points Introduction to Computer Science Fall, 2001 100 Points Notes 1. Tear off this sheet and use it to keep your answers covered at all times. 2. Turn the exam over and write your name next to the staple. Do

More information

Data, memory. Pointers and Dynamic Variables. Example. Pointers Variables (or Pointers) Fall 2018, CS2

Data, memory. Pointers and Dynamic Variables. Example. Pointers Variables (or Pointers) Fall 2018, CS2 Data, memor Pointers and Dnamic Variables Fall 2018, CS2 memor address: ever bte is identified b a numeric address in the memor. a data value requiring multiple btes are stored consecutivel in memor cells

More information

What is an algorithm?

What is an algorithm? Announcements CS 142 C++ Pointers Reminder Program 6 due Sunday, Nov. 9 th by 11:55pm 11/3/2014 2 Pointers and the Address Operator Pointer Variables Each variable in a program is stored at a unique address

More information

Example: Runtime Memory Allocation: Example: Dynamical Memory Allocation: Some Comments: Allocate and free dynamic memory

Example: Runtime Memory Allocation: Example: Dynamical Memory Allocation: Some Comments: Allocate and free dynamic memory Runtime Memory Allocation: Examle: All external and static variables Global systemcontrol Suose we want to design a rogram for handling student information: tyedef struct { All dynamically allocated variables

More information

Applications of Pointers (1A) Young Won Lim 3/21/18

Applications of Pointers (1A) Young Won Lim 3/21/18 (1A) Coyright (c) 2010-2018 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version ublished

More information

Applications of Pointers (1A) Young Won Lim 3/14/18

Applications of Pointers (1A) Young Won Lim 3/14/18 (1A) Coyright (c) 2010-2018 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version ublished

More information

Applications of Pointers (1A) Young Won Lim 4/24/18

Applications of Pointers (1A) Young Won Lim 4/24/18 (1A) Coyright (c) 2010-2018 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version ublished

More information

Classes. Code Generation for Objects. Compiling Methods. Dynamic Dispatch. The Need for Dispatching CS412/CS413

Classes. Code Generation for Objects. Compiling Methods. Dynamic Dispatch. The Need for Dispatching CS412/CS413 Classes CS4/CS43 Introduction to Comilers Tim Teitelbaum Lecture : Imlementing Objects 8 March 5 Comonents ields/instance variables values ma dier rom object to object usuall mutable methods values shared

More information

Storage Class Specifiers Scope and Lifetime of Variables CMPE-013/L. Modules and Scope. Storage Class Specifiers Automatic Variables

Storage Class Specifiers Scope and Lifetime of Variables CMPE-013/L. Modules and Scope. Storage Class Specifiers Automatic Variables CMPE-013/L Modules and Scope Gabriel Hugh Elkaim Winter 2014 Scope and Lifetime of Variables Scope and lifetime of a variable depends on its storage class: Automatic Variables Static Variables External

More information

Applications of Pointers (1A) Young Won Lim 4/11/18

Applications of Pointers (1A) Young Won Lim 4/11/18 (1A) Coyright (c) 2010-2018 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version ublished

More information

To Do. Computer Graphics (Fall 2004) Course Outline. Course Outline. Motivation. Motivation

To Do. Computer Graphics (Fall 2004) Course Outline. Course Outline. Motivation. Motivation Comuter Grahics (Fall 24) COMS 416, Lecture 3: ransformations 1 htt://www.cs.columbia.edu/~cs416 o Do Start (thinking about) assignment 1 Much of information ou need is in this lecture (slides) Ask A NOW

More information

14. Memory API. Operating System: Three Easy Pieces

14. Memory API. Operating System: Three Easy Pieces 14. Memory API Oerating System: Three Easy Pieces 1 Memory API: malloc() #include void* malloc(size_t size) Allocate a memory region on the hea. w Argument size_t size : size of the memory block(in

More information

Winter Compiler Construction T9 IR part 2 + Runtime organization. Announcements. Today. Know thy group s code

Winter Compiler Construction T9 IR part 2 + Runtime organization. Announcements. Today. Know thy group s code Winter 26-27 Compiler Construction T9 IR part 2 + Runtime organization Mool Sagiv and Roman Manevich School of Computer Science Tel-Aviv Universit Announcements What is epected in PA3 documentation (5

More information

EECS1022 Winter 2018 Additional Notes Tracing Point, PointCollector, and PointCollectorTester

EECS1022 Winter 2018 Additional Notes Tracing Point, PointCollector, and PointCollectorTester EECS1022 Winter 2018 Additional Notes Tracing, Collector, and CollectorTester Chen-Wei Wang Contents 1 Class 1 2 Class Collector 2 Class CollectorTester 7 1 Class 1 class { 2 double ; double ; 4 (double

More information

Personal SE. Arrays Pointers Strings

Personal SE. Arrays Pointers Strings Personal SE Arrays Pointers Strings Array Identifiers & Pointers char message[] = Hello ; message H e l l o \0 Array Identifiers & Pointers char message[] = Hello ; message H e l l o \0 Question: So what

More information

Informatics Ingeniería en Electrónica y Automática Industrial

Informatics Ingeniería en Electrónica y Automática Industrial Informatics Ingeniería en Electrónica y Automática Industrial Operators and expressions in C Operators and expressions in C Numerical expressions and operators Arithmetical operators Relational and logical

More information

Homework #3 CS2255 Fall 2012

Homework #3 CS2255 Fall 2012 Homework #3 CS2255 Fall 2012 MULTIPLE CHOICE 1. The, also known as the address operator, returns the memory address of a variable. a. asterisk ( * ) b. ampersand ( & ) c. percent sign (%) d. exclamation

More information

Applications of Pointers (1A) Young Won Lim 2/27/18

Applications of Pointers (1A) Young Won Lim 2/27/18 Alications of (1A) Coyright (c) 2010-2018 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Applications of Pointers (1A) Young Won Lim 3/31/18

Applications of Pointers (1A) Young Won Lim 3/31/18 (1A) Coyright (c) 2010-2018 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version ublished

More information

Applications of Pointers (1A) Young Won Lim 1/5/18

Applications of Pointers (1A) Young Won Lim 1/5/18 Alications of (1A) Coyright (c) 2010-2017 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Functions CMPE-013/L. Functions. Functions What is a function? Functions Remember Algebra Class? Gabriel Hugh Elkaim Winter 2014.

Functions CMPE-013/L. Functions. Functions What is a function? Functions Remember Algebra Class? Gabriel Hugh Elkaim Winter 2014. CMPE-013/L Program Structure Gabriel Hugh Elkaim Winter 2014 main()... eat();... drink();... eat()... return; drink()... be_merry(); return; be_merry()... return; Definition What is a function? are self

More information

Pointers (1A) Young Won Lim 12/4/17

Pointers (1A) Young Won Lim 12/4/17 Pointers (1A) Coyright (c) 2010-2017 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

A flow chart is a graphical or symbolic representation of a process.

A flow chart is a graphical or symbolic representation of a process. Q1. Define Algorithm with example? Answer:- A sequential solution of any program that written in human language, called algorithm. Algorithm is first step of the solution process, after the analysis of

More information

Goals of this Lecture

Goals of this Lecture C Pointers Goals of this Lecture Help you learn about: Pointers and application Pointer variables Operators & relation to arrays 2 Pointer Variables The first step in understanding pointers is visualizing

More information

Wednesday, February 19, 2014

Wednesday, February 19, 2014 Wednesda, Februar 19, 2014 Topics for toda Solutions to HW #2 Topics for Eam #1 Chapter 6: Mapping High-level to assembl-level The Pep/8 run-time stack Stack-relative addressing (,s) SP manipulation Stack

More information

CS 450: COMPUTER GRAPHICS 2D TRANSFORMATIONS SPRING 2016 DR. MICHAEL J. REALE

CS 450: COMPUTER GRAPHICS 2D TRANSFORMATIONS SPRING 2016 DR. MICHAEL J. REALE CS 45: COMUTER GRAHICS 2D TRANSFORMATIONS SRING 26 DR. MICHAEL J. REALE INTRODUCTION Now that we hae some linear algebra under our resectie belts, we can start ug it in grahics! So far, for each rimitie,

More information

Pointer Basics. Lecture 13 COP 3014 Spring March 28, 2018

Pointer Basics. Lecture 13 COP 3014 Spring March 28, 2018 Pointer Basics Lecture 13 COP 3014 Spring 2018 March 28, 2018 What is a Pointer? A pointer is a variable that stores a memory address. Pointers are used to store the addresses of other variables or memory

More information

2. Introduction to Operating Systems

2. Introduction to Operating Systems 2. Introduction to Oerating Systems Oerating System: Three Easy Pieces 1 What a haens when a rogram runs? A running rogram executes instructions. 1. The rocessor fetches an instruction from memory. 2.

More information

C++ for Java Programmers

C++ for Java Programmers Basics all Finished! Everything we have covered so far: Lecture 5 Operators Variables Arrays Null Terminated Strings Structs Functions 1 2 45 mins of pure fun Introduction Today: Pointers Pointers Even

More information

CS 403 Compiler Construction Lecture 8 Syntax Tree and Intermediate Code Generation [Based on Chapter 6 of Aho2] This Lecture

CS 403 Compiler Construction Lecture 8 Syntax Tree and Intermediate Code Generation [Based on Chapter 6 of Aho2] This Lecture CS 403 Compiler Construction Lecture 8 Snta Tree and Intermediate Code Generation [Based on Chapter 6 of Aho2] 1 This Lecture 2 1 Remember: Phases of a Compiler This lecture: Intermediate Code This lecture:

More information

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands Introduction Operators are the symbols which operates on value or a variable. It tells the compiler to perform certain mathematical or logical manipulations. Can be of following categories: Unary requires

More information

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each): FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each): 1. If a function has default arguments, they can be located anywhere

More information

Arrays, Pointers and Memory Management

Arrays, Pointers and Memory Management Arrays, Pointers and Memory Management EECS 2031 Summer 2014 Przemyslaw Pawluk May 20, 2014 Answer to the question from last week strct->field Returns the value of field in the structure pointed to by

More information

Pointers (1A) Young Won Lim 10/18/17

Pointers (1A) Young Won Lim 10/18/17 Pointers (1A) Coyright (c) 2010-2013 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

C-LANGUAGE CURRICULAM

C-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 information

Chapter 12 Variables and Operators

Chapter 12 Variables and Operators Chapter 12 Variables and Operators Basic C Elements Variables Named, typed data items Operators Predefined actions performed on data items Combined with variables to form expressions, statements Statements

More information

Chapter 11: Pointers

Chapter 11: Pointers Chapter 11: Pointers Christian Jacob 1 Pointer Basics 3 1.1 What Are Pointers? 3 1.2 Pointer Operators 4 1.3 Pointer Expressions 14 2 Pointers and Arrays 19 2.1 Pointer Arithmetic And Array Indexing 19

More information

Chapter 12 Variables and Operators

Chapter 12 Variables and Operators Chapter 12 Variables and Operators Highlights (1) r. height width operator area = 3.14 * r *r + width * height literal/constant variable expression (assignment) statement 12-2 Highlights (2) r. height

More information

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming 1 Literal Constants Definition A literal or a literal constant is a value, such as a number, character or string, which may be assigned to a variable or a constant. It may also be used directly as a function

More information

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty!

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty! Chapter 6 - Functions return type void or a valid data type ( int, double, char, etc) name parameter list void or a list of parameters separated by commas body return keyword required if function returns

More information

Typical Compiler. Ahead- of- time compiler. Compilers... that target interpreters. Interpreter 12/9/15. compile time. run time

Typical Compiler. Ahead- of- time compiler. Compilers... that target interpreters. Interpreter 12/9/15. compile time. run time Ahead- of- time Tpical Compiler compile time C source C 86 assembl 86 assembler 86 machine Source Leical Analzer Snta Analzer Semantic Analzer Analsis Intermediate Code Generator Snthesis run time 86 machine

More information

42. Crash Consistency: FSCK and Journaling

42. Crash Consistency: FSCK and Journaling 42. Crash Consistency: FSCK and Journaling Oerating System: Three Easy Pieces AOS@UC 1 Crash Consistency AOS@UC 2 Crash Consistency Unlike most data structure, file system data structures must ersist w

More information

Object Oriented Programming Using C++ Mathematics & Computing IET, Katunayake

Object Oriented Programming Using C++ Mathematics & Computing IET, Katunayake Assigning Values // Example 2.3(Mathematical operations in C++) float a; cout > a; cout

More information

Pointers. 10/5/07 Pointers 1

Pointers. 10/5/07 Pointers 1 Pointers 10/5/07 Pointers 1 10/5/07 Pointers 2 Variables Essentially, the computer's memory is made up of bytes. Each byte has an address, associated with it. 10/5/07 Pointers 3 Variable For example 1:#include

More information

Programming Language Dilemma Fall 2002 Lecture 1 Introduction to Compilation. Compilation As Translation. Starting Point

Programming Language Dilemma Fall 2002 Lecture 1 Introduction to Compilation. Compilation As Translation. Starting Point Programming Language Dilemma 6.035 Fall 2002 Lecture 1 Introduction to Compilation Martin Rinard Laborator for Computer Science Massachusetts Institute of Technolog Stored program computer How to instruct

More information

Reference operator (&)

Reference operator (&) Pointers Each cell can be easily located in the memory because it has a unique address and all the memory cells follow a successive pattern. For example, if we are looking for cell 1776 we know that it

More information

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

CprE 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 information

Pointers (1A) Young Won Lim 10/23/17

Pointers (1A) Young Won Lim 10/23/17 Pointers (1A) Coyright (c) 2010-2013 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

Language comparison. C has pointers. Java has references. C++ has pointers and references

Language 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 information

pointers + memory double x; string a; int x; main overhead int y; main overhead

pointers + memory double x; string a; int x; main overhead int y; main overhead pointers + memory computer have memory to store data. every program gets a piece of it to use as we create and use more variables, more space is allocated to a program memory int x; double x; string a;

More information

Pointers. Variable Declaration. Chapter 10

Pointers. Variable Declaration. Chapter 10 Pointers Chapter 10 Variable Declaration When a variable is defined, three fundamental attributes are associated with it: Name Type Address The variable definition associates the name, the type, and the

More information

a data type is Types

a 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 information

CSE4421/5324: Introduction to Robotics

CSE4421/5324: Introduction to Robotics CSE442/5324: Introduction to Robotics Contact Information Burton Ma Lassonde 246 burton@cse.yorku.ca EECS442/5324 lectures Monday, Wednesday, Friday :3-2:3PM (SLH C) Lab Thursday 2:3-2:3, Prism 4 Lab 2

More information

Monday, September 28, 2015

Monday, September 28, 2015 Monda, September 28, 2015 Topics for toda Chapter 6: Mapping High-level to assembl-level The Pep/8 run-time stack (6.1) Stack-relative addressing (,s) SP manipulation Stack as scratch space Global variables

More information

CME 112- Programming Languages II. Week 4 Pointers

CME 112- Programming Languages II. Week 4 Pointers 1 CME 112- Programming Languages II Week 4 Pointers Assist. Prof. Dr. Caner Özcan Kindness is the golden chain by which society is bound together. ~Goethe Memory Structure 2 When a variable defined it

More information

Pointer in C SHARDA UNIVERSITY. Presented By: Pushpendra K. Rajput Assistant Professor

Pointer in C SHARDA UNIVERSITY. Presented By: Pushpendra K. Rajput Assistant Professor Pointer in C Presented By: Pushpendra K. Rajput Assistant Professor 1 Introduction The Pointer is a Variable which holds the Address of the other Variable in same memory. Such as Arrays, structures, and

More information

POINTER & REFERENCE VARIABLES

POINTER & REFERENCE VARIABLES Lecture 9 POINTER & REFERENCE VARIABLES Declaring data pointer variables Assignment operations with pointers Referring objects using pointer variables Generic pointers Operations with pointer variables

More information

Lecture 7: Objects (Chapter 15) CS 1110 Introduction to Computing Using Python

Lecture 7: Objects (Chapter 15) CS 1110 Introduction to Computing Using Python htt://www.cs.cornell.edu/courses/cs1110/2018s Lecture 7: Objects (Chater 15) CS 1110 Introduction to Comuting Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner, C. Van Loan, W. White]

More information

Intermediate Programming, Spring 2017*

Intermediate Programming, Spring 2017* 600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general

More information

Sage Estimating (formerly Sage Timberline Estimating) Getting Started Guide. Version has been retired. This version of the software

Sage Estimating (formerly Sage Timberline Estimating) Getting Started Guide. Version has been retired. This version of the software Sage Estimating (formerly Sage Timberline Estimating) Getting Started Guide Version 14.12 This version of the software has been retired This is a ublication of Sage Software, Inc. Coyright 2014. Sage Software,

More information

ECE 30 Introduction to Computer Engineering

ECE 30 Introduction to Computer Engineering ECE 30 Introduction to Computer Engineering Study Problems, Set #3 Spring 2015 Use the MIPS assembly instructions listed below to solve the following problems. arithmetic add add sub subtract addi add

More information

EE 472: Pointers. 1 Memory Addresses and Pointers. James Peckol and Blake Hannaford Department of Electrical Engineering The University of Washington

EE 472: Pointers. 1 Memory Addresses and Pointers. James Peckol and Blake Hannaford Department of Electrical Engineering The University of Washington EE 472: Pointers James Peckol and Blake Hannaford Department of Electrical Engineering The University of Washington October 6, 2005 1 Memory Addresses and Pointers Consider the following code: \\ variable

More information

C Pointers. Indirection Indirection = referencing a value through a pointer. Creating Pointers. Pointer Declarations. Pointer Declarations

C Pointers. Indirection Indirection = referencing a value through a pointer. Creating Pointers. Pointer Declarations. Pointer Declarations 55:017, Computers in Engineering C Pointers C Pointers Powerful C feature but challenging to understand Some uses of pointers include Call by reference parameter passage Dynamic data structures Data structures

More information

Chapter 12 Variables and Operators

Chapter 12 Variables and Operators Basic C Elements Chapter 12 Variables and Operators Original slides from Gregory Byrd, North Carolina State University! Variables named, typed data items! Operators predefined actions performed on data

More information

Computers Programming Course 6. Iulian Năstac

Computers Programming Course 6. Iulian Năstac Computers Programming Course 6 Iulian Năstac Recap from previous course Data types four basic arithmetic type specifiers: char int float double void optional specifiers: signed, unsigned short long 2 Recap

More information

Object oriented programming C++

Object oriented programming C++ http://uranchimeg.com Object oriented programming C++ T.Uranchimeg Prof. Dr. Email uranchimeg@must.edu.mn Power Engineering School M.EC203* -- OOP (C++) -- Lecture 07 Subjects Pointers Pointer and array

More information

Example: Pointer Basics

Example: Pointer Basics Example: Pointer Basics #include int (void) { float a1, a2; /* Simple variables */ float *p1, *p2, *w; /* Pointers to variables of type float */ a1 = 10.0, a2 = 20.0; printf("after a1 = 10.0;

More information

CSI33 Data Structures

CSI33 Data Structures Outline Department of Mathematics and Computer Science Bronx Community College October 24, 2018 Outline Outline 1 Chapter 8: A C++ Introduction For Python Programmers Expressions and Operator Precedence

More information

OBJECT ORIENTED PROGRAMMING

OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING LAB 1 REVIEW THE STRUCTURE OF A C/C++ PROGRAM. TESTING PROGRAMMING SKILLS. COMPARISON BETWEEN PROCEDURAL PROGRAMMING AND OBJECT ORIENTED PROGRAMMING Course basics The Object

More information

Sage Estimating. (formerly Sage Timberline Estimating) Getting Started Guide

Sage Estimating. (formerly Sage Timberline Estimating) Getting Started Guide Sage Estimating (formerly Sage Timberline Estimating) Getting Started Guide This is a ublication of Sage Software, Inc. Document Number 20001S14030111ER 09/2012 2012 Sage Software, Inc. All rights reserved.

More information

Introduction to Linked Lists

Introduction to Linked Lists Introduction to Linked Lists In your previous programming course, you organized and processed data items sequentially using an array (or possibly an arraylist, or a vector). You probably performed several

More information

CSC 211 Intermediate Programming. Arrays & Pointers

CSC 211 Intermediate Programming. Arrays & Pointers CSC 211 Intermediate Programming Arrays & Pointers 1 Definition An array a consecutive group of memory locations that all have the same name and the same type. To create an array we use a declaration statement.

More information

Chapter 12 Variables and Operators

Chapter 12 Variables and Operators Basic C Elements Chapter 12 Variables and Operators Original slides from Gregory Byrd, North Carolina State University! Variables named, typed data items! Operators predefined actions performed on data

More information

CS 31: Intro to Systems Pointers and Memory. Kevin Webb Swarthmore College October 2, 2018

CS 31: Intro to Systems Pointers and Memory. Kevin Webb Swarthmore College October 2, 2018 CS 31: Intro to Systems Pointers and Memory Kevin Webb Swarthmore College October 2, 2018 Overview How to reference the location of a variable in memory Where variables are placed in memory How to make

More information

Pointers. Reference operator (&) ted = &andy;

Pointers. Reference operator (&)  ted = &andy; Pointers We have already seen how variables are seen as memory cells that can be accessed using their identifiers. This way we did not have to care about the physical location of our data within memory,

More information

CS2351 Data Structures. Lecture 7: A Brief Review of Pointers in C

CS2351 Data Structures. Lecture 7: A Brief Review of Pointers in C CS2351 Data Structures Lecture 7: A Brief Review of Pointers in C 1 About this lecture Pointer is a useful object that allows us to access different places in our memory We will review the basic use of

More information

CSCI 2212: Intermediate Programming / C Review, Chapters 10 and 11

CSCI 2212: Intermediate Programming / C Review, Chapters 10 and 11 ... 1/16 CSCI 2212: Intermediate Programming / C Review, Chapters 10 and 11 Alice E. Fischer February 3, 2016 ... 2/16 Outline Basic Types and Diagrams ... 3/16 Basic Types and Diagrams Types in C C has

More information

search(i): Returns an element in the data structure associated with key i

search(i): Returns an element in the data structure associated with key i CS161 Lecture 7 inary Search Trees Scribes: Ilan Goodman, Vishnu Sundaresan (2015), Date: October 17, 2017 Virginia Williams (2016), and Wilbur Yang (2016), G. Valiant Adated From Virginia Williams lecture

More information

Variables and Operators 2/20/01 Lecture #

Variables and Operators 2/20/01 Lecture # Variables and Operators 2/20/01 Lecture #6 16.070 Variables, their characteristics and their uses Operators, their characteristics and their uses Fesq, 2/20/01 1 16.070 Variables Variables enable you to

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

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

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 Introduction C++ Memory Map Free Stores Declaration and Initialization of pointers Dynamic allocation operators Pointers and Arrays Pointers and Const Pointers and Function Pointer and Structures

More information

Raster Graphics Algorithms

Raster Graphics Algorithms Overview of Grahics Pieline Raster Grahics Algorithms D scene atabase traverse geometric moel transform to worl sace transform to ee sace scan conversion Line rasterization Bresenham s Mioint line algorithm

More information

has been retired This version of the software Sage Timberline Office Get Started Document Management 9.8 NOTICE

has been retired This version of the software Sage Timberline Office Get Started Document Management 9.8 NOTICE This version of the software has been retired Sage Timberline Office Get Started Document Management 9.8 NOTICE This document and the Sage Timberline Office software may be used only in accordance with

More information