2. Blowing your mind with a simple truth

Size: px
Start display at page:

Download "2. Blowing your mind with a simple truth"

Transcription

1 1. Languages are classified by their memory management scheme In garbage collected languages such as Java, python, C#, etc., the system handles the task of freeing memory + Much faster to write programs + Much, much, much less error-prone Tends to keep memory around longer than necessary Runs much, much much slower and less predictably In manually memory managed languages such as C, Fortran, C++, etc., the user directly controls memory allocation and deallocation + Memory usage can be minimized by freeing data as early as pos + No sys process need run to do garbage collection, resulting in better and more predictable performance Takes longer to produce a working program, since programmer must manually control memory Working program often still contains mem management bugs: 1. deallocation of never allocated memory 2. memory leak: failure to deallocate memory after use 3. double free of allocated memory 4. Access past end of allocated memory You must understand how memory is organized and how variables are stored in it 2. Blowing your mind with a simple truth Everything that a computer can do comes down to manipulating binary numbers (boolean math) Every single thing involved in programming is stored in a computer as a binary number: 1. The instruction of your compiled program are stored in memory as binary numbers (text/code section of memory) 2. All automatic variables are dynamically allocated and deallocated to the stack as needed (as binary numbers, even strings!) 3. All global and static variables are stored in the data portion (as binary numbers) 3. Fundamental data types in C The two fundamental data types are the integral and floating point types: 1. Integral types: store integer numbers Default type: int Constants: 10, 0, 0xFFFA, 32 Size variants: char, short, int, long int Modifiers: unsigned, signed 2. Floating point types: store real numbers Default type: double Constants: 0.5, 10.0, 0.0, 1.2e3 ( == ) Size variants: float, double, long double Modifiers: none 4. Numbers are infinite, but storage is finite long int l; short s; char c; printf("\nsizeof(char,short,int,long int) = (%lu,%lu,%lu,%lu)\n\n", sizeof(c), sizeof(s), sizeof(i), sizeof(l)); printf("char short int long int\n"); printf("==== ====== =========== =====================\n"); c = s = i = l = 1; do c *= 2; s *= 2; i *= 2; l *= 2; printf("%4d %6d %11d %21ld\n", c, s, i, l); while (l > 0);

2 5. Numbers are infinite, but storage finite: OUTPUT sizeof(char,short,int,long int) = (1,2,4,8) char short int long int ==== ====== =========== ===================== There are infinite numbers between any two real numbers Not all numbers can be stored: * Real #s continuous and infinite * fp #s discreet and finite 1. Can be too large overflow 2. Can be too small underflow or subnormal/denormalized 3. Can have too many significant digits rounded 4. Can have no representation in fp storage rounded Infinite decimal in binary storage, eg double d; float f; f = 0.1; d = 0.1; printf("0.1 = %.20f\n", f); printf("0.1 = %.20lf\n", d); >gcc -o xtst real.c 0.1 = = Waitaminute: did you say char was an int? Everything is stored as number. It s all down to interpretation, and 1-byte (8 bits, unsigned int) chars can be translated as integers or characters, with translation from ASCII character codes (left). char ca = 65; printf("ca = %c (%d) %c!\n", ca, ca, ca+32); for (i=65; i < 91; i++) printf("%c", i); printf("\n"); ca = A (65) a! ABCDEFGHIJKLMNOPQRSTUVWXYZ DEC CHAR 0-8 nonprinting 9 \t : tab 10 \n : line feed nonprinting 32 space 33! 34 " 35 # 36 $ 37 % 38 & ( 41 ) 42 * , / DEC CHAR : 59 ; 60 < 61 = 62 > 63? A Z 91 [ 92 \ 93 ] 94 ^ 95 _ a z ~ 127 DEL 8. Classifying variables C has three general classifications of variables, which control when they are created and destroyed: 1. automatic variables (AKA local or dynamic variables): declared: inside scope () without static mod example: main(void) int i, k; accessible: only within scope lifetime: Come into existence when scope is entered during execution, deallocated when scope execution finished. Parameters are local to scope of func 2. Global variables: declared: outside functions example: int GLOB_I, JJJ=10; (appearing outside any scope) accessible: any code (using extern outside file) lifetime: Exist for entire life of program. GLOB_I has undefined start value, but JJJ is 10 at start of execution. 3. private global variables: declared: outside or inside scopes with static modifier example: static int II=0, JJ=10; accessible: by same file or private to scope (see below) lifetime: Exist for entire life of program. If decl appears inside scope, the variable is private to the scope; if decl outside scope, the variables are private to the file.

3 9. A Program s Memory Address Space Each prog (process) has full address space, as on right: Exact organization varies by architecture: Typically, heap begins at and grows upward Stack begins at and grows downward Memory between heap & stack is unused, and will not be allocated in mem or on disk until created instructions of program are stored in the text sec global variables exist for entire execution, and are allocated in the data section of heap; are initialized at program startup, and dealloced at program end Dynamically allocated memory is explicitly allocated (in the heap) (malloc/calloc) and dealloced (free) by the programmer Automatic variables exist only within a scope, and are automatically allocated and dealloc by compiler on the stack upon scope invocation and completion 0xFFFFFFFFFFFFFFFF stack unused space heap data (global) text (code) 0x0 void PrintYourStack(int i); printf("addr(i)=%lu\n\n", PrintYourStack(i); #define UL (unsigned long) void PrintYourStack(int i) int j, k; char c; printf("addr(i)=%lu\n", printf("addr(j)=%lu\n",ul &j); printf("addr(k)=%lu\n",ul&k); printf("addr(c)=%lu\n",ul&c); if (1) printf("addr(i)=%lu (IF!)\n", UL&i); 10. Stack example automatic vars can share name, but not be same var Compiler free to reorder vars within funcs but conceptually, stack would look like: main i PYS i PYS j PYS k PYS c IF i void PrintYourStack(int i); printf("addr(i)=%lu\n\n", PrintYourStack(i); #define UL (unsigned long) void PrintYourStack(int i) int j, k; char c; printf("addr(i)=%lu\n", printf("addr(j)=%lu\n",ul &j); printf("addr(k)=%lu\n",ul&k); printf("addr(c)=%lu\n",ul&c); if (1) printf("addr(i)=%lu (IF!)\n", UL&i); 11. Stack example (continued) >gcc -Wall -ansi -O3 -o xtst stackprn.c ADDR(i)= ADDR(i)= ADDR(j)= ADDR(k)= ADDR(c)= ADDR(i)= (IF!) & is the address operator main s stack frame 29 bytes from Print- YourStack s compiler puts other stuff besides auto vars on stack! Comp roughly reversed order of local vars for PYS Int paras 4 bytes apart (sizeof(int) = 4)! Comp puts char 1st, skips addr for alignment Comp has put if s i in with PYS s to avoid adjusting stack 12. Understanding variables and being confused by pointers Every variable has a lifetime (scope) Every variable has a location in memory (AKA an address) where its value is stored Two variables with the same name can have different values because they are stored in different locations! Every time you reference a variable in your program, the computer is looking up it s value from the address! (small lie) If two variables map to same location they are usually automatic variables that do not exist at the same time Two variables that map to same location at the same time are usually a union, which we don t know yet Remember: everything stored as binary #: variable declaration tells compiler how to interpret value! A pointer is a new kind of variable, that instead of storing a normal value, stores an address in memory. A pointer is often initialized with the address operator (&) The value a pointer points to can be changed by using the dereference operator (*)

4 #define UL (unsigned long) int i=2, j=4, k; int *ip; k = 2; k = 3; printf("i,j,k=(%d,%d,%d)\n", i, j, k); ip = &j; printf("addr(j)=%lu, ip=%lu\n", UL &j, UL ip); printf("j=%d, *ip=%d\n", j, *ip); i = 28; printf("j=%d, *ip=%d\n", j, *ip); *ip = 35; printf("j=%d, *ip=%d\n", j, *ip); printf("addr(j)=%lu, ip=%lu\n", UL &j, UL ip); ip = &k; *ip = 102; printf("i,j,k=(%d,%d,%d)\n", i, j, k); int i=0, j=1; int ChangeIt(int i, int j); i = ChangeIt(i, j); int ChangeIt(int i, int j) i += 8; j += 9; return(i); >gcc -ansi -o xtst ptr1.c i=0, j=1 i=8, j=1 13. Understanding pointers >gcc -ansi -o xtst ptr0.c i,j,k=(2,4,3) ADDR(j)= , ip= j=4, *ip=4 j=4, *ip=4 j=35, *ip=35 ADDR(j)= , ip= i,j,k=(28,35,102) A ptr points to/refers to the storage location of another variable! When we take an action on the data referred to by the ptr, we say we dereference it Applied to a ptr, * is the dereference operator * also indicates ptr declaration As long as ip pts to j s storage, changing one changes the other! not true once it pts somewhere else! 15. Why pointers? int i=0, j=1; void ChangeIt(int*, int*); ChangeIt(&i, &j); void ChangeIt(int *ip, int *kp) *ip += 8; *kp += 9; >gcc -ansi -o xtst ptr2.c i=0, j=1 i=8, j= Understanding pointers II Just like other variables, ptrs get space in memory, but what is stored there is a memory address, rather than the usual integer value Ptrs are really just integers that are long enough to store a complete memory address When a ptr is dereferenced for a read (eg., j = *ip;): 1. The compiler loads the address stored in the ptr s storage loc 2. The compiler then loads the value from the address just loaded from the ptr s storage Compiler knows how to interpret the value because the declaration of ip tells it what type it points to (eg., int *ip;). Pointers usually slower to use than variables! 16. Understanding 1-D arrays An array is a way to associate multiple items with a single name: individual items are accessed by indexing (AKA subscripting/offsetting), in C this is array[index] Arrays can be accessed in loops more conveniantly using loop counter as index. Eg., search an N-length array for the value -1: for (i=0; i < N; i++) if (iarr[i] == -1) return(i); int iarr[4];... iarr[3] iarr[2] iarr[1] iarr[0] main... #define UL (unsigned long int) int i, iarr[4] = 0, 1, 2, 3; printf("%lu, %lu\n", UL iarr, UL &iarr[0]); printf("%lu, %lu\n", UL (iarr+1), UL (&iarr[1])); for (i=1; i < 4; i++) printf("dist iarr[%d] = %d\n", i, (int)((ul(&iarr[i]))-(ul iarr))); >gcc -ansi -o xtst arr0.c , , dist iarr[1] = 4 dist iarr[2] = 8 dist iarr[3] = 12

5 17. Arrays and Pointers Pointers can be offset/indexed just like arrays Pointers can point to arrays Arrays are simply pointers that have space allocated by the compiler and can t change what they point to! iarr[3] iarr[2] ip iarr[1] iarr[0] main... Q1 What would ip[-1] = 22; do? Q2 How about ip[3] = 7;? int i, iarr[4] = 0, 1, 2, 3, *ip; ip = &iarr[1]; printf("ip[1]=%d, iarr[2]=%d\n", ip[1], iarr[2]); printf("iarr[3]=%d\n", iarr[3]); ip[2] = 55; printf("iarr[3]=%d\n", iarr[3]); ip[1]=2, iarr[2]=2 iarr[3]=3 iarr[3]= Memory overwrites and the pointer foot-gun Pointers can point at any piece of memory and then you can choose to do crazy stupid things with very hard-to-predict side effects: #define UL (unsigned long int) main(void) volatile int i=0, j=1, k=2, *ip; printf("ia=%lu\nja=%lu\nka=%lu\n", UL&i, UL&j, UL&k); ip = &j; ip[1] = 55; printf("i=%d, j=%d, k=%d\n", i, j, k); printf("*ip=%d, ip[0]=%d\n", *ip, ip[0]); >gcc -ansi -o xtst ptr3.c ia= ja= ka= i=0, j=1, k=55 *ip=1, ip[0]=1 k ip j i main Pointers, dynamic memory allocation, and variable length arrays Pointers and memory allocation can be used to handle arrays of unknown or varying lengths (dynamically sized arrays): #include <stdlib.h> #include <assert.h> int i, N; int *ip; printf("enter length of array: "); assert(scanf("%d", &N) == 1); ip = malloc(n*sizeof(int)); assert(ip!= NULL); for (i=0; i < N; i++) ip[i] = i; for (i=0; i < N; i++) printf("ip[%d] = %d\n", i, ip[i]); free(ip); Enter length of array: 2 ip[0] = 100 ip[1] = 101 malloc (memory allocate): tries to allocate space on the heap as specified by length argument malloc should return NULL (0) if no memory available We use assert to ensure we got memory before using it! free: releases previously allocated memory back to system On a different run, the array length could be 10,000 w/o error! Run program with valgrind --leak-check=yes anytime dynamic memory is used! 20. Strings are null-terminated 1-D arrays of chars In C, strings are simply 1-D arrays of chars: Maximum length of string declared as usual: char str[256]; End of printing string indicated by \0 (int/ascii 0) Strings called null (0) terminated (NULL of ptrs also 0) /* printf */ #include <stdlib.h> /* malloc */ #include <string.h> /* strcpy/strlen */ #include <assert.h> /* assert */ int main(int nargs, char *args[]) char *s1 = "default str"; char s2[8]= h, e, l, l, o, \0,0,0; char *s3; char *dynstr; printf("s1 = %s \n", s1); printf("s2 = %s \n", s2); s3 = (nargs>1)? args[1]:args[0]; i = strlen(s3); assert(i > 0); dynstr = malloc((i+1)*sizeof(char)); assert(dynstr); strcpy(dynstr, s3); printf("dynstr(len=%d) = %s \n",i,dynstr); free(dynstr); bob s1 = default str s2 = hello dynstr(len=3) = bob./xtst s1 = default str s2 = hello dynstr(len=6) =./xtst size_t strlen(const char *s);: Returns length of string not including null terminator! char *strcpy(char *dest, const char *src);: copies src to dest assuming src is long enough!

6 21. Pointers can be used to return whole arrays /* printf */ #include <stdlib.h> /* malloc */ #include <assert.h> /* assert */ void my_strcpy(char *out, char *in) /* not same as real strcpy */ while(*out++ = *in++); int my_strlen(char *s) int i=0; if (s) for (i=0; s[i]; i++); return(i); char *DupString(char *s) char *ns; i = my_strlen(s) + 1; ns = malloc(sizeof(char)*i); assert(ns); my_strcpy(ns, s); return(ns); int main(int nargs, char *args[]) char *s1 = "default str"; char s2[8] = h, e, l, l, o ; char *s3; char *dynstr; printf("s1 = %3.3s \n", s1); printf("s2 = %s \n", s2); s3 = (nargs>1)? args[1]:args[0]; dynstr = DupString(s3); i = my_strlen(dynstr); printf("dynstr(len=%d) = %s \n", i, dynstr); free(dynstr); >gcc -Wall -ansi -g -o xtst str1.c str1.c: In function my_strcpy: str1.c:7:4: warning: suggest parentheses around ass s1 = def s2 = hello dynstr(len=6) =./xtst

Pointers, Arrays, and Strings. CS449 Spring 2016

Pointers, Arrays, and Strings. CS449 Spring 2016 Pointers, Arrays, and Strings CS449 Spring 2016 Pointers Pointers are important. Pointers are fun! Pointers Every variable in your program has a memory location. This location can be accessed using & operator.

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

CS 61C: Great Ideas in Computer Architecture. C Arrays, Strings, More Pointers

CS 61C: Great Ideas in Computer Architecture. C Arrays, Strings, More Pointers CS 61C: Great Ideas in Computer Architecture C Arrays, Strings, More Pointers Instructor: Justin Hsia 6/20/2012 Summer 2012 Lecture #3 1 Review of Last Lecture C Basics Variables, Functions, Flow Control,

More information

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine

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

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

Principles of C and Memory Management

Principles of C and Memory Management COMP281 Lecture 9 Principles of C and Memory Management Dr Lei Shi Last Lecture Today Pointer to Array Pointer Arithmetic Pointer with Functions struct Storage classes typedef union String struct struct

More information

Intermediate Programming, Spring 2017*

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

More information

Lectures 5-6: Introduction to C

Lectures 5-6: Introduction to C Lectures 5-6: Introduction to C Motivation: C is both a high and a low-level language Very useful for systems programming Faster than Java This intro assumes knowledge of Java Focus is on differences Most

More information

CS61C Machine Structures. Lecture 4 C Structs & Memory Management. 9/5/2007 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/

CS61C Machine Structures. Lecture 4 C Structs & Memory Management. 9/5/2007 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/ CS61C Machine Structures Lecture 4 C Structs & Memory Management 9/5/2007 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L04 C Structs (1) C String Standard Functions

More information

ch = argv[i][++j]; /* why does ++j but j++ does not? */

ch = argv[i][++j]; /* why does ++j but j++ does not? */ CMPS 12M Introduction to Data Structures Lab Lab Assignment 4 The purpose of this lab assignment is to get more practice programming in C, including the character functions in the library ctype.h, and

More information

CS61C Machine Structures. Lecture 5 C Structs & Memory Mangement. 1/27/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/

CS61C Machine Structures. Lecture 5 C Structs & Memory Mangement. 1/27/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/ CS61C Machine Structures Lecture 5 C Structs & Memory Mangement 1/27/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L05 C Structs (1) C String Standard Functions

More information

Understanding Pointers

Understanding Pointers Division of Mathematics and Computer Science Maryville College Pointers and Addresses Memory is organized into a big array. Every data item occupies one or more cells. A pointer stores an address. A pointer

More information

ECE 250 / CS 250 Computer Architecture. C to Binary: Memory & Data Representations. Benjamin Lee

ECE 250 / CS 250 Computer Architecture. C to Binary: Memory & Data Representations. Benjamin Lee ECE 250 / CS 250 Computer Architecture C to Binary: Memory & Data Representations Benjamin Lee Slides based on those from Alvin Lebeck, Daniel Sorin, Andrew Hilton, Amir Roth, Gershon Kedem Administrivia

More information

Programming. Pointers, Multi-dimensional Arrays and Memory Management

Programming. Pointers, Multi-dimensional Arrays and Memory Management Programming Pointers, Multi-dimensional Arrays and Memory Management Summary } Computer Memory } Pointers } Declaration, assignment, arithmetic and operators } Casting and printing pointers } Relationship

More information

CS 33. Introduction to C. Part 5. CS33 Intro to Computer Systems V 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

CS 33. Introduction to C. Part 5. CS33 Intro to Computer Systems V 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. CS 33 Introduction to C Part 5 CS33 Intro to Computer Systems V 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. Basic Data Types int short char -2,147,483,648 2,147,483,647-32,768 32,767-128

More information

Lecture 04 Introduction to pointers

Lecture 04 Introduction to pointers Lecture 04 Introduction to pointers A pointer is an address in the memory. One of the unique advantages of using C is that it provides direct access to a memory location through its address. A variable

More information

Arrays and Pointers in C. Alan L. Cox

Arrays and Pointers in C. Alan L. Cox Arrays and Pointers in C Alan L. Cox alc@rice.edu Objectives Be able to use arrays, pointers, and strings in C programs Be able to explain the representation of these data types at the machine level, including

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

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #4 C Memory Management 2007-06-28 Scott Beamer, Instructor iphone Comes out Tomorrow CS61C L4 C Memory Management (1) www.apple.com/iphone

More information

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor CS 261 Fall 2017 Mike Lam, Professor C Introduction Variables, Memory Model, Pointers, and Debugging The C Language Systems language originally developed for Unix Imperative, compiled language with static

More information

advanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef

advanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef today advanced data types (1) typedef. mon 23 sep 2002 homework #1 due today homework #2 out today quiz #1 next class 30-45 minutes long one page of notes topics: C advanced data types dynamic memory allocation

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 5 C Memory Management Lecturer PSOE Dan Garcia www.cs.berkeley.edu/~ddgarcia CS 61C L04 C Structures, Memory Management (1) 2004-09-10 Barry

More information

CSC 1600 Memory Layout for Unix Processes"

CSC 1600 Memory Layout for Unix Processes CSC 16 Memory Layout for Unix Processes" 1 Lecture Goals" Behind the scenes of running a program" Code, executable, and process" Memory layout for UNIX processes, and relationship to C" : code and constant

More information

Why Pointers. Pointers. Pointer Declaration. Two Pointer Operators. What Are Pointers? Memory address POINTERVariable Contents ...

Why Pointers. Pointers. Pointer Declaration. Two Pointer Operators. What Are Pointers? Memory address POINTERVariable Contents ... Why Pointers Pointers They provide the means by which functions can modify arguments in the calling function. They support dynamic memory allocation. They provide support for dynamic data structures, such

More information

CS 222: Pointers and Manual Memory Management

CS 222: Pointers and Manual Memory Management CS 222: Pointers and Manual Memory Management Chris Kauffman Week 4-1 Logistics Reading Ch 8 (pointers) Review 6-7 as well Exam 1 Back Today Get it in class or during office hours later HW 3 due tonight

More information

Arrays and Memory Management

Arrays and Memory Management Arrays and Memory Management 1 Pointing to Different Size Objects Modern machines are byte-addressable Hardware s memory composed of 8-bit storage cells, each has a unique address A C pointer is just abstracted

More information

CS 11 C track: lecture 5

CS 11 C track: lecture 5 CS 11 C track: lecture 5 Last week: pointers This week: Pointer arithmetic Arrays and pointers Dynamic memory allocation The stack and the heap Pointers (from last week) Address: location where data stored

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

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

Dynamic Allocation in C

Dynamic Allocation in C Dynamic Allocation in C C Pointers and Arrays 1 The previous examples involved only targets that were declared as local variables. For serious development, we must also be able to create variables dynamically,

More information

Pointers, Arrays, Memory: AKA the cause of those Segfaults

Pointers, Arrays, Memory: AKA the cause of those Segfaults Computer Science 61C Spring 2018 Wawrzynek and Weaver Pointers, Arrays, Memory: AKA the cause of those F@#)(#@*( Segfaults 1 Agenda Computer Science 61C Spring 2018 Pointers Arrays in C Memory Allocation

More information

Procedural programming with C

Procedural programming with C Procedural programming with C Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 77 Functions Similarly to its mathematical

More information

PRINCIPLES OF OPERATING SYSTEMS

PRINCIPLES OF OPERATING SYSTEMS PRINCIPLES OF OPERATING SYSTEMS Tutorial-1&2: C Review CPSC 457, Spring 2015 May 20-21, 2015 Department of Computer Science, University of Calgary Connecting to your VM Open a terminal (in your linux machine)

More information

A brief introduction to C programming for Java programmers

A brief introduction to C programming for Java programmers A brief introduction to C programming for Java programmers Sven Gestegård Robertz September 2017 There are many similarities between Java and C. The syntax in Java is basically

More information

DAY 3. CS3600, Northeastern University. Alan Mislove

DAY 3. CS3600, Northeastern University. Alan Mislove C BOOTCAMP DAY 3 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh and Pascal Meunier s course at Purdue Memory management 2 Memory management Two

More information

CS C Primer. Tyler Szepesi. January 16, 2013

CS C Primer. Tyler Szepesi. January 16, 2013 January 16, 2013 Topics 1 Why C? 2 Data Types 3 Memory 4 Files 5 Endianness 6 Resources Why C? C is exteremely flexible and gives control to the programmer Allows users to break rigid rules, which are

More information

Bil 104 Intiroduction To Scientific And Engineering Computing. Lecture 7

Bil 104 Intiroduction To Scientific And Engineering Computing. Lecture 7 Strings and Clases BIL104E: Introduction to Scientific and Engineering Computing Lecture 7 Manipulating Strings Scope and Storage Classes in C Strings Declaring a string The length of a string Copying

More information

COMP 2355 Introduction to Systems Programming

COMP 2355 Introduction to Systems Programming COMP 2355 Introduction to Systems Programming Christian Grothoff christian@grothoff.org http://grothoff.org/christian/ 1 Pointers Pointers denote addresses in memory In C types, the * represents the use

More information

Intermediate Programming, Spring 2017*

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

More information

CS 5513 Entry Quiz. Systems Programming (CS2213/CS3423))

CS 5513 Entry Quiz. Systems Programming (CS2213/CS3423)) Name (please print): CS 5513 Entry Quiz Systems Programming (CS2213/CS3423)) 1. What is a compiler? In addition to the definition, give examples of compilers you have used. A compiler is a program that

More information

Dynamic Allocation in C

Dynamic Allocation in C Dynamic Allocation in C 1 The previous examples involved only targets that were declared as local variables. For serious development, we must also be able to create variables dynamically, as the program

More information

High Performance Programming Programming in C part 1

High Performance Programming Programming in C part 1 High Performance Programming Programming in C part 1 Anastasia Kruchinina Uppsala University, Sweden April 18, 2017 HPP 1 / 53 C is designed on a way to provide a full control of the computer. C is the

More information

Dynamic memory allocation

Dynamic memory allocation Dynamic memory allocation outline Memory allocation functions Array allocation Matrix allocation Examples Memory allocation functions (#include ) malloc() Allocates a specified number of bytes

More information

Memory Allocation in C C Programming and Software Tools. N.C. State Department of Computer Science

Memory Allocation in C C Programming and Software Tools. N.C. State Department of Computer Science Memory Allocation in C C Programming and Software Tools N.C. State Department of Computer Science The Easy Way Java (JVM) automatically allocates and reclaims memory for you, e.g... Removed object is implicitly

More information

C Introduction. Comparison w/ Java, Memory Model, and Pointers

C Introduction. Comparison w/ Java, Memory Model, and Pointers CS 261 Fall 2018 Mike Lam, Professor C Introduction Comparison w/ Java, Memory Model, and Pointers Please go to socrative.com on your phone or laptop, choose student login and join room LAMJMU The C Language

More information

Tutorial 1 C Tutorial: Pointers, Strings, Exec

Tutorial 1 C Tutorial: Pointers, Strings, Exec TCSS 422: Operating Systems Institute of Technology Spring 2017 University of Washington Tacoma http://faculty.washington.edu/wlloyd/courses/tcss422 Tutorial 1 C Tutorial: Pointers, Strings, Exec The purpose

More information

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14 C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition

More information

Jagannath Institute of Management Sciences Lajpat Nagar. BCA II Sem. C Programming

Jagannath Institute of Management Sciences Lajpat Nagar. BCA II Sem. C Programming Jagannath Institute of Management Sciences Lajpat Nagar BCA II Sem C Programming UNIT I Pointers: Introduction to Pointers, Pointer Notation,Decalaration and Initialization, Accessing variable through

More information

Array Initialization

Array Initialization Array Initialization Array declarations can specify initializations for the elements of the array: int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 ; initializes primes[0] to 2, primes[1] to 3, primes[2]

More information

C: Pointers, Arrays, and strings. Department of Computer Science College of Engineering Boise State University. August 25, /36

C: Pointers, Arrays, and strings. Department of Computer Science College of Engineering Boise State University. August 25, /36 Department of Computer Science College of Engineering Boise State University August 25, 2017 1/36 Pointers and Arrays A pointer is a variable that stores the address of another variable. Pointers are similar

More information

Pointers (part 1) What are pointers? EECS We have seen pointers before. scanf( %f, &inches );! 25 September 2017

Pointers (part 1) What are pointers? EECS We have seen pointers before. scanf( %f, &inches );! 25 September 2017 Pointers (part 1) EECS 2031 25 September 2017 1 What are pointers? We have seen pointers before. scanf( %f, &inches );! 2 1 Example char c; c = getchar(); printf( %c, c); char c; char *p; c = getchar();

More information

Agenda. Peer Instruction Question 1. Peer Instruction Answer 1. Peer Instruction Question 2 6/22/2011

Agenda. Peer Instruction Question 1. Peer Instruction Answer 1. Peer Instruction Question 2 6/22/2011 CS 61C: Great Ideas in Computer Architecture (Machine Structures) Introduction to C (Part II) Instructors: Randy H. Katz David A. Patterson http://inst.eecs.berkeley.edu/~cs61c/sp11 Spring 2011 -- Lecture

More information

Lecture Notes on Types in C

Lecture Notes on Types in C Lecture Notes on Types in C 15-122: Principles of Imperative Computation Frank Pfenning, Rob Simmons Lecture 20 April 2, 2013 1 Introduction In lecture 18, we emphasized the things we lost by going to

More information

Pointer Arithmetic and Lexical Scoping. CS449 Spring 2016

Pointer Arithmetic and Lexical Scoping. CS449 Spring 2016 Pointer Arithmetic and Lexical Scoping CS449 Spring 2016 Review Pitfall 1 from previous lecture void foo(char *s) { s = "World"; int main() { char *str = "Hello"; foo(str); printf("%s\n", str); return

More 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

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

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 5 C Memory Management Lecturer PSOE Dan Garcia www.cs.berkeley.edu/~ddgarcia CS61C L05 C Structures, Memory Management (1) 2005-01-28 The

More information

CSci 4061 Introduction to Operating Systems. Programs in C/Unix

CSci 4061 Introduction to Operating Systems. Programs in C/Unix CSci 4061 Introduction to Operating Systems Programs in C/Unix Today Basic C programming Follow on to recitation Structure of a C program A C program consists of a collection of C functions, structs, arrays,

More information

COSC Software Engineering. Lecture 16: Managing Memory Managers

COSC Software Engineering. Lecture 16: Managing Memory Managers COSC345 2013 Software Engineering Lecture 16: Managing Memory Managers Outline Typical problems (from previous lectures) Memory leaks aren t just for (Objective) C Tracking malloc() calls Catching calls

More information

Q1: /8 Q2: /30 Q3: /30 Q4: /32. Total: /100

Q1: /8 Q2: /30 Q3: /30 Q4: /32. Total: /100 ECE 2035(A) Programming for Hardware/Software Systems Fall 2013 Exam Three November 20 th 2013 Name: Q1: /8 Q2: /30 Q3: /30 Q4: /32 Total: /100 1/10 For functional call related questions, let s assume

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

ECE 15B COMPUTER ORGANIZATION

ECE 15B COMPUTER ORGANIZATION ECE 15B COMPUTER ORGANIZATION Lecture 13 Strings, Lists & Stacks Announcements HW #3 Due next Friday, May 15 at 5:00 PM in HFH Project #2 Due May 29 at 5:00 PM Project #3 Assigned next Thursday, May 19

More information

Review: C Strings. A string in C is just an array of characters. Lecture #4 C Strings, Arrays, & Malloc

Review: C Strings. A string in C is just an array of characters. Lecture #4 C Strings, Arrays, & Malloc CS61C L4 C Pointers (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #4 C Strings, Arrays, & Malloc Albert Chae Instructor 2008-06-26 Review: C Strings A string in C is just an array

More information

Lecture 8 Dynamic Memory Allocation

Lecture 8 Dynamic Memory Allocation Lecture 8 Dynamic Memory Allocation CS240 1 Memory Computer programs manipulate an abstraction of the computer s memory subsystem Memory: on the hardware side 3 @ http://computer.howstuffworks.com/computer-memory.htm/printable

More information

When you add a number to a pointer, that number is added, but first it is multiplied by the sizeof the type the pointer points to.

When you add a number to a pointer, that number is added, but first it is multiplied by the sizeof the type the pointer points to. Refresher When you add a number to a pointer, that number is added, but first it is multiplied by the sizeof the type the pointer points to. i.e. char *ptr1 = malloc(1); ptr1 + 1; // adds 1 to pointer

More information

Class Information ANNOUCEMENTS

Class Information ANNOUCEMENTS Class Information ANNOUCEMENTS Third homework due TODAY at 11:59pm. Extension? First project has been posted, due Monday October 23, 11:59pm. Midterm exam: Friday, October 27, in class. Don t forget to

More information

Procedural Programming & Fundamentals of Programming

Procedural Programming & Fundamentals of Programming Procedural Programming & Fundamentals of Programming Exercise 3 (SS 2018) 29.05.2018 What will I learn in the 4. exercise Pointer (and a little bit about memory allocation) Structure Strings and String

More information

CS 61C: Great Ideas in Computer Architecture. Lecture 3: Pointers. Bernhard Boser & Randy Katz

CS 61C: Great Ideas in Computer Architecture. Lecture 3: Pointers. Bernhard Boser & Randy Katz CS 61C: Great Ideas in Computer Architecture Lecture 3: Pointers Bernhard Boser & Randy Katz http://inst.eecs.berkeley.edu/~cs61c Agenda Pointers in C Arrays in C This is not on the test Pointer arithmetic

More information

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee. Midterm Exam Nov 8th, 2012 COMS W3157 Advanced Programming Columbia University Fall 2012 Instructor: Jae Woo Lee About this exam: - There are 4 problems totaling 100 points: problem 1: 30 points problem

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

o Code, executable, and process o Main memory vs. virtual memory

o Code, executable, and process o Main memory vs. virtual memory Goals for Today s Lecture Memory Allocation Prof. David August COS 217 Behind the scenes of running a program o Code, executable, and process o Main memory vs. virtual memory Memory layout for UNIX processes,

More information

Agenda. Components of a Computer. Computer Memory Type Name Addr Value. Pointer Type. Pointers. CS 61C: Great Ideas in Computer Architecture

Agenda. Components of a Computer. Computer Memory Type Name Addr Value. Pointer Type. Pointers. CS 61C: Great Ideas in Computer Architecture CS 61C: Great Ideas in Computer Architecture Krste Asanović & Randy Katz http://inst.eecs.berkeley.edu/~cs61c And in Conclusion, 2 Processor Control Datapath Components of a Computer PC Registers Arithmetic

More information

Lectures 13 & 14. memory management

Lectures 13 & 14. memory management Lectures 13 & 14 Linked lists and memory management Courtesy of Prof. Garcia (UCB) CS61C L05 Introduction to C (pt 3) (1) Review Pointers and arrays are virtually same C knows how to increment pointers

More information

ELEC / COMP 177 Fall Some slides from Kurose and Ross, Computer Networking, 5 th Edition

ELEC / COMP 177 Fall Some slides from Kurose and Ross, Computer Networking, 5 th Edition ELEC / COMP 177 Fall 2012 Some slides from Kurose and Ross, Computer Networking, 5 th Edition Prior experience in programming languages C++ programming? Java programming? C programming? Other languages?

More information

Chapter 11 Introduction to Programming in C

Chapter 11 Introduction to Programming in C Chapter 11 Introduction to Programming in C C: A High-Level Language Gives symbolic names to values don t need to know which register or memory location Provides abstraction of underlying hardware operations

More information

Chapter IV Introduction to C for Java programmers

Chapter IV Introduction to C for Java programmers Chapter IV Introduction to C for Java programmers Now that we have seen the native instructions that a processor can execute, we will temporarily take a step up on the abstraction ladder and learn the

More information

Under the Hood: Data Representations, Memory and Bit Operations. Computer Science 104 Lecture 3

Under the Hood: Data Representations, Memory and Bit Operations. Computer Science 104 Lecture 3 Under the Hood: Data Representations, Memory and Bit Operations Computer Science 104 Lecture 3 Homework #1 Due Feb 6 Reading TAs Finish Chapter 1 Start Chapter 2 Admin +1 UTA: Michael Zhou Lindsay is Head

More information

CS 61C: Great Ideas in Computer Architecture. Lecture 3: Pointers. Krste Asanović & Randy Katz

CS 61C: Great Ideas in Computer Architecture. Lecture 3: Pointers. Krste Asanović & Randy Katz CS 61C: Great Ideas in Computer Architecture Lecture 3: Pointers Krste Asanović & Randy Katz http://inst.eecs.berkeley.edu/~cs61c Agenda Pointers in C Arrays in C This is not on the test Pointer arithmetic

More information

Dynamic Memory. Dynamic Memory Allocation Strings. September 18, 2017 Hassan Khosravi / Geoffrey Tien 1

Dynamic Memory. Dynamic Memory Allocation Strings. September 18, 2017 Hassan Khosravi / Geoffrey Tien 1 Dynamic Memory Dynamic Memory Allocation Strings September 18, 2017 Hassan Khosravi / Geoffrey Tien 1 Pointer arithmetic If we know the address of the first element of an array, we can compute the addresses

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

Two s Complement Review. Two s Complement Review. Agenda. Agenda 6/21/2011

Two s Complement Review. Two s Complement Review. Agenda. Agenda 6/21/2011 Two s Complement Review CS 61C: Great Ideas in Computer Architecture (Machine Structures) Introduction to C (Part I) Instructor: Michael Greenbaum http://inst.eecs.berkeley.edu/~cs61c/su11 Suppose we had

More information

Memory, Data, & Addressing II CSE 351 Spring

Memory, 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 information

Outline. Lecture 1 C primer What we will cover. If-statements and blocks in Python and C. Operators in Python and C

Outline. Lecture 1 C primer What we will cover. If-statements and blocks in Python and C. Operators in Python and C Lecture 1 C primer What we will cover A crash course in the basics of C You should read the K&R C book for lots more details Various details will be exemplified later in the course Outline Overview comparison

More information

Lecture07: Strings, Variable Scope, Memory Model 4/8/2013

Lecture07: Strings, Variable Scope, Memory Model 4/8/2013 Lecture07: Strings, Variable Scope, Memory Model 4/8/2013 Slides modified from Yin Lou, Cornell CS2022: Introduction to C 1 Outline Review pointers New: Strings New: Variable Scope (global vs. local variables)

More information

C Arrays, Strings, More Pointers Instructor: Steven Ho

C Arrays, Strings, More Pointers Instructor: Steven Ho C Arrays, Strings, More Pointers Instructor: Steven Ho Review of Last Lecture C Basics Variables, Functions, Flow Control, Types, and Structs Only 0 and NULL evaluate to FALSE Pointers hold addresses Address

More information

Dynamic memory allocation (malloc)

Dynamic memory allocation (malloc) 1 Plan for today Quick review of previous lecture Array of pointers Command line arguments Dynamic memory allocation (malloc) Structures (Ch 6) Input and Output (Ch 7) 1 Pointers K&R Ch 5 Basics: Declaration

More information

Q1: /20 Q2: /30 Q3: /24 Q4: /26. Total: /100

Q1: /20 Q2: /30 Q3: /24 Q4: /26. Total: /100 ECE 2035(B) Programming for Hardware/Software Systems Fall 2013 Exam Two October 22 nd 2013 Name: Q1: /20 Q2: /30 Q3: /24 Q4: /26 Total: /100 1/6 For functional call related questions, let s assume the

More information

Dynamic Memory Allocation and Command-line Arguments

Dynamic Memory Allocation and Command-line Arguments Dynamic Memory Allocation and Command-line Arguments CSC209: Software Tools and Systems Programming Furkan Alaca & Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Week 3

More information

CS 31: Intro to Systems C Programming. Kevin Webb Swarthmore College September 13, 2018

CS 31: Intro to Systems C Programming. Kevin Webb Swarthmore College September 13, 2018 CS 31: Intro to Systems C Programming Kevin Webb Swarthmore College September 13, 2018 Reading Quiz Agenda Basics of C programming Comments, variables, print statements, loops, conditionals, etc. NOT the

More information

Hacking in C. Pointers. Radboud University, Nijmegen, The Netherlands. Spring 2019

Hacking in C. Pointers. Radboud University, Nijmegen, The Netherlands. Spring 2019 Hacking in C Pointers Radboud University, Nijmegen, The Netherlands Spring 2019 Allocation of multiple variables Consider the program main(){ char x; int i; short s; char y;... } What will the layout of

More information

Create a Program in C (Last Class)

Create a Program in C (Last Class) Create a Program in C (Last Class) Input: three floating point numbers Output: the average of those three numbers Use: scanf to get the input printf to show the result a function to calculate the average

More information

Pointers (continued), arrays and strings

Pointers (continued), arrays and strings Pointers (continued), arrays and strings 1 Last week We have seen pointers, e.g. of type char *p with the operators * and & These are tricky to understand, unless you draw pictures 2 Pointer arithmetic

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

LOÏC CAPPANERA. 1. Memory management The variables involved in a C program can be stored either statically or dynamically.

LOÏC CAPPANERA. 1. Memory management The variables involved in a C program can be stored either statically or dynamically. C PROGRAMMING LANGUAGE. MEMORY MANAGEMENT. APPLICATION TO ARRAYS. CAAM 519, CHAPTER 7 This chapter aims to describe how a programmer manages the allocation of memory associated to the various variables

More information

Memory, Arrays & Pointers

Memory, Arrays & Pointers 1 Memory, Arrays & Pointers Memory int main() { char c; int i,j; double x; c i j x 2 Arrays Defines a block of consecutive cells int main() { int i; int a[3]; i a[0] a[1] a[2] Arrays - the [ ] operator

More information

3/7/2018. Sometimes, Knowing Which Thing is Enough. ECE 220: Computer Systems & Programming. Often Want to Group Data Together Conceptually

3/7/2018. Sometimes, Knowing Which Thing is Enough. ECE 220: Computer Systems & Programming. Often Want to Group Data Together Conceptually University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 220: Computer Systems & Programming Structured Data in C Sometimes, Knowing Which Thing is Enough In MP6, we

More information

Low-Level C Programming. Memory map Pointers Arrays Structures

Low-Level C Programming. Memory map Pointers Arrays Structures Low-Level C Programming Memory map Pointers Arrays Structures Memory Map 0x7FFF_FFFF Binaries load at 0x20000 by default Stack start set by binary when started Stack grows downwards You will need one stack

More information

CS61, Fall 2012 Section 2 Notes

CS61, Fall 2012 Section 2 Notes CS61, Fall 2012 Section 2 Notes (Week of 9/24-9/28) 0. Get source code for section [optional] 1: Variable Duration 2: Memory Errors Common Errors with memory and pointers Valgrind + GDB Common Memory Errors

More information

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017 United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017 1. Do a page check: you should have 8 pages including this cover sheet. 2. You have 50 minutes

More information