Functions:"" Breaking"large"computing"tasks"to" smaller"ones"

Size: px
Start display at page:

Download "Functions:"" Breaking"large"computing"tasks"to" smaller"ones""

Transcription

1 Lecture'3'(P a rt1):'''''''' ' 0 3 ' C 'Programm E S C ing'' 1

2 Functions:"" Breaking"large"computing"tasks"to" smaller"ones" 2

3 C'Programming' 'Procedural'thought'process' main%()%/*%high%level%outline%*/% {% %%.%.%.% %%get_input(arg1)%/*comment:%step%1%*/% %%perform_step_2(arg2);%% %%perform_step_3();% %%store_result();%/*%print%output%or%store%in%a%file%*/% % }% ' 3

4 Overview'of'Functions' Functions'make'code'easy'to''! Maintain'! Debug'! Reuse' 4

5 Functions'Overview' void%foo(int%x,%int%y);%%//declaration" 5

6 //De5inition" Functions'Overview' void%foo(int%x,%int%y)%{% %%%int%tmp;% %%%tmp=%x;% %%%x=%y;% %%%y=%tmp;%%}%% What'does'foo'do?' tmp' x' foo' y' 6

7 Stack'Allocation:'Function'local' variables'and'parameters' When'program'execution'starts' Local'variables'of'func()' Other'information'about' func()' Local'variables'of'main()' What'if'main'calls'the'function'func()?' Stack'Pointer' 7

8 Stack'Allocation:'Function'local' variables'and'parameters' Variables'whose'lifetime'is'the'execution'time'of' function'are'managed'using'the'stack'structure' Local'variables'of'main()' Stack'Pointer' 8

9 Variables'declared'within'a'function'' A. can'be'used'by'other'functions' ' B. can'only'be'used'within'the'function'' C. continue'to'exist'in'memory'as'long'as'the' program'executes' ' 9

10 Consider'the'following'function' void%swap(int%x,%int%y);%% //Declaration" void%swap(int%x,%int%y)%{% %%%int%tmp;% %%%tmp=%x;% %%%x=%y;% %%%y=%tmp;%%}%% tmp' x' swap' y' The'swap'function'intends'to'swap'the'value' of'its'inputs.'is'the'logic'correct?' A. Yes' B. No' C. Depends' 10 x' y'

11 Q:'Are'the'value'of'variables' a 'and' b ' interchanged'after'swap'is'called?' main()%{% %%.%.%.% %%swap(a,%b);% %%.%.%.%.%}%% a' 5' 6' b' ' A. Yes,'because'..' B. No,'because..' ' ' 11

12 Q:'Which'of'the'following'changes'are'required'to' interchange'the'values'in' a 'and' b 'when'swap'is'called?' {%.%.%.%.% %swap(a,%b);% 5' 6' x' y' a' b' }%% swap' ' A. In'swap,'return'the'values'of' x 'and' y 'to'the'main'function' after'swapping'them' B. Declare' a 'and' b 'as'global'variables,'so'that'they'become' accessible'to'the'swap'routine' C. Pass'the'address'of' a 'and' b 'to'swap'instead'of'their'value' D. Move'the'implementation'in'swap'to'the'main'function'' ' 12

13 Q:'Which'of'the'following'changes'are'required'to' interchange'the'values'in' a 'and' b 'when'swap'is'called?' {%.%.%.%.% %swap(a,%b);% 5' 6' x' y' a' b' }%% swap' ' A. In'swap,'return'the'values'of' x 'and' y 'to'the'main'function' after'swapping'them' B. Declare' a 'and' b 'as'global'variables,'so'that'they'become' accessible'to'the'swap'routine' C. Pass'the'address'of' a 'and' b 'to'swap'instead'of'their'value' D. Move'the'implementation'in'swap'to'the'main'function'' ' 13

14 Functions:'Call'by'reference' Q:'What'should'the'modi[ied'swap'function'do?' ' void%swap(int%*x,%int%*y)%{% %%%.%.%.% }%% A. Swap'the'addresses''in' x 'and' y ' B. Swap'the'values'pointed'to'by' x 'and' y ' C. Both'the'above'operations'are'equivalent' ' 14

15 Functions:'Call'by'reference' Q:'What'should'the'modi[ied'swap'function'do?' ' void%swap(int%*x,%int%*y)%{% %%%.%.%.% }%% A. Swap'the'addresses''in' x 'and' y ' B. Swap'the'values'pointed'to'by' x 'and' y ' C. Both'the'above'operations'are'equivalent' ' 15

16 void IncrementPtr(int *p){ p = p + 1; } Q: What happens when IncrementPtr(q)is called in the following code: A q int A[3] = {50, 60, 70}; int *q = A; IncrementPtr(q);' A. The pointer q points to the next element in the array with value 60 B. The pointer q points to the first element in the array with value 50

17 void IncrementPtr(int *p){ p = p + 1; } Q: What happens when IncrementPtr(q)is called in the following code: A q int A[3] = {50, 60, 70}; int *q = A; IncrementPtr(q);' A. The pointer q points to the next element in the array with value 60 B. The pointer q points to the first element in the array with value 50

18 void IncrementPtr(int **p){ p = p + 1; } Q: How should we implement IncrementPtr(),so that q moves by one element when the following code executes? int A[3] = {50, 60, 70}; int *q = A; IncrementPtr(&q);' A q A. p = p + 1; //The current one is correct B. &p = &p + 1; C. *p= *p + 1; D. *p++; E. p= &p+1;

19 void IncrementPtr(int **p){ p = p + 1; } Q: How should we implement IncrementPtr(),so that q moves by one element when the following code executes? int A[3] = {50, 60, 70}; int *q = A; IncrementPtr(&q);' A q A. p = p + 1; //The current one is correct B. &p = &p + 1; C. *p= *p + 1; D. *p++; E. p= &p+1;

20 Derived"data"types:" Structures"

21 C structures : Overview A struct is a data structure composed of simpler data types. Like a class in Java/C++ but without methods or inheritance. struct point { int x; int y; } void PrintPoint(struct point p) { printf( (%d,%d), p.x, p.y); }

22 Pointers to structures The C arrow operator (->) dereferences and extracts a structure field with a single operator. The following are equivalent: struct point *p; printf( x is %d\n, (*p).x); printf( x is %d\n, p->x);

23 Representation in memory struct p { int y; char x; }; struct p sp; sp' y'(4'bytes)' x'(1byte)' 0x100' 0x104' 0x105'

24 struct p { char x; int y; }; Struct p sp; Data Alignment Q: How is the above struct laid out in memory?

25 Alignment Fundamentals Processors do not always access memory in byte sized chunks, instead in 2, 4, 8, even 16 or 32 byte chunks Boundaries at which data objects are stored affects the behavior of read/write operations into memory 0x00' 0x01' 0x02' 0x03' 0x04' 0x05' Programmer's'view' of'memory' 0x00' 0x02' 0x04' Processor s'view'of' memory'

26 Alignment Fundamentals Consider the task of reading 4 bytes from memory starting at 0x00 for processors that read 1, 2, 4 bytes at a time. How many memory accesses are needed in each case? 0x00' 0x01' 0x02' 0x03' 0x04' 0x05' 0x00' 0x01' 0x02' 0x03' 0x04' 0x05' 0x00' 0x02' 0x04' 0x00' 0x04' Memory' 1'byte'reads' 2'byte'reads' 4'byte'reads'

27 Alignment Fundamentals Now consider the task of reading 4 bytes from memory starting at 0x01 for processors that read 1, 2, 4 bytes at a time. How many memory accesses are needed in each case? 0x00' 0x01' 0x02' 0x03' 0x04' 0x05' Some processors just would not allow this scenario because it is extra work for the h/w and it affects the performance 0x00' 0x01' 0x02' 0x03' 0x04' 0x05' 0x00' 0x02' 0x04' 0x00' 0x04' Memory' 1'byte'reads' 2'byte'reads' 4'byte'reads' Additional'operations'needed'to'get' required'bytes'

28 Alignment requirements Data objects should start at memory addresses that are divisible by the size of the data object. short (2 byte) at address divisible by 2 0b _ 0 int (4 byte) at address divisible by 4 0b 00 double (8 byte) at address divisible by 8 0b 000

29 Alignment requirements Q: How is sp laid out in memory? Compiler takes care of zero padding struct p { char x; int y; }; struct p sp;

30 Alignment requirements Q: How is sp laid out in memory? Compiler takes care of zero padding struct p { char x; int y; }; struct p sp; sp' 0x100' x'' 0''0''0'' 0x104' y'' 0x108'

31 How big are structs? Recall C operator sizeof() which gives size in bytes (of type or variable) Q: How big is sizeof(struct p)? struct p { char x; int y; }; A. 5 bytes B. 8 bytes C. 12 bytes

32 Data' Linked Lists Node'1' Node'2' Node'3'

33 Linked Lists Node'1' Node'2' Node'3' Data' A'generic'linked'list'has:'! Multiple'data'objects'(structs)'also'called'nodes'! Each'node'linked'to'the'next'node'in'the'list'i.e.'it'knows'the' address'of'the'next'node'! Nodes'located'at'different'memory'locations'(unlike'arrays' where'they'are'contiguous)' Advantages'compared'to'arrays'! Multiple'data'members'(of'different'data'types)'can'be'stored' in'each'node'! Nodes'can'be'easily'inserted'or'removed'from'the'list'without' modifying'the'whole'list'

34 Let s look at an example of using structures, pointers, malloc(), and free() to implement a linked list of strings. typedef struct Node node; struct Node { char *value; next; }; node' value' Q:What is the data type of the variable next? A. struct Node B. Node C. node D. node * next'

35 Let s look at an example of using structures, pointers, malloc(), and free() to implement a linked list of strings. typedef struct Node node; struct Node { char *value; next; }; node' value' Q:What is the data type of the variable next? A. struct Node B. Node C. node D. node * next'

36 Adding a node to the list node *list_add(node* head, char *string) { //Step 1:Create a new node ; return new_node; value=?' } new_node' Q: How should we declare and initialize new_node? next=?' A. node *new_node=(node*) malloc(sizeof(node)); B. node new_node; C. node *new_node=head; D. node *new_node=(node *)malloc(sizeof(head));

37

38 Adding a node to the list node *list_add(node* head, char *string) { //Step 1:Create a new node ; return new_node; value=?' } new_node' Q: How should we declare and initialize new_node? next=?' A. node *new_node=(node*) malloc(sizeof(node)); B. node new_node; C. node *new_node=head; D. node *new_node=(node *)malloc(sizeof(head));

39 Q:What is wrong with step 2? node *list_add(node* head, char *string) { node *new_node=(node*) malloc(sizeof(node)); }

40 Q:What is wrong with step 2? node *list_add(node* head, char *string) { node *new_node=(node*) malloc(sizeof(node)); //Step 2: Fill in its value strcpy(new_node->value, string); return new_node; } A. Step 2 is correct. B. We should use the operator. instead of -> C. Memory is not allocated for value

41 Q:What is wrong with step 2? node *list_add(node* head, char *string) { node *new_node=(node*) malloc(sizeof(node)); //Step 2: Fill in its value strcpy(new_node->value, string); return new_node; } A. Step 2 is correct. B. We should use the operator. instead of -> C. Memory is not allocated for value

42 Draw pointer diagrams node *list_add(node* head, char *string) { node *new_node=(node*) malloc(sizeof(node)); new_node->value = (char*) malloc(strlen(string)+1); strcpy(new_node->value, string); }

43 What should Step 3 be? node *list_add(node* head, char *string){ node *new_node=(node*) malloc(sizeof(node)); new_node->value = (char*) malloc(strlen(string)+1); strcpy(new_node->value, string); //Step 3: } A. new_node->next =head; B. next=head; C. head=new_node; D. new_node->next =*head;

44 What should Step 3 be? node *list_add(node* head, char *string){ //Step 1: Create a new node node *new_node=(node*) malloc(sizeof(node)); //Step 2: Fill in its value new_node->value = (char*) malloc(strlen(string)+1); strcpy(new_node->value, string); //Step 3: Link new_node to the head of the list new_node->next =head; return new_node; } new_node' head" A. new_node->next =head; B. next=head; C. head=new_node; D. new_node->next =*head; value ' abc ' next' NULL'

45 Dangling pointers and memory leaks Dangling reference : Pointer points to a memory location that no longer exists Memory leaks (tardy free) Memory in heap that can no longer be accessed

46 Q: Which of the following functions returns a pointer to an object that may not exist in memory? int * f1(int num){ int *mem1 =(int *)malloc(num*sizeof(int)); return(mem1);} int * f2(int num){ int mem2[num]; return(mem2);} A. f1 B. f2 C. Both

47 Q: Which of the following functions returns a pointer to an object that may not exist in memory? int * f1(int num){ int *mem1 =(int *)malloc(num*sizeof(int)); return(mem1);} int * f2(int num){ int mem2[num]; return(mem2);} A. f1 B. f2 because mem2 is a local variable created in the stack C. Both

48 Which'of'the'following'is'an' example'of'a'dangling'pointer?' A. void'foo(int'bytes)''{' '''''''char'*ch'=(char'*)'malloc(bytes);' ''''''''.'.'.'.' ''''''''free'(ch);' ''''''''.'.'.'.}' ' B.''''int'*'foo(int'bytes)''{' '''''''int'i=14;' ''''''''.'.'.'.' ''''''''return'(&i);' ''''''''}' C.'''char*'foo(int'bytes)''{' '''''''char'*ch'=(char'*)'malloc(bytes);' ''''''''.'.'.'.' ''''''''return'(ch);' ''''''''}''''' D.''A'combination'of'the' above''''''

49 Which'of'the'following'is'an' example'of'a'dangling'pointer?' A. void'foo(int'bytes)''{' '''''''char'*ch'=(char'*)'malloc(bytes);' ''''''''.'.'.'.' ''''''''free'(ch);' ''''''''.'.'.'.}' ' B.''''int'*'foo(int'bytes)''{' '''''''int'i=14;' ''''''''.'.'.'.' ''''''''return'(&i);' ''''''''}' C.'''char*'foo(int'bytes)''{' '''''''char'*ch'=(char'*)'malloc(bytes);' ''''''''.'.'.'.' ''''''''return'(ch);' ''''''''}''''' D.""A"combination"of" the"above""""""

50 Memory'Leak' Is'the'following'an'example'for'a'memory'leak?' 'void'foo'(int'bytes)' '{' ''''int'*p'='(int'*)'malloc(bytes);' '''}'

51 The'C'runtime'environment' 50

52 What'does'the'executable'contain?' Instructions'or' code ' Data''' ''What'is'data?' ' '" Any'information'that'instructions'operate'on' (objects'in'memory)' 51

53 C'Runtime'Environment'' Code '(instructions'in'machine'language)' Data '(initialized'and'uninitialized'j'static' allocated)' Both'code'and'data'don t'change'in'size'' Heap '(for'dynamically'allocated'data)' Stack '(for'function'local'variables)' Heap'and'stack'change'in'size'as'the'program' executes' ' 52

54 C'Runtime'Environment' Code' Initialized'Data' Uninitialized'Data' Heap' Stack' 53

55 Data'lifetime' Lifetime:'The'interval'between'time'of' creation'and'end'of'existence'of'data' 54

56 Possible'lifetimes'of'data' 1. Execution'time'of'program' 2. Time'between'explicit'creation'and'explicit' deletion' 3. Execution'time'of'a'function'(time'between' function'call'and'function'return)' ' 55

57 Declarations'and'de[initions' Scope'and'lifetime'are'often'implicit'but' sometimes'we'have'to'use'speci[ic'keywords:' ' %static%int%a=0;%/*de[ines'lifetime*/' %extern%int%a;%%/*extends'scope'to'multiple' [iles*/' %% 56

58 Different'types'of'data' What'factor'differentiates'the'following'three' categories 'of'data'in'a'c'program:' Global'and'static'variables' Local'variables' Dynamic'variables' A. Scope' B. Lifetime' C. Representation' 57

59 Different'types'of'data' What'factor'differentiates'the'following'three' categories 'of'data'in'a'c'program:' Global'and'static'variables' Local'variables' Dynamic'variables' A. Scope' B. Lifetime' C. Representation' 58

Lecture 5: Outline. I. Multi- dimensional arrays II. Multi- level arrays III. Structures IV. Data alignment V. Linked Lists

Lecture 5: Outline. I. Multi- dimensional arrays II. Multi- level arrays III. Structures IV. Data alignment V. Linked Lists Lecture 5: Outline I. Multi- dimensional arrays II. Multi- level arrays III. Structures IV. Data alignment V. Linked Lists Multidimensional arrays: 2D Declaration int a[3][4]; /*Conceptually 2D matrix

More information

C'Programming' data'separate'from'methods/functions' Low'memory'overhead'compared'to'Java'

C'Programming' data'separate'from'methods/functions' Low'memory'overhead'compared'to'Java' ' 0 3 ' CSE 1 Lecture'3:''' ''''''''''''' C'Programm ing'' C'Programming' 'Procedural'thought'process' 'No'built'in'object'abstractions' data'separate'from'methods/functions' Low'memory'overhead'compared'to'Java'

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

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

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

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

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

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

Lecture 2: C Programm

Lecture 2: C Programm 0 3 E CS 1 Lecture 2: C Programm ing C Programming Procedural thought process No built in object abstractions data separate from methods/functions Low memory overhead compared to Java No overhead of classes

More information

How about them A s!! Go Oaktown!! CS61C - Machine Structures. Lecture 4 C Structures Memory Management Dan Garcia.

How about them A s!! Go Oaktown!! CS61C - Machine Structures. Lecture 4 C Structures Memory Management Dan Garcia. How about them A s!! Go Oaktown!! CS61C - Machine Structures Lecture 4 C Structures Memory Management 2002-09-05 Dan Garcia (www.cs.berkeley.edu/~ddgarcia) Dave Patterson (www.cs.berkeley.edu/~patterson)

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

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

Lecture 3: C Programm

Lecture 3: C Programm 0 3 E CS 1 Lecture 3: C Programm ing Reading Quiz Note the intimidating red border! 2 A variable is: A. an area in memory that is reserved at run time to hold a value of particular type B. an area in memory

More information

Operating Systems 2INC0 C course Pointer Advanced. Dr. Ir. Ion Barosan

Operating Systems 2INC0 C course Pointer Advanced. Dr. Ir. Ion Barosan Operating Systems 2INC0 C course Pointer Advanced Dr. Ir. Ion Barosan (i.barosan@tue.nl) Containt Pointers Definition and Initilization Ponter Operators Pointer Arithmetic and Array Calling Functions by

More information

(13-2) Dynamic Data Structures I H&K Chapter 13. Instructor - Andrew S. O Fallon CptS 121 (November 17, 2017) Washington State University

(13-2) Dynamic Data Structures I H&K Chapter 13. Instructor - Andrew S. O Fallon CptS 121 (November 17, 2017) Washington State University (13-2) Dynamic Data Structures I H&K Chapter 13 Instructor - Andrew S. O Fallon CptS 121 (November 17, 2017) Washington State University Dynamic Data Structures (1) Structures that expand and contract

More information

THE GOOD, BAD AND UGLY ABOUT POINTERS. Problem Solving with Computers-I

THE GOOD, BAD AND UGLY ABOUT POINTERS. Problem Solving with Computers-I THE GOOD, BAD AND UGLY ABOUT POINTERS Problem Solving with Computers-I The good: Pointers pass data around efficiently Pointers and arrays 100 104 108 112 116 ar 20 30 50 80 90 ar is like a pointer to

More information

review Pointers and arrays are virtually same C knows how to increment pointers C is an efficient language, with little protection

review Pointers and arrays are virtually same C knows how to increment pointers C is an efficient language, with little protection CS61C L05 Introduction to C (pt 3) (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 5 Introduction to C (pt 3) C Memory Management 2008-02-01 Lecturer SOE Dan Garcia Hello to Scott

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 4 Introduction to C (pt 2) 2014-09-08!!!Senior Lecturer SOE Dan Garcia!!!www.cs.berkeley.edu/~ddgarcia! C most popular! TIOBE programming

More information

Lecture 4: Outline. Arrays. I. Pointers II. III. Pointer arithmetic IV. Strings

Lecture 4: Outline. Arrays. I. Pointers II. III. Pointer arithmetic IV. Strings Lecture 4: Outline I. Pointers A. Accessing data objects using pointers B. Type casting with pointers C. Difference with Java references D. Pointer pitfalls E. Use case II. Arrays A. Representation in

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

Reference slides! Garcia, Fall 2011 UCB! CS61C L04 Introduction to C (pt 2) (1)!

Reference slides! Garcia, Fall 2011 UCB! CS61C L04 Introduction to C (pt 2) (1)! Reference slides! You ARE responsible for the material on these slides (they re just taken from the reading anyway). These were the slides that generated the fewest questions in years past (i.e., those

More information

Reference slides! C Strings! A string in C is just an array of characters.!!!char string[] = "abc";! How do you tell how long a string is?!

Reference slides! C Strings! A string in C is just an array of characters.!!!char string[] = abc;! How do you tell how long a string is?! CS61C L04 Introduction to C (pt 2) (1)! Reference slides! C Strings! You ARE responsible for the material on these slides (they re just taken from the reading anyway). These were the slides that generated

More information

Memory Management. a C view. Dr Alun Moon KF5010. Computer Science. Dr Alun Moon (Computer Science) Memory Management KF / 24

Memory Management. a C view. Dr Alun Moon KF5010. Computer Science. Dr Alun Moon (Computer Science) Memory Management KF / 24 Memory Management a C view Dr Alun Moon Computer Science KF5010 Dr Alun Moon (Computer Science) Memory Management KF5010 1 / 24 The Von Neumann model Memory Architecture One continuous address space Program

More information

Lecture 8: Pointer Arithmetic (review) Endianness Functions and pointers

Lecture 8: Pointer Arithmetic (review) Endianness Functions and pointers CSE 30: Computer Organization and Systems Programming Lecture 8: Pointer Arithmetic (review) Endianness Functions and pointers Diba Mirza University of California, San Diego 1 Q: Which of the assignment

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

HW1 due Monday by 9:30am Assignment online, submission details to come

HW1 due Monday by 9:30am Assignment online, submission details to come inst.eecs.berkeley.edu/~cs61c CS61CL : Machine Structures Lecture #2 - C Pointers and Arrays Administrivia Buggy Start Lab schedule, lab machines, HW0 due tomorrow in lab 2009-06-24 HW1 due Monday by 9:30am

More information

C: Pointers. C: Pointers. Department of Computer Science College of Engineering Boise State University. September 11, /21

C: Pointers. C: Pointers. Department of Computer Science College of Engineering Boise State University. September 11, /21 Department of Computer Science College of Engineering Boise State University September 11, 2017 1/21 Pointers A pointer is a variable that stores the address of another variable. Pointers are similar to

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #3 C Strings, Arrays, & Malloc 2007-06-27 Scott Beamer, Instructor Sun announces new supercomputer: Sun Constellation CS61C L3 C Pointers

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

CS24 Week 2 Lecture 1

CS24 Week 2 Lecture 1 CS24 Week 2 Lecture 1 Kyle Dewey Overview C Review Void pointers Allocation structs void* (Void Pointers) void* Like any other pointer, it refers to some memory address However, it has no associated type,

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

However, in C we can group related variables together into something called a struct.

However, in C we can group related variables together into something called a struct. CIT 593: Intro to Computer Systems Lecture #21 (11/27/12) Structs Unlike Java, C++, and to some extent Python, C is not traditionally considered an objectoriented language. That is, there is no concept

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

Data Representation and Storage. Some definitions (in C)

Data Representation and Storage. Some definitions (in C) Data Representation and Storage Learning Objectives Define the following terms (with respect to C): Object Declaration Definition Alias Fundamental type Derived type Use pointer arithmetic correctly Explain

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

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

Character Strings. String-copy Example

Character Strings. String-copy Example Character Strings No operations for string as a unit A string is just an array of char terminated by the null character \0 The null character makes it easy for programs to detect the end char s[] = "0123456789";

More information

6.S096: Introduction to C/C++

6.S096: Introduction to C/C++ 6.S096: Introduction to C/C++ Frank Li, Tom Lieber, Kyle Murray Lecture 4: Data Structures and Debugging! January 17, 2012 Today Memory Leaks and Valgrind Tool Structs and Unions Opaque Types Enum and

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

speller.c dictionary contains valid words, one per line 1. calls load on the dictionary file

speller.c dictionary contains valid words, one per line 1. calls load on the dictionary file mispellings speller.c 1. calls load on the dictionary file dictionary contains valid words, one per line 2. calls check on each word in the text file and prints all misspelled words 3. calls size to determine

More information

Number Review. Lecture #3 More C intro, C Strings, Arrays, & Malloc Variables. Clarification about counting down

Number Review. Lecture #3 More C intro, C Strings, Arrays, & Malloc Variables. Clarification about counting down CS61C L3 C Pointers (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #3 More C intro, C Strings, Arrays, & Malloc Albert Chae Instructor 2008-06-25 Number Review Sign and magnitude

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 Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites: C Programming Code: MBD101 Duration: 10 Hours Prerequisites: You are a computer science Professional/ graduate student You can execute Linux/UNIX commands You know how to use a text-editing tool You should

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

Run-time Environments - 3

Run-time Environments - 3 Run-time Environments - 3 Y.N. Srikant Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Principles of Compiler Design Outline of the Lecture n What is run-time

More information

COMPSCI 210 Part II Data Structure

COMPSCI 210 Part II Data Structure Agenda & Reading COMPSCI 210 Part II Data Structure Based on slides @ McGraw-Hill Agenda: Enum structs Nested structs Array of structs structs Parameters & Returning structs structs Pointers Exercises:

More information

Structures, Unions Alignment, Padding, Bit Fields Access, Initialization Compound Literals Opaque Structures Summary. Structures

Structures, Unions Alignment, Padding, Bit Fields Access, Initialization Compound Literals Opaque Structures Summary. Structures Structures Proseminar C Grundlagen und Konzepte Michael Kuhn Research Group Scientific Computing Department of Informatics Faculty of Mathematics, Informatics und Natural Sciences University of Hamburg

More information

Dynamic Memory: Alignment and Fragmentation

Dynamic Memory: Alignment and Fragmentation Dynamic Memory: Alignment and Fragmentation Learning Objectives Explain the purpose of dynamic memory Define the terms arena, heap Identify common errors involving dynamic memory Explain how dynamic memory

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

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

Pointers. Part VI. 1) Introduction. 2) Declaring Pointer Variables. 3) Using Pointers. 4) Pointer Arithmetic. 5) Pointers and Arrays

Pointers. Part VI. 1) Introduction. 2) Declaring Pointer Variables. 3) Using Pointers. 4) Pointer Arithmetic. 5) Pointers and Arrays EE105: Software Engineering II Part 6 Pointers page 1 of 19 Part VI Pointers 1) Introduction 2) Declaring Pointer Variables 3) Using Pointers 4) Pointer Arithmetic 5) Pointers and Arrays 6) Pointers and

More information

EM108 Software Development for Engineers

EM108 Software Development for Engineers EE108 Section 6 Pointers page 1 of 20 EM108 Software Development for Engineers Section 6 - Pointers 1) Introduction 2) Declaring Pointer Variables 3) Using Pointers 4) Pointer Arithmetic 5) Pointers and

More information

Chapter 2 (Dynamic variable (i.e. pointer), Static variable)

Chapter 2 (Dynamic variable (i.e. pointer), Static variable) Chapter 2 (Dynamic variable (i.e. pointer), Static variable) August_04 A2. Identify and explain the error in the program below. [4] #include int *pptr; void fun1() { int num; num=25; pptr= #

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

INITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS

INITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS INITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS Pages 792 to 800 Anna Rakitianskaia, University of Pretoria INITIALISING POINTER VARIABLES Pointer variables are declared by putting

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

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

COMP26120: Linked List in C (2018/19) Lucas Cordeiro

COMP26120: Linked List in C (2018/19) Lucas Cordeiro COMP26120: Linked List in C (2018/19) Lucas Cordeiro lucas.cordeiro@manchester.ac.uk Linked List Lucas Cordeiro (Formal Methods Group) lucas.cordeiro@manchester.ac.uk Office: 2.28 Office hours: 10-11 Tuesday,

More information

CS240: Programming in C

CS240: Programming in C CS240: Programming in C Lecture 10: Review - Structures and Memory Allocation Unions Recap: Structures Holds multiple items as a unit Treated as scalar in C: can be returned from functions, passed to functions

More information

Intro to C: Pointers and Arrays

Intro to C: Pointers and Arrays Lecture 4 Computer Science 61C Spring 2017 January 25th, 2017 Intro to C: Pointers and Arrays 1 Administrivia Teaching Assistants: Let s try that again. Lectures are recorded. Waitlist/Concurrent Enrollment

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

Dynamic Memory Allocation and Linked Lists

Dynamic Memory Allocation and Linked Lists CSE 2421: Systems I Low-Level Programming and Computer Organization Dynamic Memory Allocation and Linked Lists Presentation I Read/Study: Reek Chapter 11 & 12 Gojko Babić 02-26-2017 Functions malloc and

More information

COSC345 Software Engineering. The Heap And Dynamic Memory Allocation

COSC345 Software Engineering. The Heap And Dynamic Memory Allocation COSC345 Software Engineering The Heap And Dynamic Memory Allocation Outline Revision The programmer s view of memory Simple array-based memory allocation C memory allocation routines Virtual memory Swapping

More information

CS 61C: Great Ideas in Computer Architecture. (Brief) Review Lecture

CS 61C: Great Ideas in Computer Architecture. (Brief) Review Lecture CS 61C: Great Ideas in Computer Architecture (Brief) Review Lecture Instructor: Justin Hsia 7/16/2013 Summer 2013 Lecture #13 1 Topic List So Far (1/2) Number Representation Signed/unsigned, Floating Point

More information

CS 137 Part 5. Pointers, Arrays, Malloc, Variable Sized Arrays, Vectors. October 25th, 2017

CS 137 Part 5. Pointers, Arrays, Malloc, Variable Sized Arrays, Vectors. October 25th, 2017 CS 137 Part 5 Pointers, Arrays, Malloc, Variable Sized Arrays, Vectors October 25th, 2017 Exam Wrapper Silently answer the following questions on paper (for yourself) Do you think that the problems on

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Pointers Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) Pointers February 29, 2012 1

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

These problems are provided to you as a guide for practice. The questions cover important concepts covered in class.

These problems are provided to you as a guide for practice. The questions cover important concepts covered in class. Midterm Written Exam Practice Midterm will cover all concepts covered up to the midterm exam. Concepts of arrays, LL s, pointers (*,**,***), malloc, calloc, realloc, function pointers, Hash tables will

More information

Heap Arrays. Steven R. Bagley

Heap Arrays. Steven R. Bagley Heap Arrays 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 a[42] = 35; Variables and arrays have a type int, char, double,

More information

Cpt S 122 Data Structures. Data Structures

Cpt S 122 Data Structures. Data Structures Cpt S 122 Data Structures Data Structures Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Introduction Self Referential Structures Dynamic Memory Allocation

More information

Section Notes - Week 1 (9/17)

Section Notes - Week 1 (9/17) Section Notes - Week 1 (9/17) Why do we need to learn bits and bitwise arithmetic? Since this class is about learning about how computers work. For most of the rest of the semester, you do not have to

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

SYSC 2006 C Winter 2012

SYSC 2006 C Winter 2012 SYSC 2006 C Winter 2012 Pointers and Arrays Copyright D. Bailey, Systems and Computer Engineering, Carleton University updated Sept. 21, 2011, Oct.18, 2011,Oct. 28, 2011, Feb. 25, 2011 Memory Organization

More information

Data Representation and Storage

Data Representation and Storage Data Representation and Storage Learning Objectives Define the following terms (with respect to C): Object Declaration Definition Alias Fundamental type Derived type Use size_t, ssize_t appropriately Use

More information

Quiz 0 Review Session. October 13th, 2014

Quiz 0 Review Session. October 13th, 2014 Quiz 0 Review Session October 13th, 2014 Topics (non-exhaustive) Binary. ASCII. Algorithms. Pseudocode. Source code. Compiler. Object code. Scratch. Statements. Boolean expressions. Conditions. Loops.

More information

Code Generation. Dragon: Ch (Just part of it) Holub: Ch 6.

Code Generation. Dragon: Ch (Just part of it) Holub: Ch 6. Code Generation Dragon: Ch 7. 8. (Just part of it) Holub: Ch 6. Compilation Processes Again Choice of Intermediate Code Representation (IR) IR examples Parse tree Three address code (e.g., x := y op z)

More information

Outline. Briefly review the last class Pointers and Structs Memory allocation Linked lists

Outline. Briefly review the last class Pointers and Structs Memory allocation Linked lists Outline Briefly review the last class Pointers and Structs Memory allocation Linked lists C Structures and Memory Allocation A struct is a data structure that comprises multiple types, each known as a

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

CA341 - Comparative Programming Languages

CA341 - Comparative Programming Languages CA341 - Comparative Programming Languages David Sinclair Dynamic Data Structures Generally we do not know how much data a program will have to process. There are 2 ways to handle this: Create a fixed data

More information

PROGRAMMAZIONE I A.A. 2017/2018

PROGRAMMAZIONE I A.A. 2017/2018 PROGRAMMAZIONE I A.A. 2017/2018 LINKED LISTS LINKED LIST What are the problems with arrays? üsize is fixed üarray items are stored contiguously üinsertions and deletions at particular positions is complex

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

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Fundamental of C Programming Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Q2. Write down the C statement to calculate percentage where three subjects English, hindi, maths

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

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

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

We would like to find the value of the right-hand side of this equation. We know that

We would like to find the value of the right-hand side of this equation. We know that CS 61 Scribe Notes Computer Arithmetic II, Structured Data, Memory Layout (Th 9/13) Renzo Lucioni, Weishen Mead, Kat Zhou Unsigned Computer Arithmetic II Consider the following: We would like to find the

More information

Singly linked lists in C.

Singly linked lists in C. Singly linked lists in C http://www.cprogramming.com/tutorial/c/lesson15.html By Alex Allain Linked lists are a way to store data with structures so that the programmer can automatically create a new place

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

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

Section - Computer Science. int main() {! int a=10,b=20;! printf("a:%d B:%d\n",a,b);! a=(a+b)-(b=a);! printf("a:%d B:%d\n",a,b);!

Section - Computer Science. int main() {! int a=10,b=20;! printf(a:%d B:%d\n,a,b);! a=(a+b)-(b=a);! printf(a:%d B:%d\n,a,b);! Section - Computer Science 1. What will be the output of the following piece of code? int! int a=10,b=20;! printf("a:%d B:%d\n",a,b);! a=(a+b)-(b=a);! printf("a:%d B:%d\n",a,b);! return 1; (i) A: 10, B:

More information

CSE 333 Midterm Exam 7/27/15 Sample Solution

CSE 333 Midterm Exam 7/27/15 Sample Solution Question 1. (24 points) C programming. In this problem we want to implement a set of strings in C. A set is represented as a linked list of strings with no duplicate values. The nodes in the list are defined

More information

Character Array. C Programming. String. A sequence of characters The last character should be \0 that indicates the end of string 5 \0

Character Array. C Programming. String. A sequence of characters The last character should be \0 that indicates the end of string 5 \0 Character Array C Programming Lecture 10-1:A Array &Pointer String A sequence of characters The last character should be \0 that indicates the end of string char greeting[] = "hello"; greeting 0 1 2 3

More information

CSCI 262 Data Structures. Arrays and Pointers. Arrays. Arrays and Pointers 2/6/2018 POINTER ARITHMETIC

CSCI 262 Data Structures. Arrays and Pointers. Arrays. Arrays and Pointers 2/6/2018 POINTER ARITHMETIC CSCI 262 Data Structures 9 Dynamically Allocated Memory POINTERS AND ARRAYS 2 Arrays Arrays are just sequential chunks of memory: Arrays and Pointers Array variables are secretly pointers: x19 x18 x17

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

https://lambda.mines.edu A pointer is a value that indicates location in memory. When we change the location the pointer points to, we say we assign the pointer a value. When we look at the data the pointer

More information

Tutorial 5. Overflow. Data Types. Structures. Call stack. Stack frames. Debugging Tips. CS 136 Winter 2019 Tutorial 5 1

Tutorial 5. Overflow. Data Types. Structures. Call stack. Stack frames. Debugging Tips. CS 136 Winter 2019 Tutorial 5 1 Tutorial 5 Overflow Data Types Structures Call stack. Stack frames. Debugging Tips CS 136 Winter 2019 Tutorial 5 1 Integer Overflow: Introduction Any variable in C takes up a certain amount of memory (bits).

More information

Pointers (1A) Young Won Lim 3/5/18

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

More information

Introduction to Computer Architecture

Introduction to Computer Architecture ECE 154A Introduction to Computer Architecture Fall 2013 Dmitri istrukov Software Interface Agenda Procedures and stack Memory mapping Arrays vs. linked lists Memory management Program compilation, linking,

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

CSE351 Winter 2016, Final Examination March 16, 2016

CSE351 Winter 2016, Final Examination March 16, 2016 CSE351 Winter 2016, Final Examination March 16, 2016 Please do not turn the page until 2:30. Rules: The exam is closed-book, closed-note, etc. Please stop promptly at 4:20. There are 125 (not 100) points,

More information