Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming
|
|
- Kerry Griffin
- 6 years ago
- Views:
Transcription
1 1
2 CMPE 013/L Gabriel Hugh Elkaim Sring
3 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 stored at Variable name from C code int x; Value of variable x = 0x0123 x 005A 0123 DEAD BEEF F00D 0456 of variable x = What are ointers? A ointer is a variable or constant that holds the address of another variable or function Variable at Integer Variable: Pointer Variable: x FFFF 0123 FFFF 0802 FFFF FFFF 3
4 What do the do? A ointer allows us to indirectl access a variable (just like indirect addressing in assembl language) Direct Access via x x = 0x0123; * = 0x0123; Indirect Access via * 005A x 0123 DEAD 0802 F00D 0456 oints to x 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. : 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 next available bte in RAM buffer bufptr++; 4
5 Wh would I want to do that? : 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 next address in buffer (4) Reeat until data from UART is 0, or buffer is full (arrow oints to last address of buffer) AB CDEF BDF ACE 0x08BA 0x08BC 0x08BE 0x08C0 0x08C2 0x08C4 0x08C6 0x08C8 Where else are the used? Used in conjunction with dnamic memor allocation (creating variables at runtime) Provide method to ass arguments b reference to 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 5
6 Sntax te *trname; How to Create a Pointer Variable In the context of a declaration, the * merel indicates that the variable is a ointer te is the te of data the ointer ma oint to Pointer usuall described as a ointer to te int *iptr; float *fptr; // Create a ointer to int // Create a ointer to float Sntax How to Create a Pointer Te with tedef tedef te *tename; A ointer variable can now be declared as te tename which is a snonm for te The * is no longer needed since tename exlicitl 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 6
7 To set a ointer to oint to another variable, we use the & oerator (address of), and the ointer variable is used without the dereference oerator *: This assigns the address of the variable x to the ointer ( now oints to x) Note: must be declared to oint to the te of x (e.g. int x; int *;) Initialization = &x; Usage When accessing the variable ointed to b a ointer, we use the ointer with the dereference oerator *: = *; This assigns to the variable, the value of what is ointing to (x from the last slide) Using *, is the same as using the variable it oints to (e.g. x) 7
8 Another Wa To Look At The Sntax int x, *; //int and a ointer to int = &x; //Assign the address of x * = 5; //Same as x = 5; &xis a constant ointer It reresents the address of x The address of x will never change is a variable ointer to int It can be assigned the address of an int It ma be assigned a new address an time Another Wa To Look At The Sntax int x, *; //1 int, 1 ointer to int = &x; //Assign the address of x * = 5; //Same as x = 5; *reresents the data ointed to b *ma be used anwhere ou would use x *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 8
9 Contents of Letter (integer literal 5) Another Wa To Look At The Sntax * = 5; Contents of the Mailbox (variable x or *) of Mailbox (&x) 105 on Enveloe (ointer ) = &x; Bank of Mailboxes (memor locations) How Work int x, ; int *; Variable at 0x08BA x = 0xDEAD; = 0xBEEF; = &x; * = 0x0100; = &; * = 0x0200; x 0x08BC 0x08BE 0x08C0 0x08C2 0x08C4 0x08C6 0x08C8 9
10 How Work int x, ; int *; Variable at 0x08BA x = 0xDEAD; = 0xBEEF; = &x; * = 0x0100; = &; * = 0x0200; x DEAD 0x08BC 0x08BE 0x08C0 0x08C2 0x08C4 0x08C6 0x08C8 How Work int x, ; int *; Variable at 0x08BA x = 0xDEAD; = 0xBEEF; = &x; * = 0x0100; = &; * = 0x0200; x DEAD BEEF 0x08BC 0x08BE 0x08C0 0x08C2 0x08C4 0x08C6 0x08C8 10
11 How Work int x, ; int *; Variable at 0x08BA x = 0xDEAD; = 0xBEEF; = &x; * = 0x0100; = &; * = 0x0200; x DEAD BEEF 08BC 0x08BC 0x08BE 0x08C0 0x08C2 0x08C4 0x08C6 0x08C8 How Work int x, ; int *; Variable at 0x08BA x = 0xDEAD; = 0xBEEF; = &x; * = 0x0100; = &; * = 0x0200; x 0100 BEEF 08BC 0x08BC 0x08BE 0x08C0 0x08C2 0x08C4 0x08C6 0x08C8 11
12 How Work int x, ; int *; Variable at 0x08BA x = 0xDEAD; = 0xBEEF; = &x; * = 0x0100; = &; * = 0x0200; x 0100 BEEF 08BE 0x08BC 0x08BE 0x08C0 0x08C2 0x08C4 0x08C6 0x08C8 How Work int x, ; int *; Variable at 0x08BA x = 0xDEAD; = 0xBEEF; = &x; * = 0x0100; = &; * = 0x0200; x BE 0x08BC 0x08BE 0x08C0 0x08C2 0x08C4 0x08C6 0x08C8 12
13 and Arras A Quick Reminder Arra elements occu consecutive memor locations int x[3] = 1,2,3; FFFF FFFF 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 x[5] = 1,2,3,4,5; int *; We can initialize the ointer to oint to the arra using an one of these three methods: = x; = &x; = &; //Works onl for arras! //Works for arras or variables //This one is the most obvious 13
14 and Arras A Preview of Pointer Arithmetic Incrementing a ointer will move it to the next element of the arra int x[3] = 1,2,3; int *; = &x; ++; FFFF FFFF More on this in just a bit and Arras A Preview of Pointer Arithmetic Incrementing a ointer will move it to the next element of the arra int x[3] = 1,2,3; int *; = &x; ++; FFFF More on this in just a bit 14
15 and Arras A Preview of Pointer Arithmetic Incrementing a ointer will move it to the next element of the arra int x[3] = 1,2,3; int *; = &x; ++; FFFF More on this in just a bit Pointer Arithmetic Incrementing Incrementing or decrementing a ointer will add or subtract a multile of the number of btes of its te If we have: float x; float * = &x; ++; We will get = &x + 4 since a float variable occuies 4 btes of memor 15
16 Pointer Arithmetic Incrementing float *tr; tr = &a; tr++; Incrementing tr moves it to the next 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] 0x0050 0x0052 0x0054 0x0056 0x0058 0x005A 0x005C 0x005E 0x0060 0x0062 0x0064 0x0066 0x0068 0x006A 0x006C 0x006E 0x0070 0x0072 0x0074 0x0076 Pointer Arithmetic 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 x; int * = &x; += 3; We will get = &x + 6 since an int variable occuies 2 btes of memor 16
17 Pointer Arithmetic Larger Jums float *tr; tr = &a; Adding 6 to tr moves it 6 float arra 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] 0x0050 0x0052 0x0054 0x0056 0x0058 0x005A 0x005C 0x005E 0x0060 0x0062 0x0064 0x0066 0x0068 0x006A 0x006C 0x006E 0x0070 0x0072 0x0074 0x0076 Pointer Arithmetic long x[3] = 1,2,3; long * = &x; * += 4; ++; * = 0xDEADBEEF; ++; * = 0xF1D0F00D; -= 2; * = 0xBADF00D1;
18 Pointer Arithmetic long x[3] = 1,2,3; long * = &x; * += 4; ++; * = 0xDEADBEEF; ++; * = 0xF1D0F00D; -= 2; * = 0xBADF00D1; Pointer Arithmetic long x[3] = 1,2,3; long * = &x; * += 4; ++; * = 0xDEADBEEF; ++; * = 0xF1D0F00D; -= 2; * = 0xBADF00D1;
19 Pointer Arithmetic long x[3] = 1,2,3; long * = &x; * += 4; ++; * = 0xDEADBEEF; ++; * = 0xF1D0F00D; -= 2; * = 0xBADF00D1; 0005 BEEF DEAD 0804 Pointer Arithmetic long x[3] = 1,2,3; long * = &x; * += 4; ++; * = 0xDEADBEEF; ++; * = 0xF1D0F00D; -= 2; * = 0xBADF00D1; 0005 BEEF DEAD
20 Pointer Arithmetic long x[3] = 1,2,3; long * = &x; * += 4; ++; * = 0xDEADBEEF; ++; * = 0xF1D0F00D; -= 2; * = 0xBADF00D1; 0005 BEEF DEAD F00D F1D Pointer Arithmetic long x[3] = 1,2,3; long * = &x; * += 4; ++; * = 0xDEADBEEF; ++; * = 0xF1D0F00D; -= 2; * = 0xBADF00D1; 0005 BEEF DEAD F00D F1D
21 Pointer Arithmetic long x[3] = 1,2,3; long * = &x; * += 4; ++; * = 0xDEADBEEF; ++; * = 0xF1D0F00D; -= 2; * = 0xBADF00D1; 00D1 BADF BEEF DEAD F00D F1D Post Increment/Decrement Sntax Rule Care must be taken with resect to oerator recedence when doing ointer arithmetic: Sntax Oeration Descrition b *++ *(++) (*)++ Post Increment Pointer Post Increment data ointed to b Pointer z = *(++); is equivalent to: z = *; = + 1; z = (*)++; is equivalent to: z = *; * = * + 1; 21
22 Post Increment / Decrement Sntax int x[3] = 1,2,3; int ; int * = &x; = 5 + *(++); = 5 + (*)++; Remember: *(++) is the same as * Post Increment / Decrement Sntax int x[3] = 1,2,3; int ; int * = &x; = 5 + *(++); = 5 + (*)++; Remember: *(++) is the same as *
23 Post Increment / Decrement Sntax int x[3] = 1,2,3; int ; int * = &x; = 5 + *(++); = 5 + (*)++; Remember: *(++) is the same as * Post Increment / Decrement Sntax int x[3] = 1,2,3; int ; int * = &x; = 5 + *(++); = 5 + (*)++; Remember: *(++) is the same as *
24 Post Increment / Decrement Sntax int x[3] = 1,2,3; int ; int * = &x; = 5 + *(++); = 5 + (*)++; Remember: *(++) is the same as * Pre Increment/Decrement Sntax Rule Care must be taken with resect to oerator recedence when doing ointer arithmetic: Sntax Oeration Descrition b ++* *(++) ++(*) Pre Increment Pointer Pre Increment data ointed to b Pointer z = *(++); is equivalent to: = + 1; z = *; z = ++(*); is equivalent to: * = * + 1; z = *; 24
25 Pre Increment / Decrement Sntax int x[3] = 1,2,3; int ; int * = &x; = 5 + *(++); = (*); Remember: *(++) is the same as * Pre Increment / Decrement Sntax int x[3] = 1,2,3; int ; int * = &x; = 5 + *(++); = (*); Remember: *(++) is the same as *
26 Pre Increment / Decrement Sntax int x[3] = 1,2,3; int ; int * = &x; = 5 + *(++); = (*); Remember: *(++) is the same as * Pre Increment / Decrement Sntax int x[3] = 1,2,3; int ; int * = &x; = 5 + *(++); = (*); Remember: *(++) is the same as *
27 Pre Increment / Decrement Sntax int x[3] = 1,2,3; int ; int * = &x; = 5 + *(++); = (*); Remember: *(++) is the same as * The arentheses determine what gets incremented/decremented: Modif the ointer itself Pre and Post Increment/Decrement Summar *(++) or *++ and *(++) or *++ Modif the value ointed to b the ointer ++(*) and (*)++ 27
28 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 int * = NULL; NUL is the character '\0' but NULL is the value of a ointer that oints to nowhere Exercise 11 and Pointer Arithmetic 28
29 Oen the lab Project: Lab 11 and Pointer Arithmetic On the class website /s/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 Exercise 11 and Pointer Arithmetic Solution: Stes 1, 2 and 3 /*############################################################################ # STEP 1: Initialize the ointer with the address of the variable x ############################################################################*/ //Point to address of x = &x; /*############################################################################ # STEP 2: Comlete the following rintf() functions b adding in the # aroriate arguments as described in the control string. ############################################################################*/ rintf("the variable x is located at address 0x%X\n", &x); rintf("the value of x is %d\n", x); rintf("the ointer is located at address 0x%X\n", &); rintf("the value of is 0x%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; 29
30 Exercise 11 and Pointer Arithmetic 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 next item. ############################################################################*/ //Increment ointer to next arra element ++; Exercise 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 30
31 Questions? 31
Pointers CMPE-013/L. Pointers. Pointers What do they do? Pointers What are pointers? Gabriel Hugh Elkaim Winter 2014
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
More informationCMPE-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 informationLecture06: 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 informationGabriel 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 informationGabriel 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 informationPointers 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 informationtype 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 informationAssist. 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 informationCS335 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 informationLinear 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 informationDefinition. 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 informationWhat 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 informationWho. 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 informationApplications 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 informationSimple 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 informationApplications 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 informationShuigeng 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 informationApplications 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[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 informationApplications 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 informationStorage 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 informationStorage 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 informationGabriel 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 informationApplications 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 informationIntroduction 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 informationApplications 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 informationApplications 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 informationPointers (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 informationExample: 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 informationPersonal 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 information14. 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 informationHomework #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 informationFunctions 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 informationPointers (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 informationClasses. 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 informationLecture 14. No in-class files today. Homework 7 (due on Wednesday) and Project 3 (due in 10 days) posted. Questions?
Lecture 14 No in-class files today. Homework 7 (due on Wednesday) and Project 3 (due in 10 days) posted. Questions? Friday, February 11 CS 215 Fundamentals of Programming II - Lecture 14 1 Outline Static
More informationFORM 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 informationC++ 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 informationCS 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 informationChapter 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 informationPointers (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 informationChapter 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 informationExercise 3 / Ch.7. Given the following array, write code to initialize all the elements to 0: int ed[100]; Hint: It can be done two different ways!
Exercise 3 / Ch.7 Given the following array, write code to initialize all the elements to 0: int ed[100]; Hint: It can be done two different ways! Exercise 3 / Ch.8 Given the following array, write code
More informationA 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 informationGoals 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 informationCS162 - POINTERS. Lecture: Pointers and Dynamic Memory
CS162 - POINTERS Lecture: Pointers and Dynamic Memory What are pointers Why dynamically allocate memory How to dynamically allocate memory What about deallocation? Walk thru pointer exercises 1 CS162 -
More informationReference 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 informationExercise: Inventing Language
Memory Computers get their powerful flexibility from the ability to store and retrieve data Data is stored in main memory, also known as Random Access Memory (RAM) Exercise: Inventing Language Get a separate
More informationWednesday, 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 informationPointer 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 informationCS 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 informationpointers + 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 informationArrays, 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 informationExample: 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 informationInformatics 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 informationC 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 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 informationChapter 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 informationIntroduction to Computer Engineering. CS/ECE 252, Spring 2017 Rahul Nayar Computer Sciences Department University of Wisconsin Madison
Introduction to Computer Engineering CS/ECE 252, Spring 2017 Rahul Nayar Computer Sciences Department University of Wisconsin Madison Chapter 5 The LC-3 Announcements Homework 3 due today No class on Monday
More informationEE 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 informationChapter 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 informationPointers. 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 informationOBJECT 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 informationCS 1613 Lecture 24. Figure 1. Program p01.
Consider a rogram that is required to find all values larger than the average in a list of integers. The list is stored in a file. The rogram must read and store the list to fulfill its requirement. The
More informationCSE4421/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 informationBinghamton University. CS-211 Fall Pointers
Pointers 1 What is a pointer? Says I m not important what s important is over there Points AT or TO something else 2 Memory Array of bytes Each element has a value 0 1 2 3 xffff fffd xffff fffe xffff ffff
More informationProgramming 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 information42. 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! A data structure representing a list. ! A series of nodes chained together in sequence. ! A separate pointer (the head) points to the first
Ch. 17: Linked Lists 17.1 Introduction to Linked Lists! A data structure reresenting a list! A series of nodes chained together in sequence CS 2308 Sring 2015 Jill Seaman - Each node oints to one other
More informationChapter 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 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 informationCS 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 informationData, 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 information9.2 Pointer Variables. Pointer Variables CS Pointer Variables. Pointer Variables. 9.1 Getting the Address of a. Variable
CS 1400 Chapter 9 9.1 Getting the Address of a Variable A variable has: Name Value Location in a memory Type The location in memory is an address Use address operator & to get address of a variable: int
More information2. 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 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 informationtoday cs3157-fall2002-sklar-lect05 1
today homework #1 due on monday sep 23, 6am some miscellaneous topics: logical operators random numbers character handling functions FILE I/O strings arrays pointers cs3157-fall2002-sklar-lect05 1 logical
More informationPointers. 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 informationTo 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 informationCOMP26120: Pointers in C (2018/19) Lucas Cordeiro
COMP26120: Pointers in C (2018/19) Lucas Cordeiro lucas.cordeiro@manchester.ac.uk Organisation Lucas Cordeiro (Senior Lecturer, FM Group) lucas.cordeiro@manchester.ac.uk Office: 2.44 Office hours: 10-11
More informationEECS1022 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 informationAssembly labs start this week. Don t forget to submit your code at the end of your lab section. Download MARS4_5.jar to your lab PC or laptop.
CSC258 Week 10 Logistics Assembly labs start this week. Don t forget to submit your code at the end of your lab section. Download MARS4_5.jar to your lab PC or laptop. Quiz review A word-addressable RAM
More informationPointers. 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 informationLab5 2-Nov-18, due 16-Nov-18 (2 weeks duration) Lab6 16-Nov-19, due 30-Nov-18 (2 weeks duration)
CS1021 AFTER READING WEEK Mid-Semester Test NOW Thurs 8th Nov @ 9am in Goldsmith Hall (ALL students to attend at 9am) Final 2 Labs Lab5 2-Nov-18, due 16-Nov-18 (2 weeks duration) Lab6 16-Nov-19, due 30-Nov-18
More informationExpressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators
Expressions 1 Expressions n Variables and constants linked with operators Arithmetic expressions n Uses arithmetic operators n Can evaluate to any value Logical expressions n Uses relational and logical
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 informationStrings Investigating Memory Allocation Pointers Fixed-Point Arithmetic. Memory Matters. Embedded Systems Interfacing.
22 September 2011 Strings Single character char ch; char ch = a ; char ch = 0x41; Array of characters char str[5]={ H, e, l, l, o }; Null-terminated string char str[ ]= Hello String Runtime Library #include
More informationCME 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 informationCSE351 Autumn 2013 Final Exam (11 Dec 2013)
CSE351 Autumn 2013 Final Exam (11 Dec 2013) Please read through the entire examination first! We designed this exam so that it can be completed in approximately 90 minutes and, hopefully, this estimate
More informationCSCI-1200 Data Structures Fall 2017 Lecture 5 Pointers, Arrays, & Pointer Arithmetic
CSCI-1200 Data Structures Fall 2017 Lecture 5 Pointers, Arrays, & Pointer Arithmetic Review from Letctures 3 & 4 C++ class syntax, designing classes, classes vs. structs; Passing comparison functions to
More informationPOINTERS INTRODUCTION: A pointer is a variable that holds (or whose value is) the memory address of another variable and provides an indirect way of accessing data in memory. The main memory (RAM) of computer
More informationPointer 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 informationWinter 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 informationUNIT- 3 Introduction to C++
UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationMonday, 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 informationPOINTER & 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 informationLecture 18. Today, we will discuss developing algorithms for a basic model for parallel computing the Parallel Random Access Machine (PRAM) model.
U.C. Berkeley CS273: Parallel and Distributed Theory Lecture 18 Professor Satish Rao Lecturer: Satish Rao Last revised Scribe so far: Satish Rao (following revious lecture notes quite closely. Lecture
More informationMemory, Data, & Addressing II CSE 351 Spring
Memory, Data, & Addressing II CSE 351 Spring 2018 http://xkcd.com/138/ Review Questions 1) If the word size of a machine is 64-bits, which of the following is usually true? (pick all that apply) a) 64
More informationIntermediate 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 informationME 461 C review Session Fall 2009 S. Keres
ME 461 C review Session Fall 2009 S. Keres DISCLAIMER: These notes are in no way intended to be a complete reference for the C programming material you will need for the class. They are intended to help
More information