Comp 11 Lectures. Mike Shah. June 26, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

Size: px
Start display at page:

Download "Comp 11 Lectures. Mike Shah. June 26, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57"

Transcription

1 Comp 11 Lectures Mike Shah Tufts University June 26, 2017 Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

2 Please do not distribute or host these slides without prior permission. Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

3 Pointers Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

4 Comp 11 - Pre-Class warm up If I write the address to your house down on an envelope, I can conveniently send that letter to you and retrieve some response. There are alternatives though I could just move you and your house to where I am standing! Or just rebuild a copy of your house next to me (and also clone you). Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

5 Lecture Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

6 Radia Perlman Figure 1: Radia Perlman is a MIT Ph.D. graduate best known for her work in computer networks. She holds over 100 patents and is responsible for transforming how Ethernets are able to utilized to create large networks Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

7 Memory and Pass by Reference Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

8 Memory We have talked about memory briefly when we talked about arrays. A modern computer these days, has quite a bit of memory available. You have memory in your hard disk, memory in RAM, and storage in the Cache. These are all different levels of memory, and our operating system helps us manage where it goes. As an example, your operating system hands you memory, when you run your program Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

9 Here is some Memory when you start your program (Note that each box represents 4 bytes of memory in the following slides.) Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

10 Then you start storing things int a = 2; Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

11 Then you start storing things int a = 2; int b = 7; Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

12 And some more int a = 2; int b = 7; int c = 9; Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

13 Maybe an entire array int a = 2; int b = 7; int c = 9; int d[9]; // Notice, how the array is contiguous in our memory! Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

14 Space in C++ So remember what these little boxes are. They are bytes of memory. Depending on the variable or data structure we use, they take up a different amount of memory. Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

15 Sample Data Sizes Type Number of Bytes bool 1 char 1 short 2 float 4 int 4 long 4 double 8 long long 8 Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

16 Lets allocate some more memory, of different types int a = 2; int b = 7; int c = 9; int d[9]; double e = 1.01; // Ah, notice that a double takes twice as much space as our int because it is twice as many bytes Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

17 A closer look at just one of the boxes int a = 2; 2 So let s just look at the first integer. It contains our integer value But what about the second part of the box? Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

18 An address! int a = 2; 2 The address (in hexadecimal) tells us where we are! So just like addresses we have in real life, memory has a unique address. 0x Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

19 Okay, but who cares? Well, having access to the memory address is actually quite powerful! In fact, this is what makes a language like C++ very powerful. We are close to the metal, and have the opportunity to work with the hardware. And at the very least, our C++ compilers and operating systems care about memory (and our end users!) Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

20 Address Of If I want to see the memory address, I can use the ampersand operator. Here is an example. 1 #i n c l u d e <i o s t r e a m > 2 3 i n t main ( ) { 4 5 i n t x = ; 6 7 s t d : : cout << Address o f x i s : << &x << \n ; 8 9 r e t u r n 0 ; 0 } Listing 1: Where in our memory is a variable Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

21 Reference Neat, so we can get the address of some variable in memory. We now know where it lives. But we do not get the actual value. Instead we are getting a reference to where some value resides. So when you think &, you think reference from now on. What does this allow us to do? (where is the power? See next slide) Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

22 Pass by Value In this class, we have always passed by value. That is, we have not used the & sign, which is pass by reference. When I say pass by, I am referring to functions, lets take a look at an example. Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

23 Pass by Value - Example 1 #i n c l u d e <i o s t r e a m > 2 3 v o i d s e t V a l u e ( i n t x ) { 4 x = 9999; 5 } 6 7 i n t main ( ) { 8 9 i n t a = 6 ; 0 s e t V a l u e ( a ) ; 1 // What i s a h e r e? 2 s t d : : cout << a << \n ; 3 4 r e t u r n 0 ; 5 } Listing 2: Pass by Value Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

24 Why is a not 9999? 1 #i n c l u d e <i o s t r e a m > 2 3 v o i d s e t V a l u e ( i n t x ) { 4 x = 9999; 5 } 6 7 i n t main ( ) { 8 9 i n t a = 6 ; 0 s e t V a l u e ( a ) ; 1 // What i s a h e r e? 2 s t d : : cout << a << \n ; 3 4 r e t u r n 0 ; 5 } Listing 3: Pass by Value Well, when we pass by value, we are actually passing a copy of a on the stack. So pass by value, is copying a value into the function to be used, but it does not modify the value. Where does that value live again? On the stack (see 2 bullet points up) Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

25 Why is a not The Stack Table 1: This is a stack with two items parameter 1 - int a return value 4 bytes of memory here In this case, void Stack Memory is allocated when we call a function. The amount of memory is the number of parameters we pass (in our previous example, 1 int), and the number of items we need to return. When we are done with the stack, C++ (and the OS) wants to reclaim that memory for other functions. Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

26 Pass by Reference - Example 1 #i n c l u d e <i o s t r e a m > 2 3 // A one c h a r a c t e r change! 4 v o i d s e t V a l u e ( i n t &x ) { 5 x = 9999; 6 } 7 8 i n t main ( ) { 9 0 i n t a = 6 ; 1 s e t V a l u e ( a ) ; 2 // What i s a h e r e? 3 s t d : : cout << a << \n ; 4 5 r e t u r n 0 ; 6 } Listing 4: Pass by Reference Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

27 Pass by Reference So why does it work? Remember what we are passing into the function this time We are saying, pass the address of an int type. The address lives in our huge grid of memory that we saw earlier. This means that if we modify an address that is not on the stack, it does not go away with the stack after the function call. Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

28 A closer look 1 // Pass x by r e f e r e n c e 2 v o i d s e t V a l u e ( i n t &x ) { 3 // Whatever i s i n the memory at x, s e t 4 // t h a t i n t e g e r v a l u e to x = 9999; 6 } Listing 5: Annotated function example Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

29 A quick review Pass by reference means we are only passing an address(0x ) to a function, not that actual value. Nothing more, nothing less. Just use the ampersand &. Remember, ampersand is address of, where something is stored in memory. Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

30 Stack Memory is different! Pass by value means copying 1 #i n c l u d e <i o s t r e a m > 2 3 v o i d memoryonstack ( i n t a ) { 4 s t d : : cout << &a << \n ; 5 } 6 7 i n t main ( ) { 8 i n t i = 5 ; 9 // i s a d d r e s s s h o u l d be the same 0 // i f i t i s i n the same p l a c e i n memory. 1 // But no! You w i l n o t i c e a copy i s made 2 // ( and s t o r e d where? the s t a c k! ) 3 memoryonstack ( i ) ; 4 s t d : : cout << &i << \n ; 5 6 r e t u r n 0 ; 7 } Listing 6: Annotated function example Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

31 Pointers Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

32 We have another tool I have exciting news, we have another tool to work with! The asterisk operator *, which is a pointer. A pointer is a qualifier to a type that says point to memory at this location. We might want to still pass by value, but not by reference if we do not want a mutation to take place. Again, a pointer is only a variable that holds a memory address no values are stored! Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

33 We might want to still pass by value, but not by reference. A pointer when passed as a parameter, is still copied, but it is only an address, thus cheap. (imagine if you have a struct that has 100s of member variables those all have to be copied!) Let me show you then we ll dive into pointers. Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

34 Nasty vector copy 1 #i n c l u d e <v e c t o r > 2 #i n c l u d e <i o s t r e a m > 3 // Doing one s i m p l e o p e r a t i o n r e q u i r e s a copy o f the e n t i r e v e c t o r. 4 v o i d p r i n t V e c t o r ( s t d : : v e c t o r <i n t > vectorcopy ) { 5 s t d : : cout << vectorcopy [ 0 ] << \n ; 6 } 7 8 i n t main ( ) { 9 s t d : : v e c t o r <i n t > veccounter ; 0 1 f o r ( i n t i =0; i < ; i ++){ 2 veccounter. push back ( i ) ; 3 } 4 // Pass a copy o f our v e c t o r to the f u n c t i o n 5 p r i n t V e c t o r ( veccounter ) ; 6 r e t u r n 0 ; 7 } Listing 7: A vector with items Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

35 Pointers A pointer is a type. There are integer pointers, floating pointers, double pointers, even pointers to your custom defined types (using structs) We often say, a pointer to int, which has the same meaning as above. We use the asterisk (*) to signfify that we want to point to a specific data type. Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

36 Pointer syntax 1 1 // A r e g u l a r i n t e g e r 2 i n t x ; 3 // A p o i n t e r to an i n t e g e r 4 i n t px ; 5 // Sometimes we p r e f i x our v a r i a b l e with a p or p to remember i t i s a p o i n t e r. Listing 8: Integer pointer Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

37 Pointer syntax 2 1 // A r e g u l a r f l o a t 2 f l o a t x ; 3 // A p o i n t e r to a f l o a t 4 f l o a t p x ; 5 // Sometimes we p r e f i x our v a r i a b l e with a p or p to remember i t i s a p o i n t e r. Listing 9: float pointer Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

38 Pointer syntax 3 1 // A s t r u c t we c r e a t e d 2 s t r u c t s t u d e n t { 3 s t d : : s t r i n g name ; 4 i n t age ; 5 } ; 6 // C r e a t e our s t r u c t o b j e c t 7 Student mike ; 8 // A p o i n t e r to our o b j e c t 9 Student p s t u d e n t ; Listing 10: struct pointer Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

39 Pointer syntax 4 So remember all a pointer does is point to an address. How do we get an address? Ampersand &! Okay, let us try it out. Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

40 Creating and assigning a pointer 1 #i n c l u d e <i o s t r e a m > 2 3 i n t main ( ) { 4 i n t x = 5 ; 5 // I n t e g e r p o i n t s t y p e s match i f i t p o i n t s to 6 // a p r i m i t i v e ( i n t ) t h a t i s an a d d r e s s 7 // We g e t the a d d r e s s with & 8 i n t i = &x ; r e t u r n 0 ; 3 } Listing 11: Creating a pointer Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

41 Dereferencing a pointer Great, so we can point to an integer. But what if we want the value for which we point at? We dereference, i.e. Whatever I am referring to, don t give me the address (because remember & means reference), but instead give me the value hence dereference. We dereference by putting an asterisk(*) before our variable. Note that this is a different context, then when we created a pointer type (a pointer to an integer in the previous example). Okay, let s give it a try. Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

42 Dereferencing a pointer - Example 1 #i n c l u d e <i o s t r e a m > 2 3 i n t main ( ) { 4 i n t x = 5 ; 5 // I n t e g e r p o i n t s t y p e s match i f i t p o i n t s to 6 // a p r i m i t i v e ( i n t ) t h a t i s an a d d r e s s 7 // We g e t the a d d r e s s with & 8 i n t i = &x ; 9 // D e r e f e r e n c i n g i ( i ) g i v e s us the v a l u e ) 0 s t d : : cout << v a l u e t h a t i p o i n t s to i s : << i << \n ; 1 2 r e t u r n 0 ; 3 } Listing 12: Dereference a pointer Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

43 Question If the pointer i points to integer x, does that mean i can modify x s value? Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

44 Question Answered 1 #i n c l u d e <i o s t r e a m > 2 3 i n t main ( ) { 4 i n t x = 5 ; 5 i n t i = &x ; 6 s t d : : cout << v a l u e t h a t i p o i n t s to i s : << i << \n ; 7 // L e t s s e t i to something e l s e 8 // We a r e t a l k i n g about v a l u e s, so we de r e f e r e n c e 9 // ( i = 72 would t r y to s e t the memory a d d r e s s to 7 2! ) 0 i = 7 2 ; 1 s t d : : cout << what i s i now : << i << \n ; 2 s t d : : cout << what i s x now : << x << \n ; 3 4 r e t u r n 0 ; 5 } Listing 13: Dereference a pointer Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

45 Pointers and functions - parameters are pass by value 1 #i n c l u d e <i o s t r e a m > 2 3 // Pass by v a l u e ( Only p a s s by r e f e r e n c e with &) 4 v o i d settoone ( i n t p ) { 5 // p p o i n t s to something i n memory, so we can 6 // s t i l l modify i t s c o n t e n t s however! 7 p = 1 ; 8 } 9 0 i n t main ( ) { 1 i n t x = ; 2 i n t i = &x ; 3 settoone ( i ) ; 4 5 s t d : : cout << x i s : << x << \n ; 6 7 r e t u r n 0 ; 8 } Listing 14: Parameters Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

46 Still pass by value 1 #i n c l u d e <i o s t r e a m > 2 i n t g l o b a l = 1 0 ; // C r e a t e some g l o b a l we can p o i n t to. 3 4 v o i d cannotchange ( i n t p ) { 5 p = &g l o b a l ; 6 } 7 8 i n t main ( ) { 9 i n t x = ; 0 i n t i = &x ; 1 // Pass by v a l u e 2 cannotchange ( i ) ; 3 // So even i f we p o i n t to something new 4 // Remember, o n l y a copy o f a p o i n t e r i s p a s s e d i n. 5 s t d : : cout << i s h o u l d s t i l l be what x i s : << i << \n ; 6 7 r e t u r n 0 ; 8 } Listing 15: Still only passing a copy of the variable as a parameter Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

47 Whew, quite a bit First things first, pointers are fun and they give us power We can now modify variables in functions using either pointers or references. We want to start thinking of functions as having their own memory on the stack. We want to think about where memory is otherwise, and remember the concepts of scope. Speaking of memory there s yet another curveball with arrays. Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

48 Passing arrays into functions The first three functions are exactly the same! 1 i n t incrementone ( i n t a r r a y ) { 2 //... 3 } 4 5 i n t incrementtwo ( i n t a r r a y [ ] ) { 6 //... 7 } 8 9 i n t i n c r e m e n t T h r e e ( i n t a r r a y [ 5 ] ) { 0 //... 1 } 2 3 i n t i n c r e m e n t F o u r ( i n t &a r r a y ) { 4 //... 5 } Listing 16: Many variations Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

49 Passing arrays into functions - Part 2 The reason is because an array is really just a pointer to memory. That is, a pointer to the first element in our array. incrementone actually gives this away (the other two following examples decay to the same thing). However, we do not know how big the array is, so we will want to pass that as a parameter for our function. Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

50 wait, so you skipped incrementfour? This is passing an array(which is a pointer) by reference This is illegal. The C++ Standard forbids it, and if we really understand references, this sort of makes sense. An array syntax (arr[5]) actually is *(arr+5) Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

51 Pointer Arithmetic 1 #i n c l u d e <i o s t r e a m > 2 i n t main ( ) { 3 i n t a [ 1 0 ] ; 4 // B r a c k e t s a r e a c o n v e n i e n t s y n t a x f o r us 5 // to a v o i d doing p o i n t e r a r i t h e m e t i c. 6 // What t h i s s a y s i s, 7 // ( 1 ) A s s i g n the v a l u e 5 to the l e f t hand s i d e ( l h s ) 8 // ( 2 ) On the l h s, i n c r e m e n t 5 memory a d d r e s s e s from the s t a r t 9 // ( 3 ) And de r e f e r e n c e t h i s v a l u e and s e t i t to 5. 0 // ( 4 ) Now a [ 5 ] i s e q u a l to 5. 1 ( a+5) = 5 ; 2 3 s t d : : cout << a [ 5 ] << \n ; 4 r e t u r n 0 ; 5 } Listing 17: Incrementing through memory Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

52 NULL It is best practice when we create a pointer, to set it to NULL. At any point, we can also point our pointer to NULL, which essentially means it is pointing to nothing. We (you, me, and every C++ programmer) will run into a segfault error at some point. This means you dereferenced a pointer at an illegal memory location. Which really means, you do not have anything at that memory location, and you are trying to access something that does not exist! (e.g. Array out of bounds error). This is good behavior in a way, it gives us a place to start looking. Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

53 In-Class Activity http: // Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

54 Activity Discussion Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

55 Review of what we learned (At least) Two students Tell me each 1 thing you learned or found interesting in lecture. Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

56 5-10 minute break Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

57 To the lab! Lab: You should have gotten an and hopefully setup an account at prior to today. If not no worries, we ll take care of it during lab! Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

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

Pointers in C/C++ 1 Memory Addresses 2

Pointers in C/C++ 1 Memory Addresses 2 Pointers in C/C++ Contents 1 Memory Addresses 2 2 Pointers and Indirection 3 2.1 The & and * Operators.............................................. 4 2.2 A Comment on Types - Muy Importante!...................................

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

CMSC202 Computer Science II for Majors

CMSC202 Computer Science II for Majors CMSC202 Computer Science II for Majors Lecture 04 Pointers Dr. Katherine Gibson Based on slides by Chris Marron at UMBC Last Class We Covered C++ Functions Parts of a function: Prototype Definition Call

More information

REFERENCES, POINTERS AND STRUCTS

REFERENCES, POINTERS AND STRUCTS REFERENCES, POINTERS AND STRUCTS Problem Solving with Computers-I https://ucsb-cs16-sp17.github.io/ Pointer assignment 2 int *p1, *p2, x; p1 = &x; p2 = p1; Q: Which of the following pointer diagrams best

More information

C++ for Java Programmers

C++ for Java Programmers Lecture 6 More pointing action Yesterday we considered: Pointer Assignment Dereferencing Pointers to Pointers to Pointers Pointers and Array Pointer Arithmetic 2 Todays Lecture What do we know 3 And now

More information

Principles of Programming Pointers, Dynamic Memory Allocation, Character Arrays, and Buffer Overruns

Principles of Programming Pointers, Dynamic Memory Allocation, Character Arrays, and Buffer Overruns Pointers, Dynamic Memory Allocation, Character Arrays, and Buffer Overruns What is an array? Pointers Memory issues The name of the array is actually a memory address. You can prove this by trying to print

More information

Introduction to C: Pointers

Introduction to C: Pointers Introduction to C: Pointers Nils Moschüring PhD Student (LMU) Nils Moschüring PhD Student (LMU), Introduction to C: Pointers 1 1 Introduction 2 Pointers Basics Useful: Function

More information

Functions, Pointers, and the Basics of C++ Classes

Functions, Pointers, and the Basics of C++ Classes Functions, Pointers, and the Basics of C++ Classes William E. Skeith III Functions in C++ Vocabulary You should be familiar with all of the following terms already, but if not, you will be after today.

More information

CS 61c: Great Ideas in Computer Architecture

CS 61c: Great Ideas in Computer Architecture Arrays, Strings, and Some More Pointers June 24, 2014 Review of Last Lecture C Basics Variables, functioss, control flow, types, structs Only 0 and NULL evaluate to false Pointers hold addresses Address

More information

PIC 10A Pointers, Arrays, and Dynamic Memory Allocation. Ernest Ryu UCLA Mathematics

PIC 10A Pointers, Arrays, and Dynamic Memory Allocation. Ernest Ryu UCLA Mathematics PIC 10A Pointers, Arrays, and Dynamic Memory Allocation Ernest Ryu UCLA Mathematics Pointers A variable is stored somewhere in memory. The address-of operator & returns the memory address of the variable.

More information

Lecture Notes on Memory Layout

Lecture Notes on Memory Layout Lecture Notes on Memory Layout 15-122: Principles of Imperative Computation Frank Pfenning André Platzer Lecture 11 1 Introduction In order to understand how programs work, we can consider the functions,

More information

Pointers II. Class 31

Pointers II. Class 31 Pointers II Class 31 Compile Time all of the variables we have seen so far have been declared at compile time they are written into the program code you can see by looking at the program how many variables

More information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #34. Function with pointer Argument

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #34. Function with pointer Argument Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #34 Function with pointer Argument (Refer Slide Time: 00:05) So, here is the stuff that we have seen about pointers.

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

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

CS 31: Intro to Systems Pointers and Memory. Martin Gagne Swarthmore College February 16, 2016

CS 31: Intro to Systems Pointers and Memory. Martin Gagne Swarthmore College February 16, 2016 CS 31: Intro to Systems Pointers and Memory Martin Gagne Swarthmore College February 16, 2016 So we declared a pointer How do we make it point to something? 1. Assign it the address of an existing variable

More information

Consider the above code. This code compiles and runs, but has an error. Can you tell what the error is?

Consider the above code. This code compiles and runs, but has an error. Can you tell what the error is? Discussion 1H Notes (Week 8, May 20) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 Dynamic Allocation of Memory Recall that when you create an array, you must know

More information

Heap Arrays and Linked Lists. Steven R. Bagley

Heap Arrays and Linked Lists. Steven R. Bagley Heap Arrays and Linked Lists Steven R. Bagley Recap Data is stored in variables Can be accessed by the variable name Or in an array, accessed by name and index Variables and arrays have a type Create our

More information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #33 Pointer Arithmetic

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #33 Pointer Arithmetic Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #33 Pointer Arithmetic In this video let me, so some cool stuff which is pointer arithmetic which helps you to

More information

Pointers. 1 Background. 1.1 Variables and Memory. 1.2 Motivating Pointers Massachusetts Institute of Technology

Pointers. 1 Background. 1.1 Variables and Memory. 1.2 Motivating Pointers Massachusetts Institute of Technology Introduction to C++ Massachusetts Institute of Technology ocw.mit.edu 6.096 Pointers 1 Background 1.1 Variables and Memory When you declare a variable, the computer associates the variable name with a

More information

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)...

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)... Remembering numbers (and other stuff)... Let s talk about one of the most important things in any programming language. It s called a variable. Don t let the name scare you. What it does is really simple.

More information

CS 220: Introduction to Parallel Computing. Arrays. Lecture 4

CS 220: Introduction to Parallel Computing. Arrays. Lecture 4 CS 220: Introduction to Parallel Computing Arrays Lecture 4 Note: Windows I updated the VM image on the website It now includes: Sublime text Gitkraken (a nice git GUI) And the git command line tools 1/30/18

More information

Contents. Slide Set 1. About these slides. Outline of Slide Set 1. Typographical conventions: Italics. Typographical conventions. About these slides

Contents. Slide Set 1. About these slides. Outline of Slide Set 1. Typographical conventions: Italics. Typographical conventions. About these slides Slide Set 1 for ENCM 369 Winter 2014 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2014 ENCM 369 W14 Section

More information

Lecture 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? 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 information

Sixth lecture; classes, objects, reference operator.

Sixth lecture; classes, objects, reference operator. Sixth lecture; classes, objects, reference operator. 1 Some notes on the administration of the class: From here on out, homework assignments should be a bit shorter, and labs a bit longer. My office hours

More information

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

CS 61C: Great Ideas in Computer Architecture C Pointers. Instructors: Vladimir Stojanovic & Nicholas Weaver

CS 61C: Great Ideas in Computer Architecture C Pointers. Instructors: Vladimir Stojanovic & Nicholas Weaver CS 61C: Great Ideas in Computer Architecture C Pointers Instructors: Vladimir Stojanovic & Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/sp16 1 Agenda Pointers Arrays in C 2 Address vs. Value Consider

More information

377 Student Guide to C++

377 Student Guide to C++ 377 Student Guide to C++ c Mark Corner January 21, 2004 1 Introduction In this course you will be using the C++ language to complete several programming assignments. Up to this point we have only provided

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Programming in C++ Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Programming in C++ Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Programming in C++ Indian Institute of Technology, Kharagpur Lecture 14 Default Parameters and Function Overloading

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

Arrays and Pointers. CSC209: Software Tools and Systems Programming (Winter 2019) Furkan Alaca & Paul Vrbik. University of Toronto Mississauga

Arrays and Pointers. CSC209: Software Tools and Systems Programming (Winter 2019) Furkan Alaca & Paul Vrbik. University of Toronto Mississauga Arrays and Pointers CSC209: Software Tools and Systems Programming (Winter 2019) Furkan Alaca & Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Week 2 Alaca & Vrbik (UTM)

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

EL2310 Scientific Programming

EL2310 Scientific Programming Lecture 11: Structures and Memory (yaseminb@kth.se) Overview Overview Lecture 11: Structures and Memory Structures Continued Memory Allocation Lecture 11: Structures and Memory Structures Continued Memory

More information

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Week 02 Module 06 Lecture - 14 Merge Sort: Analysis

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Week 02 Module 06 Lecture - 14 Merge Sort: Analysis Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute Week 02 Module 06 Lecture - 14 Merge Sort: Analysis So, we have seen how to use a divide and conquer strategy, we

More information

First of all, it is a variable, just like other variables you studied

First of all, it is a variable, just like other variables you studied Pointers: Basics What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the address (rather than the value)

More information

introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion

introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion Today s video will talk about an important concept in computer science which is

More information

CSCI-1200 Data Structures Fall 2017 Lecture 5 Pointers, Arrays, & Pointer Arithmetic

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

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #44. Multidimensional Array and pointers

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #44. Multidimensional Array and pointers Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #44 Multidimensional Array and pointers In this video, we will look at the relation between Multi-dimensional

More information

CS162 - POINTERS. Lecture: Pointers and Dynamic Memory

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

Pointers. A pointer is simply a reference to a variable/object. Compilers automatically generate code to store/retrieve variables from memory

Pointers. A pointer is simply a reference to a variable/object. Compilers automatically generate code to store/retrieve variables from memory Pointers A pointer is simply a reference to a variable/object Compilers automatically generate code to store/retrieve variables from memory It is automatically generating internal pointers We don t have

More information

Arrays. Returning arrays Pointers Dynamic arrays Smart pointers Vectors

Arrays. Returning arrays Pointers Dynamic arrays Smart pointers Vectors Arrays Returning arrays Pointers Dynamic arrays Smart pointers Vectors To declare an array specify the type, its name, and its size in []s int arr1[10]; //or int arr2[] = {1,2,3,4,5,6,7,8}; arr2 has 8

More information

Variation of Pointers

Variation of Pointers Variation of Pointers A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before

More information

Administrivia. Introduction to Computer Systems. Pointers, cont. Pointer example, again POINTERS. Project 2 posted, due October 6

Administrivia. Introduction to Computer Systems. Pointers, cont. Pointer example, again POINTERS. Project 2 posted, due October 6 CMSC 313 Introduction to Computer Systems Lecture 8 Pointers, cont. Alan Sussman als@cs.umd.edu Administrivia Project 2 posted, due October 6 public tests s posted Quiz on Wed. in discussion up to pointers

More information

(Refer Slide Time: 06:01)

(Refer Slide Time: 06:01) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 28 Applications of DFS Today we are going to be talking about

More information

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi.

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi. Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 18 Tries Today we are going to be talking about another data

More information

C Pointers 2013 Author Riko H i

C Pointers 2013 Author Riko H i http:/cdorm.net/understanding C Pointers 2013 Author Riko H i Copyright 2013 CDorm.net All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form

More information

CS61C Machine Structures. Lecture 4 C Pointers and Arrays. 1/25/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/

CS61C Machine Structures. Lecture 4 C Pointers and Arrays. 1/25/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/ CS61C Machine Structures Lecture 4 C Pointers and Arrays 1/25/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L04 C Pointers (1) Common C Error There is a difference

More information

Slide Set 2. for ENCM 335 in Fall Steve Norman, PhD, PEng

Slide Set 2. for ENCM 335 in Fall Steve Norman, PhD, PEng Slide Set 2 for ENCM 335 in Fall 2018 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2018 ENCM 335 Fall 2018 Slide Set 2 slide

More information

Binghamton University. CS-211 Fall Pointers

Binghamton University. CS-211 Fall Pointers Pointers 1 Memory The act of keeping track of something over time Remembering is the concept of storing information A memory is no good unless you can retrieve that information In a computer, we remember

More information

printf( Please enter another number: ); scanf( %d, &num2);

printf( Please enter another number: ); scanf( %d, &num2); CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful

More information

If Statements, For Loops, Functions

If Statements, For Loops, Functions Fundamentals of Programming If Statements, For Loops, Functions Table of Contents Hello World Types of Variables Integers and Floats String Boolean Relational Operators Lists Conditionals If and Else Statements

More information

Data Structure Series

Data Structure Series Data Structure Series This series is actually something I started back when I was part of the Sweet.Oblivion staff, but then some things happened and I was no longer able to complete it. So now, after

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, Dynamic Data, and Reference Types

Pointers, Dynamic Data, and Reference Types Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple

More information

Binghamton University. CS-211 Fall Pointers

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

In Java we have the keyword null, which is the value of an uninitialized reference type

In Java we have the keyword null, which is the value of an uninitialized reference type + More on Pointers + Null pointers In Java we have the keyword null, which is the value of an uninitialized reference type In C we sometimes use NULL, but its just a macro for the integer 0 Pointers are

More information

Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute

Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute Module # 02 Lecture - 03 Characters and Strings So, let us turn our attention to a data type we have

More information

(Refer Slide Time: 01:25)

(Refer Slide Time: 01:25) Computer Architecture Prof. Anshul Kumar Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture - 32 Memory Hierarchy: Virtual Memory (contd.) We have discussed virtual

More information

C Review. MaxMSP Developers Workshop Summer 2009 CNMAT

C Review. MaxMSP Developers Workshop Summer 2009 CNMAT C Review MaxMSP Developers Workshop Summer 2009 CNMAT C Syntax Program control (loops, branches): Function calls Math: +, -, *, /, ++, -- Variables, types, structures, assignment Pointers and memory (***

More information

Week 5, continued. This is CS50. Harvard University. Fall Cheng Gong

Week 5, continued. This is CS50. Harvard University. Fall Cheng Gong This is CS50. Harvard University. Fall 2014. Cheng Gong Table of Contents News... 1 Buffer Overflow... 1 Malloc... 6 Linked Lists... 7 Searching... 13 Inserting... 16 Removing... 19 News Good news everyone!

More information

CS 2461: Computer Architecture I

CS 2461: Computer Architecture I Next: Pointers, Arrays, Structs... : Computer Architecture I The real fun stuff in C.. Pointers and Arrays Read Chapters 16, 18 of text Functions, Arrays, Pointers Dynamic data structures Allocating space

More information

CMSC 341 Lecture 2 Dynamic Memory and Pointers

CMSC 341 Lecture 2 Dynamic Memory and Pointers CMSC 341 Lecture 2 Dynamic Memory and Pointers Park Sects. 01 & 02 Based on earlier course slides at UMBC Today s Topics Stack vs Heap Allocating and freeing memory new and delete Memory Leaks Valgrind

More information

Programming and Data Structures Prof. N. S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras

Programming and Data Structures Prof. N. S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras Programming and Data Structures Prof. N. S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 02 Structures, Pointers and Functions Welcome to

More information

(Refer Slide Time: 00:23)

(Refer Slide Time: 00:23) In this session, we will learn about one more fundamental data type in C. So, far we have seen ints and floats. Ints are supposed to represent integers and floats are supposed to represent real numbers.

More information

QUIZ How do we implement run-time constants and. compile-time constants inside classes?

QUIZ How do we implement run-time constants and. compile-time constants inside classes? QUIZ How do we implement run-time constants and compile-time constants inside classes? Compile-time constants in classes The static keyword inside a class means there s only one instance, regardless of

More information

C++ ARRAYS POINTERS POINTER ARITHMETIC. Problem Solving with Computers-I

C++ ARRAYS POINTERS POINTER ARITHMETIC. Problem Solving with Computers-I C++ ARRAYS POINTERS POINTER ARITHMETIC Problem Solving with Computers-I General model of memory Sequence of adjacent cells Each cell has 1-byte stored in it Each cell has an address (memory location) Memory

More information

Artificial Intelligence Prof. Deepak Khemani Department of Computer Science and Engineering Indian Institute of Technology, Madras

Artificial Intelligence Prof. Deepak Khemani Department of Computer Science and Engineering Indian Institute of Technology, Madras Artificial Intelligence Prof. Deepak Khemani Department of Computer Science and Engineering Indian Institute of Technology, Madras (Refer Slide Time: 00:17) Lecture No - 10 Hill Climbing So, we were looking

More information

Compilers and Interpreters

Compilers and Interpreters Compilers and Interpreters Pointers, the addresses we can see Programs that write other programs Managing the details A compiler is a program that, when fed itself as input, produces ITSELF! Then how was

More information

Programming and Data Structure

Programming and Data Structure Programming and Data Structure Dr. P.P.Chakraborty Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture # 09 Problem Decomposition by Recursion - II We will

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

Lecture 2, September 4

Lecture 2, September 4 Lecture 2, September 4 Intro to C/C++ Instructor: Prashant Shenoy, TA: Shashi Singh 1 Introduction C++ is an object-oriented language and is one of the most frequently used languages for development due

More information

12. Pointers Address-of operator (&)

12. Pointers Address-of operator (&) 12. Pointers In earlier chapters, variables have been explained as locations in the computer's memory which can be accessed by their identifer (their name). This way, the program does not need to care

More information

arrays review arrays and memory arrays: character array example cis15 advanced programming techniques, using c++ summer 2008 lecture # V.

arrays review arrays and memory arrays: character array example cis15 advanced programming techniques, using c++ summer 2008 lecture # V. topics: arrays pointers arrays of objects resources: cis15 advanced programming techniques, using c++ summer 2008 lecture # V.1 some of this lecture is covered in parts of Pohl, chapter 3 arrays review

More information

QUIZ. What is wrong with this code that uses default arguments?

QUIZ. What is wrong with this code that uses default arguments? QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code

More information

Lecture Transcript While and Do While Statements in C++

Lecture Transcript While and Do While Statements in C++ Lecture Transcript While and Do While Statements in C++ Hello and welcome back. In this lecture we are going to look at the while and do...while iteration statements in C++. Here is a quick recap of some

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

Memory and Addresses. Pointers in C. Memory is just a sequence of byte-sized storage devices.

Memory and Addresses. Pointers in C. Memory is just a sequence of byte-sized storage devices. Memory and Addresses Memory is just a sequence of byte-sized storage devices. 1 The bytes are assigned numeric addresses, starting with zero, just like the indexing of the cells of an array. It is the

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture 10 Reference and Pointer Welcome to module 7 of programming in

More information

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n) Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Module 10A Lecture - 20 What is a function?

More information

today cs3157-fall2002-sklar-lect05 1

today 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 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

Programming Abstractions

Programming Abstractions Programming Abstractions C S 1 0 6 X Cynthia Lee Topics: Last week, with Marty Stepp: Making your own class Arrays in C++ This week: Memory and Pointers Revisit some topics from last week Deeper look at

More information

CS107 Handout 08 Spring 2007 April 9, 2007 The Ins and Outs of C Arrays

CS107 Handout 08 Spring 2007 April 9, 2007 The Ins and Outs of C Arrays CS107 Handout 08 Spring 2007 April 9, 2007 The Ins and Outs of C Arrays C Arrays This handout was written by Nick Parlante and Julie Zelenski. As you recall, a C array is formed by laying out all the elements

More information

nptr = new int; // assigns valid address_of_int value to nptr std::cin >> n; // assigns valid int value to n

nptr = new int; // assigns valid address_of_int value to nptr std::cin >> n; // assigns valid int value to n Static and Dynamic Memory Allocation In this chapter we review the concepts of array and pointer and the use of the bracket operator for both arrays and pointers. We also review (or introduce) pointer

More information

Templating functions. Comp Sci 1570 Introduction to C++ Administrative notes. Review. Templates. Compiler processing. Functions Overloading

Templating functions. Comp Sci 1570 Introduction to C++ Administrative notes. Review. Templates. Compiler processing. Functions Overloading s s in Templating functions Comp Sci 1570 Introduction to Outline s s in 1 2 3 s s in 4 Test 1 grade distribution grade on y, each student on x, sorted by y s s in 50 or below should talk to me. Outline

More information

More about BOOLEAN issues

More about BOOLEAN issues More about BOOLEAN issues Every boolean test is an implicit comparison against zero (0). However, zero is not a simple concept. It represents: the integer zero for all integral types the floating point

More information

Memory Addressing, Binary, and Hexadecimal Review

Memory Addressing, Binary, and Hexadecimal Review C++ By A EXAMPLE Memory Addressing, Binary, and Hexadecimal Review You do not have to understand the concepts in this appendix to become well-versed in C++. You can master C++, however, only if you spend

More information

CS31 Discussion. Jie(Jay) Wang Week8 Nov.18

CS31 Discussion. Jie(Jay) Wang Week8 Nov.18 CS31 Discussion Jie(Jay) Wang Week8 Nov.18 Outline Pointer Struct Memory Management When the program gets executed, it gets some amount of memory allocated for use. memory Program 1 Program 2 Memory Management

More information

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014 Lesson 10A OOP Fundamentals By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Definition Pointers vs containers Object vs primitives Constructors Methods Object class

More information

CSCI-1200 Data Structures Fall 2018 Lecture 5 Pointers, Arrays, & Pointer Arithmetic

CSCI-1200 Data Structures Fall 2018 Lecture 5 Pointers, Arrays, & Pointer Arithmetic CSCI-1200 Data Structures Fall 2018 Lecture 5 Pointers, Arrays, & Pointer Arithmetic Announcements: Test 1 Information Test 1 will be held Thursday, Sept 20th, 2018 from 6-7:50pm Students will be randomly

More information

COSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26

COSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26 COSC 2P95 Procedural Abstraction Week 3 Brock University Brock University (Week 3) Procedural Abstraction 1 / 26 Procedural Abstraction We ve already discussed how to arrange complex sets of actions (e.g.

More information

Kurt Schmidt. October 30, 2018

Kurt Schmidt. October 30, 2018 to Structs Dept. of Computer Science, Drexel University October 30, 2018 Array Objectives to Structs Intended audience: Student who has working knowledge of Python To gain some experience with a statically-typed

More information

Quiz 0 Answer Key. Answers other than the below may be possible. Multiple Choice. 0. a 1. a 2. b 3. c 4. b 5. d. True or False.

Quiz 0 Answer Key. Answers other than the below may be possible. Multiple Choice. 0. a 1. a 2. b 3. c 4. b 5. d. True or False. Quiz 0 Answer Key Answers other than the below may be possible. Multiple Choice. 0. a 1. a 2. b 3. c 4. b 5. d True or False. 6. T or F 7. T 8. F 9. T 10. T or F Itching for Week 0? 11. 00011001 + 00011001

More information

COP 3223 Final Review

COP 3223 Final Review COP 3223 Final Review Jennifer Brown December 2, 2018 1 Introduction 1.1 Variables I. How can we store data in a program? Initializing variables with data types A. Which of these are valid names for variables?

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

Lecture 10 Notes Linked Lists

Lecture 10 Notes Linked Lists Lecture 10 Notes Linked Lists 15-122: Principles of Imperative Computation (Summer 1 2015) Frank Pfenning, Rob Simmons, André Platzer 1 Introduction In this lecture we discuss the use of linked lists to

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

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 4 C Pointers 2004-09-08 Lecturer PSOE Dan Garcia www.cs.berkeley.edu/~ddgarcia Cal flies over Air Force We re ranked 13 th in the US and

More information