Complex data structures. Cedric Saule

Size: px
Start display at page:

Download "Complex data structures. Cedric Saule"

Transcription

1 Complex data structures Cedric Saule

2 Arrays in language C In language C, arrays are contiguous spaces in memory. We make the difference between two kinds of arrays : Static arrays : their size is defined during the compilation. Dynamic arrays : their size will be known during the execution. 2

3 Arrays in memory C Contiguous memory space of exactly same type adress 1 adress 2 adress 3 Size of Type Size of Type Size of Type adress2 adress1 = ((unsigned long) adress1 (unsigned long) adress2) / sizeof(type) adress1 + n = (Type *) ((unsigned long) adress1 + n * sizeof(type)) To acces to the next case in memory : *(adress1 + n) == adress1[n] Like for functions, the array's name identifies the adress of the first cell. 3

4 Static arrays declaration Declaration of a static array type name[number of elements]; Number of elements as to be known during compilation. Numbers : 1, 5, 10, 100, Constant : global integers : #define size 10 Constant types are not considered in ANSI. 4

5 Static arrays declaration Because of the previous considerations, these expressions are equivalent : int t[10]; *t and t[0] (Because the basic pointer is the first cell, the first index is 0.) t and &t[0] *(t + i) and t[i] I neglect here the pointer size conversion, but be careful! 5

6 Operations on pointers Arrays are contiguous cells in memory, so increasing a pointer by one is pointing the next cell. But : int t[5] ; /* t is a constant pointer. */ int* p; /* p is a variable pointer. */ p = t; p++; /* This operation is legal. */ t = p; t++; /* This operation is illegal because t is a constant */ 6

7 Operations on pointers C char t[] = ''Hello''; char *p = ''Hello''; H e l l o \0 char t[] = ''Hello''; ''t'' is a true array t h \0 H e l l o \0 W char *p = ''Hello''; ''p'' contains the adress of the string beginning among other constants in memory. 7

8 Static arrays in multidimensions int t[4][3] = { { 1, 2, 3, { 4, 5, 6, { 7, 8, 9, { 10, 11, 12 ; In memory : According to the previous definition, we have : t[i][j] = *(int*)(t[i] + j) = *(int*)(*(t + i) + j) = *(int*)(*(t + ( i * 3 + j)); Number of cells in the second dimension t [0][0] [0][1] [0][2] [1][0] [1][1] [1][2] [2][0] [2][1] [2][2] [3][0] [3][1] [3][2] 8

9 Static arrays in multidimensions Another way : int t[4][3], *u[4]; u is a 4 cells array of integers pointers. [0] [1] [2] [3] u Of course, u[2][1] is a valid expression! Initialisation : int i = 0; for(i = 0; i < 4; i++) { u[i] = t[i]; Value : u[i][j] = *(int*)(*( u + i ) + j ) t [0][0] [0][1] [0][2] [1][0] [1][1] [1][2] [2][0] [2][1] [2][2] [3][0] [3][1] [3][2] 9

10 Static arrays in multidimensions initialisation : int t[4][3] = { { 1, 2, 3, { 4, 5, 6, { 7, 8, 9, { 10, 11, 12 ; int t[4][3] = { { 1, 2, 3, { 4, 5, 6, { 7, 8, 9 ; int t[4][3] = { { 1, 2, { 4, 5, { 7, 8, { 10, 11 ; int t[4][3] = { { 1, 2, 3, 4, 5, 6, 7, 8 ;

11 Dynamic arrays In dynamic arrays, the number of cells is known during the execution. It is impossible to use the basic declaration of arrays since the number of cells and is ignored and so, the memory occupancy. But arrays are also pointers, so we can use this definition! 11

12 Dynamic arrays We reserve memory and store the adress in a pointer. For multidimension, we do the same! But the memory will contain adresses int size1 = 4, size2 = 3, i = 0; float** t; t = malloc(size1 * sizeof(float*)); for( i = 0; i < size1; i++ ) { t[i] = malloc(size2 * sizeof(float)); for(i = 0; i < size1; i++) { free(t); free(t[i]); Free the memory of the array of float* Reservation of size1 cells of memory with the size of a float*. Reservation of size2 cells of memory with the size of a float. Each pointer of size1 cells points to the adress of a pointer of size2 cells. Free the memory of each array of float 12

13 Dynamic arrays Arrays creation Declaration of float** t 13

14 Dynamic arrays Arrays creation t Memory allocation of size1 cells of size float* 14

15 Dynamic arrays Arrays creation t float float float t[0] Memory allocation of size2 cells of float. Allocation to the cell0 of the previous array. 15

16 Dynamic arrays Arrays creation t float float float float float float float float float t[0] t[1] t[2] float float float t[3] We repeat the operation for each cell of the array of float*. 16

17 Dynamic arrays Arrays destruction t The memory of each array of size2 cells is freed. Be careful, the pointers point now on nothing! 17

18 Dynamic arrays Arrays destruction t The size1 memory spaces are freed. t points on nothing. 18

19 Dynamic arrays Arrays creation t float float float If we free t before each of the size1 array of float. We loose acces to their adress. float float float float float float Anonymous reserved memory float float float 19

20 Dynamic arrays We can define non homogenous arrays. t float float float t[0] float float float float float float float float float t[1] t[2] float float float t[3] We have just to keep in memory the number of cells for each. 20

21 Arrays and functions To use an array as a parameter, the pointer on the first adress is enough. Better is float sumarray(float* myarray, int nb1 ) { int i; float sum = 0; for(i = 0; i < nb1; i++) { sum += myarray[i]; return sum; float sumarray(const float* myarray, int nb1 ) { int i; float sum = 0; for(i = 0; i < nb1; i++) { sum += myarray[i]; return sum; We cannot modify the arrays by ''mistake'' 21

22 Arrays and functions We can also write : float sumarray(const float myarray[], int nb1 ) { int i; float sum = 0; for(i = 0; i < nb1; i++) { sum += myarray[i]; return sum; Or, equivalently : float sumarray(const float myarray[15], int nb1 ) { int i; float sum = 0; for(i = 0; i < nb1; i++) { sum += myarray[i]; return sum; The compiler does not check the bounds! 22

23 Arrays and functions In two dimensions (or more...) : float sumarray(const float myarray[][nb2], int nb1 ) { int i, j; float sum = 0; for(i = 0; i < nb1; i++) { for(j = 0; j < nb2; j++) { sum += myarray[i][j]; return sum; Or : t Because we have to knoe the dimensions sizes after the first one. Remember : t[i][j] = *(float*)(*(t + ( i * 3 + j)) [0][0] [0][1] [0][2] [1][0] [1][1] [1][2] [2][0] [2][1] [2][2] [3][0] [3][1] [3][2] float sumarray(const * myarray, int nb1, int nb2 ) { int i, j; float sum = 0; for(i = 0; i < nb1; i++) { for(j = 0; j < nb2; j++) { sum += *(float*)(*(myarray + i * nb2 + j)); return sum; 23

24 Convenient functions calloc : initialise the value to ''0'' or ''NULL'' : int* myarray = calloc(nb, sizeof(int)); realloc : resize dynamically the memory space. myarray = realloc(myarray, (nb+1) * sizeof(int)); These two functions returns NULL in case of mistake. We have to be careful (temporary variables, test of right allocation...) 24

25 Another way to enumerate We want to use ''strings'' as identifyers. Exemples : Days of the week. Months Each name is associated with an integer : enum day {monday, tuesday, wednesday, thursday, friday, satursday, sunday; Monday is equal to 0, tuesday to 1... enum somemonth {january = 1, february, march, april, september = 9, october, november;

26 Quick preview How to make a copy of an array in fonction? How to create new data types? What about trees? Graphs? Lists? Stacks? We can define structures which contain several types and recursive definitions. 26

Structures and Pointers

Structures and Pointers Structures and Pointers Comp-206 : Introduction to Software Systems Lecture 11 Alexandre Denault Computer Science McGill University Fall 2006 Note on Assignment 1 Please note that handin does not allow

More information

Example. Section: PS 709 Examples of Calculations of Reduced Hours of Work Last Revised: February 2017 Last Reviewed: February 2017 Next Review:

Example. Section: PS 709 Examples of Calculations of Reduced Hours of Work Last Revised: February 2017 Last Reviewed: February 2017 Next Review: Following are three examples of calculations for MCP employees (undefined hours of work) and three examples for MCP office employees. Examples use the data from the table below. For your calculations use

More information

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso Why C? Test on 21 Android Devices with 32-bits and 64-bits processors and different versions

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

Announcements. assign0 due tonight. Labs start this week. No late submissions. Very helpful for assign1

Announcements. assign0 due tonight. Labs start this week. No late submissions. Very helpful for assign1 Announcements assign due tonight No late submissions Labs start this week Very helpful for assign1 Goals for Today Pointer operators Allocating memory in the heap malloc and free Arrays and pointer arithmetic

More information

Pointers. Cedric Saule

Pointers. Cedric Saule Pointers Cedric Saule cedric.saule@uni-bielefeld.de Variables and memory Each variable needs to be stored in memory. Memory is made of plenty cells of 8 bits (1 Byte) A ''char'' is stored in 1 cell, a

More information

CS349/SE382 A1 C Programming Tutorial

CS349/SE382 A1 C Programming Tutorial CS349/SE382 A1 C Programming Tutorial Erin Lester January 2005 Outline Comments Variable Declarations Objects Dynamic Memory Boolean Type structs, enums and unions Other Differences The Event Loop Comments

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

Arrays and Pointers (part 1)

Arrays and Pointers (part 1) Arrays and Pointers (part 1) CSE 2031 Fall 2010 17 October 2010 1 Arrays Grouping of data of the same type. Loops commonly used for manipulation. Programmers set array sizes explicitly. 2 1 Arrays: Example

More information

Arrays and Pointers (part 1)

Arrays and Pointers (part 1) Arrays and Pointers (part 1) CSE 2031 Fall 2012 Arrays Grouping of data of the same type. Loops commonly used for manipulation. Programmers set array sizes explicitly. Arrays: Example Syntax type name[size];

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

typedef int Array[10]; String name; Array ages;

typedef int Array[10]; String name; Array ages; Morteza Noferesti The C language provides a facility called typedef for creating synonyms for previously defined data type names. For example, the declaration: typedef int Length; Length a, b, len ; Length

More information

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

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

More information

High Performance Computing MPI and C-Language Seminars 2009

High Performance Computing MPI and C-Language Seminars 2009 High Performance Computing - Seminar Plan Welcome to the High Performance Computing seminars for 2009. Aims: Introduce the C Programming Language. Basic coverage of C and programming techniques needed

More information

Dynamic Memory Allocation

Dynamic Memory Allocation Dynamic Memory Allocation The process of allocating memory at run time is known as dynamic memory allocation. C does not Inherently have this facility, there are four library routines known as memory management

More information

Functions. Cedric Saule

Functions. Cedric Saule Cedric Saule cedric.saule@uni-bielefeld.de or procedures? In algorithmic (and some programming languages), we use two kinds of unconditional branchings : Procedures : execute computations and do not return

More information

Arrays in C. Data and File Structures Laboratory. DFS Lab (ISI) Arrays in C 1 / 1

Arrays in C. Data and File Structures Laboratory.   DFS Lab (ISI) Arrays in C 1 / 1 Arrays in C Data and File Structures Laboratory http://wwwisicalacin/~dfslab/2017/indexhtml DFS Lab (ISI) Arrays in C 1 / 1 What is an array? A A[0] A[1] A[2] A[n 1] Syntax Sequence of n contiguous memory

More information

Dynamic Data Structures. CSCI 112: Programming in C

Dynamic Data Structures. CSCI 112: Programming in C Dynamic Data Structures CSCI 112: Programming in C 1 It s all about flexibility In the programs we ve made so far, the compiler knows at compile time exactly how much memory to allocate for each variable

More information

Institute For Arts & Digital Sciences SHORT COURSES

Institute For Arts & Digital Sciences SHORT COURSES Institute For Arts & Digital Sciences SHORT COURSES SCHEDULES AND FEES 2017 SHORT COURSES - GRAPHIC DESIGN Adobe Photoshop Basic 07 February 28 February Tuesdays 14:30-17:30 Adobe Photoshop Basic 07 February

More information

C-types: basic & constructed. C basic types: int, char, float, C constructed types: pointer, array, struct

C-types: basic & constructed. C basic types: int, char, float, C constructed types: pointer, array, struct C-types: basic & constructed C basic types: int, char, float, C constructed types: pointer, array, struct Memory Management Code Global variables in file (module) Local static variables in functions Dynamic

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

Arrays and Pointers (part 2) Be extra careful with pointers!

Arrays and Pointers (part 2) Be extra careful with pointers! Arrays and Pointers (part 2) EECS 2031 22 October 2017 1 Be extra careful with pointers! Common errors: l Overruns and underruns Occurs when you reference a memory beyond what you allocated. l Uninitialized

More information

Arrays. What if you have a 1000 line file? Arrays

Arrays. What if you have a 1000 line file? Arrays Arrays Chapter 8 page 477 11/8/06 CS150 Introduction to Computer Science 1 1 What if you have a 1000 line file? Read in the following file and print out a population graph as shown below. The maximum value

More information

CS 161 Exam II Winter 2018 FORM 1

CS 161 Exam II Winter 2018 FORM 1 CS 161 Exam II Winter 2018 FORM 1 Please put your name and form number on the scantron. True (A)/False (B) (28 pts, 2 pts each) 1. The following array declaration is legal double scores[]={0.1,0.2,0.3;

More information

Arrays and Pointers (part 2) Be extra careful with pointers!

Arrays and Pointers (part 2) Be extra careful with pointers! Arrays and Pointers (part 2) CSE 2031 Fall 2011 23 October 2011 1 Be extra careful with pointers! Common errors: Overruns and underruns Occurs when you reference a memory beyond what you allocated. Uninitialized

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

Arrays and Pointers. CSE 2031 Fall November 11, 2013

Arrays and Pointers. CSE 2031 Fall November 11, 2013 Arrays and Pointers CSE 2031 Fall 2013 November 11, 2013 1 Arrays l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. 2 Arrays: Example

More information

Note: The enumerations range from 0 to (number_of_elements_in_enumeration 1).

Note: The enumerations range from 0 to (number_of_elements_in_enumeration 1). C8-1 Algorithm 1. Use a subtype to represent the numbers for months 2. Use an enumeration to represent the named months 3. Use an enumeration to represent the roman months 4. Get the inputs from the user

More information

Data Types. Data Types. Introduction. Data Types. Data Types. Data Types. Introduction

Data Types. Data Types. Introduction. Data Types. Data Types. Data Types. Introduction Introduction Primitive Composite Structured Abstract Introduction Introduction Data Type is a Collection of Data Objects Possible r-values for a memory cell Set of operations on those objects Descriptor

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

Calendar Excel Template User Guide

Calendar Excel Template User Guide Calendar Excel Template User Guide Excel-based simple Calendar Template Version 3 This Excel-based template provides a calendar template for each month of a year. It also incorporates an hourly schedule

More information

Exercises Software Development I. 02 Algorithm Testing & Language Description Manual inspection, test plan, grammar, metasyntax notations (BNF, EBNF)

Exercises Software Development I. 02 Algorithm Testing & Language Description Manual inspection, test plan, grammar, metasyntax notations (BNF, EBNF) Exercises Software Development I 02 Algorithm Testing & Language Description Manual inspection, test plan, grammar, metasyntax notations (BNF, EBNF) October 15th, 2014 Software Development I Winter term

More information

Object-Oriented Principles and Practice / C++

Object-Oriented Principles and Practice / C++ Object-Oriented Principles and Practice / C++ Alice E. Fischer April 20, 2015 OOPP / C++ Lecture 3... 1/23 New Things in C++ Object vs. Pointer to Object Optional Parameters Enumerations Using an enum

More information

Arrays. C Types. Derived. Function Array Pointer Structure Union Enumerated. EE 1910 Winter 2017/18

Arrays. C Types. Derived. Function Array Pointer Structure Union Enumerated. EE 1910 Winter 2017/18 C Types Derived Function Array Pointer Structure Union Enumerated 2 tj Arrays Student 0 Student 1 Student 2 Student 3 Student 4 Student 0 Student 1 Student 2 Student 3 Student 4 Student[0] Student[1] Student[2]

More information

Scheduling. Scheduling Tasks At Creation Time CHAPTER

Scheduling. Scheduling Tasks At Creation Time CHAPTER CHAPTER 13 This chapter explains the scheduling choices available when creating tasks and when scheduling tasks that have already been created. Tasks At Creation Time The tasks that have the scheduling

More information

CSE 305 Programming Languages Spring, 2010 Homework 5 Maximum Points: 24 Due 10:30 AM, Friday, February 26, 2010

CSE 305 Programming Languages Spring, 2010 Homework 5 Maximum Points: 24 Due 10:30 AM, Friday, February 26, 2010 CSE 305 Programming Languages Spring, 2010 Homework 5 Maximum Points: 24 Due 10:30 AM, Friday, February 26, 2010 Professor Shapiro February 12, 2010 Write the answers in a file named hw5.txt. Put your

More information

Principles of C and Memory Management

Principles of C and Memory Management COMP281 Lecture 8 Principles of C and Memory Management Dr Lei Shi Last Lecture Pointer Basics Previous Lectures Arrays, Arithmetic, Functions Last Lecture Pointer Basics Previous Lectures Arrays, Arithmetic,

More information

Introduction to C. Sami Ilvonen Petri Nikunen. Oct 6 8, CSC IT Center for Science Ltd, Espoo. int **b1, **b2;

Introduction to C. Sami Ilvonen Petri Nikunen. Oct 6 8, CSC IT Center for Science Ltd, Espoo. int **b1, **b2; Sami Ilvonen Petri Nikunen Introduction to C Oct 6 8, 2015 @ CSC IT Center for Science Ltd, Espoo int **b1, **b2; /* Initialise metadata */ board_1->height = height; board_1->width = width; board_2->height

More information

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

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

More information

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2. Class #10: Understanding Primitives and Assignments Software Design I (CS 120): M. Allen, 19 Sep. 18 Java Arithmetic } Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = 2 + 5 / 2; 3.

More information

Arrays and Pointers. Arrays. Arrays: Example. Arrays: Definition and Access. Arrays Stored in Memory. Initialization. EECS 2031 Fall 2014.

Arrays and Pointers. Arrays. Arrays: Example. Arrays: Definition and Access. Arrays Stored in Memory. Initialization. EECS 2031 Fall 2014. Arrays Arrays and Pointers l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. EECS 2031 Fall 2014 November 11, 2013 1 2 Arrays: Example

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

C Programming Basics II

C Programming Basics II C Programming Basics II Xianyi Zeng xzeng@utep.edu Department of Mathematical Sciences The University of Texas at El Paso. September 20, 2016. Pointers and Passing by Address Upon declaring a variable,

More information

DCS/100 Procedural Programming

DCS/100 Procedural Programming DCS/100 Procedural Programming Week 9: References, the Heap and the Stack Last Week: Learning Outcomes From last week you should be able to: write programs that are split into methods write programs that

More information

COMP-202: Foundations of Programming. Lecture 4: Flow Control Loops Sandeep Manjanna, Summer 2015

COMP-202: Foundations of Programming. Lecture 4: Flow Control Loops Sandeep Manjanna, Summer 2015 COMP-202: Foundations of Programming Lecture 4: Flow Control Loops Sandeep Manjanna, Summer 2015 Announcements Check the calendar on the course webpage regularly for updates on tutorials and office hours.

More information

Pointers and Terminal Control

Pointers and Terminal Control Division of Mathematics and Computer Science Maryville College Outline 1 2 3 Outline 1 2 3 A Primer on Computer Memory Memory is a large list. Typically, each BYTE of memory has an address. Memory can

More information

High Performance Computing

High Performance Computing High Performance Computing MPI and C-Language Seminars 2009 Photo Credit: NOAA (IBM Hardware) High Performance Computing - Seminar Plan Seminar Plan for Weeks 1-5 Week 1 - Introduction, Data Types, Control

More information

Arrays. Arrays (8.1) Arrays. One variable that can store a group of values of the same type. Storing a number of related values.

Arrays. Arrays (8.1) Arrays. One variable that can store a group of values of the same type. Storing a number of related values. Arrays Chapter 8 page 471 Arrays (8.1) One variable that can store a group of values of the same type Storing a number of related values o all grades for one student o all temperatures for one month o

More information

22c:111 Programming Language Concepts. Fall Types I

22c:111 Programming Language Concepts. Fall Types I 22c:111 Programming Language Concepts Fall 2008 Types I Copyright 2007-08, The McGraw-Hill Company and Cesare Tinelli. These notes were originally developed by Allen Tucker, Robert Noonan and modified

More information

A Beginner s Guide to Programming Logic, Introductory. Chapter 6 Arrays

A Beginner s Guide to Programming Logic, Introductory. Chapter 6 Arrays A Beginner s Guide to Programming Logic, Introductory Chapter 6 Arrays Objectives In this chapter, you will learn about: Arrays and how they occupy computer memory Manipulating an array to replace nested

More information

Memory Allocation. General Questions

Memory Allocation. General Questions General Questions 1 Memory Allocation 1. Which header file should be included to use functions like malloc() and calloc()? A. memory.h B. stdlib.h C. string.h D. dos.h 2. What function should be used to

More information

Objectives. Describe ways to create constants const readonly enum

Objectives. Describe ways to create constants const readonly enum Constants Objectives Describe ways to create constants const readonly enum 2 Motivation Idea of constant is useful makes programs more readable allows more compile time error checking 3 Const Keyword const

More information

[0569] p 0318 garbage

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

More information

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

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary GATE- 2016-17 Postal Correspondence 1 C-Programming Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts, Analysis

More information

Warmup January 9th, What is the value of the following C expression? 8*9 % 10/ 2

Warmup January 9th, What is the value of the following C expression? 8*9 % 10/ 2 Warmup January 9th, 2018 What is the value of the following C expression? 8*9 % 10/ 2 Warmup January 11th, 2018 What is the value of the following C expression? ( -42 3!= 3) && ( -3 < -2 < -1) Warmup January

More information

ControlLogix/Studio 5000 Logix Designer Course Code Course Title Duration CCP143 Studio 5000 Logix Designer Level 3: Project Development 4.

ControlLogix/Studio 5000 Logix Designer Course Code Course Title Duration CCP143 Studio 5000 Logix Designer Level 3: Project Development 4. NORTH CONTROLLERS ControlLogix/Studio 5000 Logix Designer CCP143 Studio 5000 Logix Designer Level 3: Project Development 4.0 Tuesday, March 7, 2017 Friday, March 10, 2017 CCP146 Studio 5000 Logix Designer

More information

Incoming Exam. CS 201 Introduction to Pointers. What is a Pointer? Pointers and Addresses. High Speed Memory (RAM) Size of Variable Types.

Incoming Exam. CS 201 Introduction to Pointers. What is a Pointer? Pointers and Addresses. High Speed Memory (RAM) Size of Variable Types. Incoming Exam CS 0 Introduction to Pointers Debzani Deb Next Monday (th March), we will have Exam # Closed book Sit with an empty space in either side of you Calculators that have text-allowing is not

More information

Why arrays? To group distinct variables of the same type under a single name.

Why arrays? To group distinct variables of the same type under a single name. Lesson #7 Arrays Why arrays? To group distinct variables of the same type under a single name. Suppose you need 100 temperatures from 100 different weather stations: A simple (but time consuming) solution

More information

Arrays, Pointers and Memory Management

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

More information

Lecture 5: Multidimensional Arrays. Wednesday, 11 February 2009

Lecture 5: Multidimensional Arrays. Wednesday, 11 February 2009 Lecture 5: Multidimensional Arrays CS209 : Algorithms and Scientific Computing Wednesday, 11 February 2009 CS209 Lecture 5: Multidimensional Arrays 1/20 In today lecture... 1 Let s recall... 2 Multidimensional

More information

C Pointers. Abdelghani Bellaachia, CSCI 1121 Page: 1

C Pointers. Abdelghani Bellaachia, CSCI 1121 Page: 1 C Pointers 1. Objective... 2 2. Introduction... 2 3. Pointer Variable Declarations and Initialization... 3 4. Reference operator (&) and Dereference operator (*) 6 5. Relation between Arrays and Pointers...

More information

1 of 8 10/10/2018, 12:52 PM RM-01, 10/10/2018. * Required. 1. Agency Name: * 2. Fiscal year reported: * 3. Date: *

1 of 8 10/10/2018, 12:52 PM RM-01, 10/10/2018. * Required. 1. Agency Name: * 2. Fiscal year reported: * 3. Date: * 1 of 8 10/10/2018, 12:52 PM RM-01, 10/10/2018 * Required 1. Agency Name: * 2. Fiscal year reported: * 3. Date: * Example: December 15, 2012 4. Name of agency staff member completing this report: * The

More information

CS201- Introduction to Programming Current Quizzes

CS201- Introduction to Programming Current Quizzes CS201- Introduction to Programming Current Quizzes Q.1 char name [] = Hello World ; In the above statement, a memory of characters will be allocated 13 11 12 (Ans) Q.2 A function is a block of statements

More information

INFORMATION TECHNOLOGY SPREADSHEETS. Part 1

INFORMATION TECHNOLOGY SPREADSHEETS. Part 1 INFORMATION TECHNOLOGY SPREADSHEETS Part 1 Page: 1 Created by John Martin Exercise Built-In Lists 1. Start Excel Spreadsheet 2. In cell B1 enter Mon 3. In cell C1 enter Tue 4. Select cell C1 5. At the

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 10 Structures, Unions, Bit Manipulations and Enumerations Department of Computer Engineering

More information

Chapter 7. Pointers. Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.

Chapter 7. Pointers. Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 7 Pointers Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2 Chapter 7 - Pointers 7.1 Introduction 7.2 Pointer Variable Definitions and Initialization

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

CHAPTER 5 FLOW OF CONTROL

CHAPTER 5 FLOW OF CONTROL CHAPTER 5 FLOW OF CONTROL PROGRAMMING CONSTRUCTS - In a program, statements may be executed sequentially, selectively or iteratively. - Every programming language provides constructs to support sequence,

More information

CSC2/454 Programming Languages Design and Implementation Records and Arrays

CSC2/454 Programming Languages Design and Implementation Records and Arrays CSC2/454 Programming Languages Design and Implementation Records and Arrays Sreepathi Pai November 6, 2017 URCS Outline Scalar and Composite Types Arrays Records and Variants Outline Scalar and Composite

More information

CSCI312 Principles of Programming Languages!

CSCI312 Principles of Programming Languages! CSCI312 Principles of Programming Languages! Chapter 5 Types Xu Liu! ! 5.1!Type Errors! 5.2!Static and Dynamic Typing! 5.3!Basic Types! 5.4!NonBasic Types! 5.5!Recursive Data Types! 5.6!Functions as Types!

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

CSE2301. Dynamic memory Allocation. malloc() Dynamic Memory Allocation and Structs

CSE2301. Dynamic memory Allocation. malloc() Dynamic Memory Allocation and Structs Warning: These notes are not complete, it is a Skelton that will be modified/add-to in the class. If you want to us them for studying, either attend the class or get the completed notes from someone who

More information

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam Multimedia Programming 2004 Lecture 2 Erwin M. Bakker Joachim Rijsdam Recap Learning C++ by example No groups: everybody should experience developing and programming in C++! Assignments will determine

More information

Lecture 3. The syntax for accessing a struct member is

Lecture 3. The syntax for accessing a struct member is Lecture 3 Structures: Structures are typically used to group several data items together to form a single entity. It is a collection of variables used to group variables into a single record. Thus a structure

More information

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

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

Introduction to C. Zhiyuan Teo. Cornell CS 4411, August 26, Geared toward programmers

Introduction to C. Zhiyuan Teo. Cornell CS 4411, August 26, Geared toward programmers Introduction to C Geared toward programmers Zhiyuan Teo Slide heritage: Alin Dobra Niranjan Nagarajan Owen Arden Robert Escriva Cornell CS 4411, August 26, 2011 1 Administrative Information 2 Why C? 3

More information

Laboratory 10 POINTERS I. FUNDAMENTALS

Laboratory 10 POINTERS I. FUNDAMENTALS PROGRAMMING LANGUAGES Laboratory 10 POINTERS I. FUNDAMENTALS As already known, a program together with its data is stored in the computer s memory. The RAM memory is a random access memory (RAM) which,

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

Outline. Review of Last Week II. Review of Last Week. Computer Memory. Review Variables and Memory. February 7, Data Types

Outline. Review of Last Week II. Review of Last Week. Computer Memory. Review Variables and Memory. February 7, Data Types Data Types Declarations and Initializations Larry Caretto Computer Science 16 Computing in Engineering and Science February 7, 25 Outline Review last week Meaning of data types Integer data types have

More information

Chapter 4: Arrays, Pointers and Strings

Chapter 4: Arrays, Pointers and Strings Chapter 4: Arrays, Pointers and Strings C Programming Language Šimon Řeřucha v3.2 March 1, 2016 A C program is like a fast dance on a newly waxed dance floor by people carrying razors. Waldi Ravens. Advanced

More information

just a ((somewhat) safer) dialect.

just a ((somewhat) safer) dialect. Intro_to_C Page 1 Intro to C Tuesday, September 07, 2004 5:30 PM C was developed specifically for writing operating systems Low level of abstraction. "Just above machine language." Direct access to the

More information

Cambridge English Dates and Fees for 2018

Cambridge English Dates and Fees for 2018 Cambridge English Dates and Fees for 2018 Cambridge English: Key (KET) KET 10,900.00 10,500.00 10,300.00 Saturday, 17 March Thursday, 01 February 9 March 18 March Saturday, 12 May Friday, 6 April 4 May

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

AIMMS Function Reference - Date Time Related Identifiers

AIMMS Function Reference - Date Time Related Identifiers AIMMS Function Reference - Date Time Related Identifiers This file contains only one chapter of the book. For a free download of the complete book in pdf format, please visit www.aimms.com Aimms 3.13 Date-Time

More information

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Allocating Space

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Allocating Space CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Allocating Space Dynamic Memory Allocation All variables, arrays, structures and unions that we worked with so far are statically allocated,

More information

TYPES, VALUES AND DECLARATIONS

TYPES, VALUES AND DECLARATIONS COSC 2P90 TYPES, VALUES AND DECLARATIONS (c) S. Thompson, M. Winters 1 Names, References, Values & Types data items have a value and a type type determines set of operations variables Have an identifier

More information

Chapter 6 Reacting to Player Input

Chapter 6 Reacting to Player Input Chapter 6 Reacting to Player Input 6.1 Introduction In this chapter, we will show you how your game program can react to mouse clicks and button presses. In order to do this, we need a instruction called

More information

September 2015 Calendar This Excel calendar is blank & designed for easy use as a planner. Courtesy of WinCalendar.com

September 2015 Calendar This Excel calendar is blank & designed for easy use as a planner. Courtesy of WinCalendar.com September 2015 Calendar This Excel calendar is blank & designed for easy use as a planner. Courtesy of WinCalendar.com August ~ September 2015 ~ Sunday Monday Tuesday Wednesday Thursday Friday 1 2 3 4

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

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

Dynamic Allocation of Memory

Dynamic Allocation of Memory Dynamic Allocation of Memory Lecture 5 Section 9.8 Robb T. Koether Hampden-Sydney College Wed, Jan 24, 2018 Robb T. Koether (Hampden-Sydney College) Dynamic Allocation of Memory Wed, Jan 24, 2018 1 / 34

More information

Floating-point lab deadline moved until Wednesday Today: characters, strings, scanf Characters, strings, scanf questions clicker questions

Floating-point lab deadline moved until Wednesday Today: characters, strings, scanf Characters, strings, scanf questions clicker questions Announcements Thursday Extras: CS Commons on Thursdays @ 4:00 pm but none next week No office hours next week Monday or Tuesday Reflections: when to use if/switch statements for/while statements Floating-point

More information

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II:

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II: FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each): 1. The declaration below declares three pointer variables of type pointer to double that is

More information

CP2 Revision. theme: dynamic datatypes & data structures

CP2 Revision. theme: dynamic datatypes & data structures CP2 Revision theme: dynamic datatypes & data structures structs can hold any combination of datatypes handled as single entity struct { }; ;

More information

Basic Device Management

Basic Device Management This chapter contains the following sections: About, page 1 Licensing Requirements for, page 2 Default Settings for Basic Device Parameters, page 3 Changing the Device Hostname, page 3 Configuring the

More information

C for Engineers and Scientists: An Interpretive Approach. Chapter 10: Arrays

C for Engineers and Scientists: An Interpretive Approach. Chapter 10: Arrays Chapter 10: Arrays 10.1 Declaration of Arrays 10.2 How arrays are stored in memory One dimensional (1D) array type name[expr]; type is a data type, e.g. int, char, float name is a valid identifier (cannot

More information

Aerospace Software Engineering

Aerospace Software Engineering 16.35 Aerospace Software Engineering Ada 95: subtypes, enumeration types, functions, packages, exception handling September 30/2002 Prof. I. K. Lundqvist kristina@mit.edu 16.35 September 30/2002 Prof.

More information

YEAR 8 STUDENT ASSESSMENT PLANNER SEMESTER 1, 2018 TERM 1

YEAR 8 STUDENT ASSESSMENT PLANNER SEMESTER 1, 2018 TERM 1 YEAR 8 STUDENT ASSESSMENT PLANNER SEMESTER 1, 2018 TERM 1 Term 1 - Due Dates 22 26 January 29 January 2 February 5 9 February 12 16 February 19 23 February 26 February 2 March 5 9 March 12 16 March 19

More information