Pointers and Arrays. More Pointer Examples. Pointers CS 217

Size: px
Start display at page:

Download "Pointers and Arrays. More Pointer Examples. Pointers CS 217"

Transcription

1 Pointers nd Arrs CS Pointers More Pointer Emples Wht is pointer A vrile whose vlue is the ddress of nother vrile p is pointer to vrile v Opertions &: ddress of (reference) *: indirection (dereference) p: v: References (e.g., *p) re vriles int,, *p, *p; Declrtion mimics use int *p; p is the ddress of n int (dereference p is n integer) int v; p = &v; p stores the ddress of v 0 4

2 More Pointer Emples References (e.g., *p) re vriles int,, *p, *p; More Pointer Emples References (e.g., *p) re vriles int,, *p, *p; p = &; /* p is the ddress of */ p p p p 5 6 More Pointer Emples References (e.g., *p) re vriles int,, *p, *p; p = &; /* p is the ddress of */ More Pointer Emples References (e.g., *p) re vriles int,, *p, *p; p = &; /* p is the ddress of */ *p = 0; /* sets to 0 */ p p p p 8

3 More Pointer Emples References (e.g., *p) re vriles int,, *p, *p; p = &; /* p is the ddress of */ *p = 0; /* sets to 0 */ More Pointer Emples References (e.g., *p) re vriles int,, *p, *p; p = &; /* p is the ddress of */ *p = 0; /* sets to 0 */ p = p; /* p lso points to */ 0 p 0 p p 9 p 10 More Pointer Emples More Pointer Emples References (e.g., *p) re vriles int,, *p, *p; References (e.g., *p) re vriles int,, *p, *p; p = &; /* p is the ddress of */ *p = 0; /* sets to 0 */ p = p; /* p lso points to */ p = &; /* p is the ddress of */ *p = 0; /* sets to 0 */ p = p; /* p lso points to */ *p += 1; /* increments to 1 */ 0 0 p p 11 p p 12

4 More Pointer Emples References (e.g., *p) re vriles int,, *p, *p; p = &; /* p is the ddress of */ *p = 0; /* sets to 0 */ p = p; /* p lso points to */ *p += 1; /* increments to 1 */ More Pointer Emples References (e.g., *p) re vriles int,, *p, *p; p = &; /* p is the ddress of */ *p = 0; /* sets to 0 */ p = p; /* p lso points to */ *p += 1; /* increments to 1 */ = (*p)++; /* sets to 1, to 2 */ 1 1 p p 1 p p 14 More Pointer Emples References (e.g., *p) re vriles int,, *p, *p; p = &; /* p is the ddress of */ *p = 0; /* sets to 0 */ p = p; /* p lso points to */ *p += 1; /* increments to 1 */ = (*p)++; /* sets to 1, to 2 */ More Pointer Emples References (e.g., *p) re vriles int,, *p, *p; p = &; /* p is the ddress of */ *p = 0; /* sets to 0 */ p = p; /* p lso points to */ *p += 1; /* increments to 1 */ = (*p)++; /* sets to 1, to 2 */ p p 15 p p 16

5 Opertor Precedents Unr opertors ssocite right to left = *&; /* sme s = *(&) */ Unr opertors ind more tightl thn inr ones = *p + 1; /* sme s = (*p) + 1; */ More emples = *p++; /* sme s = *p; p++; */ = *(p++); /* sme s ove */ = *++p; /* sme s p++; = *p; */ = ++*p; /* sme s = (*p) + 1; */ When in dout, lierll use prentheses Argument Pssing C functions pss rguments vlue void swp(int, int ) t = ; = ; = t; int =, = ; swp(, ); printf( %d %d\n,,); 1 18 Argument Pssing C functions pss rguments vlue Argument Pssing C functions pss rguments vlue void swp(int, int ) t = ; = ; = t; int =, = ; swp(, ); printf( %d %d\n,,); void swp(int, int ) t = ; = ; = t; int =, = ; swp(, ); printf( %d %d\n,,); 19 20

6 Argument Pssing C functions pss rguments vlue To pss rguments reference, use pointers void swp(int, int ) t = ; = ; = t; int =, = ; swp(, ); printf( %d %d\n,,); void swp(int *, int t = *; * = *; * = t; int =, = ; swp(&, &); printf( %d %d\n,,); *) Argument Pssing C functions pss rguments vlue To pss rguments reference, use pointers void swp(int, int ) t = ; = ; = t; int =, = ; swp(, ); printf( %d %d\n,,); void swp(int *, int t = *; * = *; * = t; int =, = ; swp(&, &); printf( %d %d\n,,); *) Argument Pssing C functions pss rguments vlue To pss rguments reference, use pointers void swp(int, int ) t = ; = ; = t; int =, = ; swp(, ); printf( %d %d\n,,); void swp(int *, int t = *; * = *; * = t; int =, = ; swp(&, &); printf( %d %d\n,,); *) Formtted Input: scnf Emple doule v; scnf( %lf, &v ); int d, month, er; scnf( %d/%d/%d, &month, &d, &er); 2 24

7 Pointers nd Arrs Pointers cn wlk long rrs int [10], *p, ; p = &[0]; /* p gets the ddress of [0] */ = *p; /* gets [0] */ = *(p+1); /* gets [1] */ p = p + 1; /* p points to [1] */ p++; /* p points to [2] */ p Pointers nd Arrs Pointers cn wlk long rrs int [10], *p, ; p = &[0]; /* p gets the ddress of [0] */ = *p; /* gets [0] */ = *(p+1); /* gets [1] */ p = p + 1; /* p points to [1] */ p++; /* p points to [2] */ Pointers nd Arrs Pointers cn wlk long rrs int [10], *p, ; p = &[0]; /* p gets the ddress of [0] */ = *p; /* gets [0] */ = *(p+1); /* gets [1] */ p = p + 1; /* p points to [1] */ p++; /* p points to [2] */ p p 2 28

8 Pointers nd Arrs, cont d Arr nmes re constnt pointers int [10], *p, i; p = ; /* p points to [0] */ = p; /* Illegl; cn t chnge constnt */ ++; /* Illegl; cn t chnge constnt */ p++; /* Legl; p is vrile */ Suscripting is defined in terms of pointers [i], *(+i), i[] /* Legl nd the sme */ &[i], +i /* Legl nd the sme */ p = &[0] /* &*(+0) &* */ Pointers cn wlk rrs efficientl p = ; for (i = 0; i < 10; i++) printf( %d\n, *p++ ); 29 Pointer Arithmetic n o w i s t h e t i m e \ long *p; Pointer rithmetic tkes into ccount the stride (size of) the vlue pointed to long *p; p += i; /* increments p i elements */ p -= i; /* decrements p i elements */ p++; /* increments p 1 element */ p--; /* decrements p 1 element */ If p nd q re pointers to sme tpe T p q /* numer of elements (longs, or chrs) etween p nd q */ Does it mke sense to dd two pointers? chr *p; 0 Pointer Arithmetic, cont d Pointer & Arr Prmeters Comprison opertions for pointers <, >, <=, >=, ==,!= if (p < q)... ; p nd q must point to the sme rr no runtime checks to ensure this An emple int strlen(chr *s) chr *p; for (p = s; *p; p++) ; return p s; n o w i s t h e t i m e \0 Formls re not constnt; the re vriles Pssing n rr psses pointer to 1st element Arrs (nd onl rrs) re pssed reference Declrtion: void f(int [])... is equivlent to void f(int *)... = +1; Cll: int [10];... f(); 1 2 s p p

9 Pointers & Strings An Emple: String Cop A C string is n rr of chr with NULL t the end n o w i s t h e t i m e \0 String constnts denote constnt pointers to ctul chrs chr *msg = now is the time ; chr msg[] = now is the time ; chr *msg = msg; /* msg points to 1st chrcter of now is the time */ Strings cn e used whenever rrs of chrs re used sttic chr digits[] = ; putchr( [i]); putchr(digits[i]); Pointers nd rrs re essentill the sme thing => Pointers to chrs nd rrs of chrs re the sme Arr version void scop(chr s[], chr t[]) int i = 0; while ((s[i] = t[i])!= \0 ) i++; Pointer version void scop(chr *s, chr *t) while (*s = *t) s++; t++; Idiomtic version void scop(chr s[], chr t[]) while (*s++ = *t++) ; 4 Arrs of Pointers Arrs of Pointers, cont d Used to uild tulr structures Declre rr of pointers to strings chr *line[100]; chr *(line[100]); /* sme s ove */ chr (*line)[100]; /* never used */ Initiliztion emple chr *month(int n) sttic chr *nme[] = Jnur, Ferur, Mrch, April, M, June, Jul, August, Septemer, Octoer, Novemer, Decemer ; Reference emples line[i] /* refers to the i-th string */ *line[i] /* refers to the 0-th chr of the i-th string */ ssert(n >= 1 && n <= 12); return nme[n-1]; Another emple int, ; int *[] = &, &, &, &, NULL; 5 6

10 Arrs of Pointers, cont d An rr of pointers is 2-D rr int [10][10]; int *[10]; Arr : 2-dimensionl 1010 rr Storge for 100 elements llocted t compile time Ech row of hs 10 elements, cnnot chnge t runtime [6] is constnt 2-d rrs re stored in row-mjor order row 2 row 1 row 0 Arr : An rr of 10 pointers; ech element could point to n rr Storge for 10 pointers llocted t compile time Vlues of these pointers must e initilized t runtime Ech row of cn hve different length (rgged rr) [6] is vrile; [i] cn chnge t runtime More Emples Equivlence emple void f(int *[10]); /* known numer of rows */ void f(int **); Another equivlnce emple void g(int [][10]); /* known numer of columns */ void g(int (*)[10]); Legl in oth f nd g: ** = 1; 8 Commnd-Line Arguments Pointers to Functions B convention, min() is clled with 2 rguments int min(int rgc, chr *rgv[]) rgc is the numer of rguments, including the progrm nme rgv is n rr of pointers to the rguments Emple: % echo hello rgc = 2 rgv[0] = echo rgv[1] = hello rgv[2] = NULL Implementtion of echo min(int rgc, chr *rgv[]) int i; for (i = 1; i < rgc; i++) printf( %s%c,rgv[i], (i < rgc-1)? : \n ); eit(0); 9 #include <stdio.h> int dd(int, int ) return + ; int mul(int, int ) return * ; min() int [5] = 1, 2,, 4, 5; int sum = doarr(, 5, 0, dd); int prod = doarr(, 5, 1, mul); printf("sum = %d, product = %d\n", sum, prod); int doarr(int [], int n, int vl, int (*op)(int, int)) int i; for (i = 0; i < n; i++) vl = (*op)(vl, [i]); /* vl = op(vl, [i]); */ return vl; 40

11 Pointers to Functions, cont d Declrtion snt cn e confusing: int (*op)(int, int) declres op to e pointer to function tht tkes two int rguments nd returns n int int *op(int, int) declres op to e function tht tkes two int rguments nd returns pointer to n int Invoction snt cn lso confuse: (*op)(, ) clls the function pointed to op with the rguments nd, equivlent to op(, ) *op(, ) clls the function op with rguments nd, then dereferences the vlue returned Pointers to Functions, cont d A function nme itself is constnt pointer to function (like n rr nme) int dd(int, int ) int mul(int, int ) int sum = doarr(, 5, 0, dd); int prod = doarr(, 5, 1, mul); Function cll hs higher precedence thn dereferencing Pointers to Functions, cont d Arrs of pointers to functions etern int mul(int, int); etern int dd(int, int);... int (*opertors[])(int, int) = mul, dd,... ; To invoke (*opertors[i])(, ); Summr Pointers tpe * (int *p) declres pointer vrile * nd & re the ke opertions Opertion rules Unr opertions ind more tightl thn inr ones Pointer rithmetic opertions consider size of the elements Pointers nd rrs hve tight reltionship An rr is constnt pointer pointing to the 1 st element A pointer cn wlk through elements of n rr An rr of pointers is 2-D rr (1-D fied nd nother vrile) Mster how to get commnd-line rguments from min() 4 Pointers to functions Cn e used to prmeterize functions 44

Pointers. Pointers. Pointers (cont) CS 217

Pointers. Pointers. Pointers (cont) CS 217 Pointers CS 217 Pointers Variables whose values are the addresses of variables Operations address of (reference) & indirection (dereference) * arithmetic +, - Declaration mimics use char *p; *p is a char,

More information

cisc1110 fall 2010 lecture VI.2 call by value function parameters another call by value example:

cisc1110 fall 2010 lecture VI.2 call by value function parameters another call by value example: cisc1110 fll 2010 lecture VI.2 cll y vlue function prmeters more on functions more on cll y vlue nd cll y reference pssing strings to functions returning strings from functions vrile scope glol vriles

More information

Agenda & Reading. Class Exercise. COMPSCI 105 SS 2012 Principles of Computer Science. Arrays

Agenda & Reading. Class Exercise. COMPSCI 105 SS 2012 Principles of Computer Science. Arrays COMPSCI 5 SS Principles of Computer Science Arrys & Multidimensionl Arrys Agend & Reding Agend Arrys Creting & Using Primitive & Reference Types Assignments & Equlity Pss y Vlue & Pss y Reference Copying

More information

Pointers. Pointer References

Pointers. Pointer References Pointers Pointers are variables whose values are the addresses of other variables Basic operations address of (reference) indirection (dereference) Suppose x and y are integers, p is a pointer to an integer:

More information

box Boxes and Arrows 3 true 7.59 'X' An object is drawn as a box that contains its data members, for example:

box Boxes and Arrows 3 true 7.59 'X' An object is drawn as a box that contains its data members, for example: Boxes nd Arrows There re two kinds of vriles in Jv: those tht store primitive vlues nd those tht store references. Primitive vlues re vlues of type long, int, short, chr, yte, oolen, doule, nd flot. References

More information

Programming. Example - Complex Numbers. add_complex step by step. add_complex step by step. add_complex step by step י"ט/טבת/תשע"א

Programming. Example - Complex Numbers. add_complex step by step. add_complex step by step. add_complex step by step יט/טבת/תשעא Emple - Comple Numers Progrmming Structure declrtion tpedef struct comple doule, ; Comple ; Structures Vrile definition Comple c1, c2; Structures nd Functions - Emple Comple mke_comple(doule, doule ) Comple

More information

Sample Midterm Solutions COMS W4115 Programming Languages and Translators Monday, October 12, 2009

Sample Midterm Solutions COMS W4115 Programming Languages and Translators Monday, October 12, 2009 Deprtment of Computer cience Columbi University mple Midterm olutions COM W4115 Progrmming Lnguges nd Trnsltors Mondy, October 12, 2009 Closed book, no ids. ch question is worth 20 points. Question 5(c)

More information

Reference types and their characteristics Class Definition Constructors and Object Creation Special objects: Strings and Arrays

Reference types and their characteristics Class Definition Constructors and Object Creation Special objects: Strings and Arrays Objects nd Clsses Reference types nd their chrcteristics Clss Definition Constructors nd Object Cretion Specil objects: Strings nd Arrys OOAD 1999/2000 Cludi Niederée, Jochim W. Schmidt Softwre Systems

More information

Discussion 1 Recap. COP4600 Discussion 2 OS concepts, System call, and Assignment 1. Questions. Questions. Outline. Outline 10/24/2010

Discussion 1 Recap. COP4600 Discussion 2 OS concepts, System call, and Assignment 1. Questions. Questions. Outline. Outline 10/24/2010 COP4600 Discussion 2 OS concepts, System cll, nd Assignment 1 TA: Hufeng Jin hj0@cise.ufl.edu Discussion 1 Recp Introduction to C C Bsic Types (chr, int, long, flot, doule, ) C Preprocessors (#include,

More information

Scope, Functions, and Storage Management

Scope, Functions, and Storage Management Scope, Functions, nd Storge Mngement Block-structured lnguges nd stck storge In-le Blocks (previous set of overheds) ctivtion records storge for locl, glol vriles First-order functions (previous set of

More information

CS201 Discussion 10 DRAWTREE + TRIES

CS201 Discussion 10 DRAWTREE + TRIES CS201 Discussion 10 DRAWTREE + TRIES DrwTree First instinct: recursion As very generic structure, we could tckle this problem s follows: drw(): Find the root drw(root) drw(root): Write the line for the

More information

Mid-term exam. Scores. Fall term 2012 KAIST EE209 Programming Structures for EE. Thursday Oct 25, Student's name: Student ID:

Mid-term exam. Scores. Fall term 2012 KAIST EE209 Programming Structures for EE. Thursday Oct 25, Student's name: Student ID: Fll term 2012 KAIST EE209 Progrmming Structures for EE Mid-term exm Thursdy Oct 25, 2012 Student's nme: Student ID: The exm is closed book nd notes. Red the questions crefully nd focus your nswers on wht

More information

Lexical Analysis. Amitabha Sanyal. (www.cse.iitb.ac.in/ as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay

Lexical Analysis. Amitabha Sanyal. (www.cse.iitb.ac.in/ as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay Lexicl Anlysis Amith Snyl (www.cse.iit.c.in/ s) Deprtment of Computer Science nd Engineering, Indin Institute of Technology, Bomy Septemer 27 College of Engineering, Pune Lexicl Anlysis: 2/6 Recp The input

More information

Functor (1A) Young Won Lim 10/5/17

Functor (1A) Young Won Lim 10/5/17 Copyright (c) 2016-2017 Young W. Lim. Permission is grnted to copy, distribute nd/or modify this document under the terms of the GNU Free Documenttion License, Version 1.2 or ny lter version published

More information

ASTs, Regex, Parsing, and Pretty Printing

ASTs, Regex, Parsing, and Pretty Printing ASTs, Regex, Prsing, nd Pretty Printing CS 2112 Fll 2016 1 Algeric Expressions To strt, consider integer rithmetic. Suppose we hve the following 1. The lphet we will use is the digits {0, 1, 2, 3, 4, 5,

More information

CPSC 213. Polymorphism. Introduction to Computer Systems. Readings for Next Two Lectures. Back to Procedure Calls

CPSC 213. Polymorphism. Introduction to Computer Systems. Readings for Next Two Lectures. Back to Procedure Calls Redings for Next Two Lectures Text CPSC 213 Switch Sttements, Understnding Pointers - 2nd ed: 3.6.7, 3.10-1st ed: 3.6.6, 3.11 Introduction to Computer Systems Unit 1f Dynmic Control Flow Polymorphism nd

More information

CSCE 531, Spring 2017, Midterm Exam Answer Key

CSCE 531, Spring 2017, Midterm Exam Answer Key CCE 531, pring 2017, Midterm Exm Answer Key 1. (15 points) Using the method descried in the ook or in clss, convert the following regulr expression into n equivlent (nondeterministic) finite utomton: (

More information

Functor (1A) Young Won Lim 8/2/17

Functor (1A) Young Won Lim 8/2/17 Copyright (c) 2016-2017 Young W. Lim. Permission is grnted to copy, distribute nd/or modify this document under the terms of the GNU Free Documenttion License, Version 1.2 or ny lter version published

More information

Introduction To Files In Pascal

Introduction To Files In Pascal Why other With Files? Introduction To Files In Pscl Too much informtion to input ll t once The informtion must be persistent (RAM is voltile) Etc. In this section of notes you will lern how to red from

More information

Symbol Table management

Symbol Table management TDDD Compilers nd interpreters TDDB44 Compiler Construction Symol Tles Symol Tles in the Compiler Symol Tle mngement source progrm Leicl nlysis Syntctic nlysis Semntic nlysis nd Intermedite code gen Code

More information

Today s Lecture. Basics of Logic Design: Boolean Algebra, Logic Gates. Recursive Example. Review: The C / C++ code. Recursive Example (Continued)

Today s Lecture. Basics of Logic Design: Boolean Algebra, Logic Gates. Recursive Example. Review: The C / C++ code. Recursive Example (Continued) Tod s Lecture Bsics of Logic Design: Boolen Alger, Logic Gtes Alvin R. Leeck CPS 4 Lecture 8 Homework #2 Due Ferur 3 Outline Review (sseml recursion) Building the uilding locks Logic Design Truth tles,

More information

CS412/413. Introduction to Compilers Tim Teitelbaum. Lecture 4: Lexical Analyzers 28 Jan 08

CS412/413. Introduction to Compilers Tim Teitelbaum. Lecture 4: Lexical Analyzers 28 Jan 08 CS412/413 Introduction to Compilers Tim Teitelum Lecture 4: Lexicl Anlyzers 28 Jn 08 Outline DFA stte minimiztion Lexicl nlyzers Automting lexicl nlysis Jlex lexicl nlyzer genertor CS 412/413 Spring 2008

More information

CS321 Languages and Compiler Design I. Winter 2012 Lecture 5

CS321 Languages and Compiler Design I. Winter 2012 Lecture 5 CS321 Lnguges nd Compiler Design I Winter 2012 Lecture 5 1 FINITE AUTOMATA A non-deterministic finite utomton (NFA) consists of: An input lphet Σ, e.g. Σ =,. A set of sttes S, e.g. S = {1, 3, 5, 7, 11,

More information

Procedures vs. Functions. Procedure Call. Syntax. Activation Record for Nested Blocks. Environment. CSE 3302 Programming Languages

Procedures vs. Functions. Procedure Call. Syntax. Activation Record for Nested Blocks. Environment. CSE 3302 Programming Languages -2-3 CSE 3302 Progrmmng Lnguges Control II Procedures nd Envronments Chengk L, Wemn He Sprng Procedures vs. Functons Functon: no sde effect return vlue Functon cll: epresson Procedure: sde effect, eecuted

More information

Quiz2 45mins. Personal Number: Problem 1. (20pts) Here is an Table of Perl Regular Ex

Quiz2 45mins. Personal Number: Problem 1. (20pts) Here is an Table of Perl Regular Ex Long Quiz2 45mins Nme: Personl Numer: Prolem. (20pts) Here is n Tle of Perl Regulr Ex Chrcter Description. single chrcter \s whitespce chrcter (spce, t, newline) \S non-whitespce chrcter \d digit (0-9)

More information

Lecture Overview. Knowledge-based systems in Bioinformatics, 1MB602. Procedural abstraction. The sum procedure. Integration as a procedure

Lecture Overview. Knowledge-based systems in Bioinformatics, 1MB602. Procedural abstraction. The sum procedure. Integration as a procedure Lecture Overview Knowledge-bsed systems in Bioinformtics, MB6 Scheme lecture Procedurl bstrction Higher order procedures Procedures s rguments Procedures s returned vlues Locl vribles Dt bstrction Compound

More information

Stack. A list whose end points are pointed by top and bottom

Stack. A list whose end points are pointed by top and bottom 4. Stck Stck A list whose end points re pointed by top nd bottom Insertion nd deletion tke plce t the top (cf: Wht is the difference between Stck nd Arry?) Bottom is constnt, but top grows nd shrinks!

More information

Virtual Machine (Part I)

Virtual Machine (Part I) Hrvrd University CS Fll 2, Shimon Schocken Virtul Mchine (Prt I) Elements of Computing Systems Virtul Mchine I (Ch. 7) Motivtion clss clss Min Min sttic sttic x; x; function function void void min() min()

More information

Matrices and Systems of Equations

Matrices and Systems of Equations Mtrices Mtrices nd Sstems of Equtions A mtri is rectngulr rr of rel numbers. CHAT Pre-Clculus Section 8. m m m............ n n n mn We will use the double subscript nottion for ech element of the mtri.

More information

10/9/2012. Operator is an operation performed over data at runtime. Arithmetic, Logical, Comparison, Assignment, Etc. Operators have precedence

10/9/2012. Operator is an operation performed over data at runtime. Arithmetic, Logical, Comparison, Assignment, Etc. Operators have precedence /9/22 P f Performing i Si Simple l Clcultions C l l ti with ith C#. Opertors in C# nd Opertor Precedence 2. Arithmetic Opertors 3. Logicl Opertors 4. Bitwise Opertors 5. Comprison Opertors 6. Assignment

More information

Definition of Regular Expression

Definition of Regular Expression Definition of Regulr Expression After the definition of the string nd lnguges, we re redy to descrie regulr expressions, the nottion we shll use to define the clss of lnguges known s regulr sets. Recll

More information

The Basic Properties of the Integral

The Basic Properties of the Integral The Bsic Properties of the Integrl When we compute the derivtive of complicted function, like + sin, we usull use differentition rules, like d [f()+g()] d f()+ d g(), to reduce the computtion d d d to

More information

Fig.25: the Role of LEX

Fig.25: the Role of LEX The Lnguge for Specifying Lexicl Anlyzer We shll now study how to uild lexicl nlyzer from specifiction of tokens in the form of list of regulr expressions The discussion centers round the design of n existing

More information

CMPSC 470: Compiler Construction

CMPSC 470: Compiler Construction CMPSC 47: Compiler Construction Plese complete the following: Midterm (Type A) Nme Instruction: Mke sure you hve ll pges including this cover nd lnk pge t the end. Answer ech question in the spce provided.

More information

Memory Management Functions

Memory Management Functions Meory Mngeent Functions Chpter 9 Meory Mngeent Process of binding vlues to eory loctions Vlues y be sttic or dynic Vlues re ssigned t different plces Sttic eory Run-tie stck Hep 1 Meory Mngeent Sttic Meory

More information

Introduction to Computer Science, Shimon Schocken, IDC Herzliya. Lecture Writing Classes

Introduction to Computer Science, Shimon Schocken, IDC Herzliya. Lecture Writing Classes Introduction to Computer Science, Shimon Schocken, IDC Herzliy Lecture 5.1-5.2 Writing Clsses Writing Clsses, Shimon Schocken IDC Herzliy, www.ro2cs.com slide 1 Clsses Two viewpos on es: Client view: how

More information

Lists in Lisp and Scheme

Lists in Lisp and Scheme Lists in Lisp nd Scheme Lists in Lisp nd Scheme Lists re Lisp s fundmentl dt structures, ut there re others Arrys, chrcters, strings, etc. Common Lisp hs moved on from eing merely LISt Processor However,

More information

2 Computing all Intersections of a Set of Segments Line Segment Intersection

2 Computing all Intersections of a Set of Segments Line Segment Intersection 15-451/651: Design & Anlysis of Algorithms Novemer 14, 2016 Lecture #21 Sweep-Line nd Segment Intersection lst chnged: Novemer 8, 2017 1 Preliminries The sweep-line prdigm is very powerful lgorithmic design

More information

Outline. Tiling, formally. Expression tile as rule. Statement tiles as rules. Function calls. CS 412 Introduction to Compilers

Outline. Tiling, formally. Expression tile as rule. Statement tiles as rules. Function calls. CS 412 Introduction to Compilers CS 412 Introduction to Compilers Andrew Myers Cornell University Lectur8 Finishing genertion 9 Mr 01 Outline Tiling s syntx-directed trnsltion Implementing function clls Implementing functions Optimizing

More information

Reducing a DFA to a Minimal DFA

Reducing a DFA to a Minimal DFA Lexicl Anlysis - Prt 4 Reducing DFA to Miniml DFA Input: DFA IN Assume DFA IN never gets stuck (dd ded stte if necessry) Output: DFA MIN An equivlent DFA with the minimum numer of sttes. Hrry H. Porter,

More information

In the last lecture, we discussed how valid tokens may be specified by regular expressions.

In the last lecture, we discussed how valid tokens may be specified by regular expressions. LECTURE 5 Scnning SYNTAX ANALYSIS We know from our previous lectures tht the process of verifying the syntx of the progrm is performed in two stges: Scnning: Identifying nd verifying tokens in progrm.

More information

Lecture 10 Evolutionary Computation: Evolution strategies and genetic programming

Lecture 10 Evolutionary Computation: Evolution strategies and genetic programming Lecture 10 Evolutionry Computtion: Evolution strtegies nd genetic progrmming Evolution strtegies Genetic progrmming Summry Negnevitsky, Person Eduction, 2011 1 Evolution Strtegies Another pproch to simulting

More information

CIS 1068 Program Design and Abstraction Spring2015 Midterm Exam 1. Name SOLUTION

CIS 1068 Program Design and Abstraction Spring2015 Midterm Exam 1. Name SOLUTION CIS 1068 Progrm Design nd Astrction Spring2015 Midterm Exm 1 Nme SOLUTION Pge Points Score 2 15 3 8 4 18 5 10 6 7 7 7 8 14 9 11 10 10 Totl 100 1 P ge 1. Progrm Trces (41 points, 50 minutes) Answer the

More information

Systems I. Logic Design I. Topics Digital logic Logic gates Simple combinational logic circuits

Systems I. Logic Design I. Topics Digital logic Logic gates Simple combinational logic circuits Systems I Logic Design I Topics Digitl logic Logic gtes Simple comintionl logic circuits Simple C sttement.. C = + ; Wht pieces of hrdwre do you think you might need? Storge - for vlues,, C Computtion

More information

COMPUTER SCIENCE 123. Foundations of Computer Science. 6. Tuples

COMPUTER SCIENCE 123. Foundations of Computer Science. 6. Tuples COMPUTER SCIENCE 123 Foundtions of Computer Science 6. Tuples Summry: This lecture introduces tuples in Hskell. Reference: Thompson Sections 5.1 2 R.L. While, 2000 3 Tuples Most dt comes with structure

More information

1.1. Interval Notation and Set Notation Essential Question When is it convenient to use set-builder notation to represent a set of numbers?

1.1. Interval Notation and Set Notation Essential Question When is it convenient to use set-builder notation to represent a set of numbers? 1.1 TEXAS ESSENTIAL KNOWLEDGE AND SKILLS Prepring for 2A.6.K, 2A.7.I Intervl Nottion nd Set Nottion Essentil Question When is it convenient to use set-uilder nottion to represent set of numers? A collection

More information

Unit #9 : Definite Integral Properties, Fundamental Theorem of Calculus

Unit #9 : Definite Integral Properties, Fundamental Theorem of Calculus Unit #9 : Definite Integrl Properties, Fundmentl Theorem of Clculus Gols: Identify properties of definite integrls Define odd nd even functions, nd reltionship to integrl vlues Introduce the Fundmentl

More information

10.5 Graphing Quadratic Functions

10.5 Graphing Quadratic Functions 0.5 Grphing Qudrtic Functions Now tht we cn solve qudrtic equtions, we wnt to lern how to grph the function ssocited with the qudrtic eqution. We cll this the qudrtic function. Grphs of Qudrtic Functions

More information

Data sharing in OpenMP

Data sharing in OpenMP Dt shring in OpenMP Polo Burgio polo.burgio@unimore.it Outline Expressing prllelism Understnding prllel threds Memory Dt mngement Dt cluses Synchroniztion Brriers, locks, criticl sections Work prtitioning

More information

Summer Review Packet For Algebra 2 CP/Honors

Summer Review Packet For Algebra 2 CP/Honors Summer Review Pcket For Alger CP/Honors Nme Current Course Mth Techer Introduction Alger uilds on topics studied from oth Alger nd Geometr. Certin topics re sufficientl involved tht the cll for some review

More information

Computer Arithmetic Logical, Integer Addition & Subtraction Chapter

Computer Arithmetic Logical, Integer Addition & Subtraction Chapter Computer Arithmetic Logicl, Integer Addition & Sutrction Chpter 3.-3.3 3.3 EEC7 FQ 25 MIPS Integer Representtion -it signed integers,, e.g., for numeric opertions 2 s s complement: one representtion for

More information

Stack Manipulation. Other Issues. How about larger constants? Frame Pointer. PowerPC. Alternative Architectures

Stack Manipulation. Other Issues. How about larger constants? Frame Pointer. PowerPC. Alternative Architectures Other Issues Stck Mnipultion support for procedures (Refer to section 3.6), stcks, frmes, recursion mnipulting strings nd pointers linkers, loders, memory lyout Interrupts, exceptions, system clls nd conventions

More information

PARALLEL AND DISTRIBUTED COMPUTING

PARALLEL AND DISTRIBUTED COMPUTING PARALLEL AND DISTRIBUTED COMPUTING 2009/2010 1 st Semester Teste Jnury 9, 2010 Durtion: 2h00 - No extr mteril llowed. This includes notes, scrtch pper, clcultor, etc. - Give your nswers in the ville spce

More information

Topics in Analytic Geometry

Topics in Analytic Geometry Nme Chpter 10 Topics in Anltic Geometr Section 10.1 Lines Objective: In this lesson ou lerned how to find the inclintion of line, the ngle between two lines, nd the distnce between point nd line. Importnt

More information

PYTHON PROGRAMMING. The History of Python. Features of Python. This Course

PYTHON PROGRAMMING. The History of Python. Features of Python. This Course The History of Python PYTHON PROGRAMMING Dr Christin Hill 7 9 November 2016 Invented by Guido vn Rossum* t the Centrum Wiskunde & Informtic in Amsterdm in the erly 1990s Nmed fter Monty Python s Flying

More information

From Dependencies to Evaluation Strategies

From Dependencies to Evaluation Strategies From Dependencies to Evlution Strtegies Possile strtegies: 1 let the user define the evlution order 2 utomtic strtegy sed on the dependencies: use locl dependencies to determine which ttriutes to compute

More information

Presentation Martin Randers

Presentation Martin Randers Presenttion Mrtin Rnders Outline Introduction Algorithms Implementtion nd experiments Memory consumption Summry Introduction Introduction Evolution of species cn e modelled in trees Trees consist of nodes

More information

What do all those bits mean now? Number Systems and Arithmetic. Introduction to Binary Numbers. Questions About Numbers

What do all those bits mean now? Number Systems and Arithmetic. Introduction to Binary Numbers. Questions About Numbers Wht do ll those bits men now? bits (...) Number Systems nd Arithmetic or Computers go to elementry school instruction R-formt I-formt... integer dt number text chrs... floting point signed unsigned single

More information

CS 241. Fall 2017 Midterm Review Solutions. October 24, Bits and Bytes 1. 3 MIPS Assembler 6. 4 Regular Languages 7.

CS 241. Fall 2017 Midterm Review Solutions. October 24, Bits and Bytes 1. 3 MIPS Assembler 6. 4 Regular Languages 7. CS 241 Fll 2017 Midterm Review Solutions Octoer 24, 2017 Contents 1 Bits nd Bytes 1 2 MIPS Assemly Lnguge Progrmming 2 3 MIPS Assemler 6 4 Regulr Lnguges 7 5 Scnning 9 1 Bits nd Bytes 1. Give two s complement

More information

called the vertex. The line through the focus perpendicular to the directrix is called the axis of the parabola.

called the vertex. The line through the focus perpendicular to the directrix is called the axis of the parabola. Review of conic sections Conic sections re grphs of the form REVIEW OF CONIC SECTIONS prols ellipses hperols P(, ) F(, p) O p =_p REVIEW OF CONIC SECTIONS In this section we give geometric definitions

More information

CSE 401 Midterm Exam 11/5/10 Sample Solution

CSE 401 Midterm Exam 11/5/10 Sample Solution Question 1. egulr expressions (20 points) In the Ad Progrmming lnguge n integer constnt contins one or more digits, but it my lso contin embedded underscores. Any underscores must be preceded nd followed

More information

Exam #1 for Computer Simulation Spring 2005

Exam #1 for Computer Simulation Spring 2005 Exm # for Computer Simultion Spring 005 >>> SOLUTION

More information

Product of polynomials. Introduction to Programming (in C++) Numerical algorithms. Product of polynomials. Product of polynomials

Product of polynomials. Introduction to Programming (in C++) Numerical algorithms. Product of polynomials. Product of polynomials Product of polynomils Introduction to Progrmming (in C++) Numericl lgorithms Jordi Cortdell, Ricrd Gvldà, Fernndo Orejs Dept. of Computer Science, UPC Given two polynomils on one vrile nd rel coefficients,

More information

5 Regular 4-Sided Composition

5 Regular 4-Sided Composition Xilinx-Lv User Guide 5 Regulr 4-Sided Composition This tutoril shows how regulr circuits with 4-sided elements cn be described in Lv. The type of regulr circuits tht re discussed in this tutoril re those

More information

L2-Python-Data-Structures

L2-Python-Data-Structures L2-Python-Dt-Structures Mrch 19, 2018 1 Principl built-in types in Python (Python ) numerics: int, flot, long, complex sequences: str, unicode, list, tuple, byterry, buffer, xrnge mppings: dict files:

More information

Lecture 7: Integration Techniques

Lecture 7: Integration Techniques Lecture 7: Integrtion Techniques Antiderivtives nd Indefinite Integrls. In differentil clculus, we were interested in the derivtive of given rel-vlued function, whether it ws lgeric, eponentil or logrithmic.

More information

Example: Source Code. Lexical Analysis. The Lexical Structure. Tokens. What do we really care here? A Sample Toy Program:

Example: Source Code. Lexical Analysis. The Lexical Structure. Tokens. What do we really care here? A Sample Toy Program: Lexicl Anlysis Red source progrm nd produce list of tokens ( liner nlysis) source progrm The lexicl structure is specified using regulr expressions Other secondry tsks: (1) get rid of white spces (e.g.,

More information

Engineer To Engineer Note

Engineer To Engineer Note Engineer To Engineer Note EE-188 Technicl Notes on using Anlog Devices' DSP components nd development tools Contct our technicl support by phone: (800) ANALOG-D or e-mil: dsp.support@nlog.com Or visit

More information

Union-Find Problem. Using Arrays And Chains. A Set As A Tree. Result Of A Find Operation

Union-Find Problem. Using Arrays And Chains. A Set As A Tree. Result Of A Find Operation Union-Find Problem Given set {,,, n} of n elements. Initilly ech element is in different set. ƒ {}, {},, {n} An intermixed sequence of union nd find opertions is performed. A union opertion combines two

More information

Reducing Costs with Duck Typing. Structural

Reducing Costs with Duck Typing. Structural Reducing Costs with Duck Typing Structurl 1 Duck Typing In computer progrmming with object-oriented progrmming lnguges, duck typing is lyer of progrmming lnguge nd design rules on top of typing. Typing

More information

Arrays as functions. Types. Multidimensional Arrays (row major, column major form) Java arrays

Arrays as functions. Types. Multidimensional Arrays (row major, column major form) Java arrays Louden Chpters 6,9 Types Dt Types nd Abstrct Dt Types 1 Arrys s functons f: U -> V (f U s ordnl type) f() rry C rrys types cn be wthout szes rry vrbles must hve fxed sze rry_mx( [], sze) // prmeters re

More information

EXPONENTIAL & POWER GRAPHS

EXPONENTIAL & POWER GRAPHS Eponentil & Power Grphs EXPONENTIAL & POWER GRAPHS www.mthletics.com.u Eponentil EXPONENTIAL & Power & Grphs POWER GRAPHS These re grphs which result from equtions tht re not liner or qudrtic. The eponentil

More information

MA1008. Calculus and Linear Algebra for Engineers. Course Notes for Section B. Stephen Wills. Department of Mathematics. University College Cork

MA1008. Calculus and Linear Algebra for Engineers. Course Notes for Section B. Stephen Wills. Department of Mathematics. University College Cork MA1008 Clculus nd Liner Algebr for Engineers Course Notes for Section B Stephen Wills Deprtment of Mthemtics University College Cork s.wills@ucc.ie http://euclid.ucc.ie/pges/stff/wills/teching/m1008/ma1008.html

More information

Solution of Linear Algebraic Equations using the Gauss-Jordan Method

Solution of Linear Algebraic Equations using the Gauss-Jordan Method Solution of Liner Algebric Equtions using the Guss-Jordn Method Populr pproch for solving liner equtions The Guss Jordn method depends on two properties of liner equtions: Scling one or more of ny of the

More information

Dynamic Programming. Andreas Klappenecker. [partially based on slides by Prof. Welch] Monday, September 24, 2012

Dynamic Programming. Andreas Klappenecker. [partially based on slides by Prof. Welch] Monday, September 24, 2012 Dynmic Progrmming Andres Klppenecker [prtilly bsed on slides by Prof. Welch] 1 Dynmic Progrmming Optiml substructure An optiml solution to the problem contins within it optiml solutions to subproblems.

More information

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών ΕΠΛ323 - Θωρία και Πρακτική Μταγλωττιστών Lecture 3 Lexicl Anlysis Elis Athnsopoulos elisthn@cs.ucy.c.cy Recognition of Tokens if expressions nd reltionl opertors if è if then è then else è else relop

More information

Algebra II Notes Unit Ten: Conic Sections

Algebra II Notes Unit Ten: Conic Sections Sllus Ojective: 0. The student will sketch the grph of conic section with centers either t or not t the origin. (PARABOLAS) Review: The Midpoint Formul The midpoint M of the line segment connecting the

More information

LAB L Hardware Building Blocks

LAB L Hardware Building Blocks LAB L Hrdwre Building Blocks Perform the following groups of tsks: LL1.v 1. In previous l we creted the 2-to-1 mux shown in the left prt of the figure elow nd found tht it cts s n if sttement. c c 0 1

More information

How to Design REST API? Written Date : March 23, 2015

How to Design REST API? Written Date : March 23, 2015 Visul Prdigm How Design REST API? Turil How Design REST API? Written Dte : Mrch 23, 2015 REpresenttionl Stte Trnsfer, n rchitecturl style tht cn be used in building networked pplictions, is becoming incresingly

More information

Context-Free Grammars

Context-Free Grammars Context-Free Grmmrs Descriing Lnguges We've seen two models for the regulr lnguges: Finite utomt ccept precisely the strings in the lnguge. Regulr expressions descrie precisely the strings in the lnguge.

More information

Essential Question What are some of the characteristics of the graph of a rational function?

Essential Question What are some of the characteristics of the graph of a rational function? 8. TEXAS ESSENTIAL KNOWLEDGE AND SKILLS A..A A..G A..H A..K Grphing Rtionl Functions Essentil Question Wht re some of the chrcteristics of the grph of rtionl function? The prent function for rtionl functions

More information

COMP 423 lecture 11 Jan. 28, 2008

COMP 423 lecture 11 Jan. 28, 2008 COMP 423 lecture 11 Jn. 28, 2008 Up to now, we hve looked t how some symols in n lphet occur more frequently thn others nd how we cn sve its y using code such tht the codewords for more frequently occuring

More information

- 2 U NIX FILES 1. Explin different file types vilble in UNIX or P OSIX s ystem. ( 08 mrks) ( My-08/Dec-08/My-10/My- 12) 2. Wht is n API? How is it di

- 2 U NIX FILES 1. Explin different file types vilble in UNIX or P OSIX s ystem. ( 08 mrks) ( My-08/Dec-08/My-10/My- 12) 2. Wht is n API? How is it di -1 I NTRODUCTION 1. Wht is posix stndrd? Explin different subset of posix stndrd. Write structure of progrm to filter out non- p osix complint codes from user progrm. ( 06 mrks) ( Dec- 2010). 2. W rite

More information

Information Retrieval and Organisation

Information Retrieval and Organisation Informtion Retrievl nd Orgnistion Suffix Trees dpted from http://www.mth.tu.c.il/~himk/seminr02/suffixtrees.ppt Dell Zhng Birkeck, University of London Trie A tree representing set of strings { } eef d

More information

Hyperbolas. Definition of Hyperbola

Hyperbolas. Definition of Hyperbola CHAT Pre-Clculus Hyperols The third type of conic is clled hyperol. For n ellipse, the sum of the distnces from the foci nd point on the ellipse is fixed numer. For hyperol, the difference of the distnces

More information

Suffix trees, suffix arrays, BWT

Suffix trees, suffix arrays, BWT ALGORITHMES POUR LA BIO-INFORMATIQUE ET LA VISUALISATION COURS 3 Rluc Uricru Suffix trees, suffix rrys, BWT Bsed on: Suffix trees nd suffix rrys presenttion y Him Kpln Suffix trees course y Pco Gomez Liner-Time

More information

Basics of Logic Design Arithmetic Logic Unit (ALU)

Basics of Logic Design Arithmetic Logic Unit (ALU) Bsics of Logic Design Arithmetic Logic Unit (ALU) CPS 4 Lecture 9 Tody s Lecture Homework #3 Assigned Due Mrch 3 Project Groups ssigned & posted to lckord. Project Specifiction is on We Due April 9 Building

More information

George Boole. IT 3123 Hardware and Software Concepts. Switching Algebra. Boolean Functions. Boolean Functions. Truth Tables

George Boole. IT 3123 Hardware and Software Concepts. Switching Algebra. Boolean Functions. Boolean Functions. Truth Tables George Boole IT 3123 Hrdwre nd Softwre Concepts My 28 Digitl Logic The Little Mn Computer 1815 1864 British mthemticin nd philosopher Mny contriutions to mthemtics. Boolen lger: n lger over finite sets

More information

COMMON HALF YEARLY EXAMINATION DECEMBER 2018

COMMON HALF YEARLY EXAMINATION DECEMBER 2018 li.net i.net li.net i.net li.net i.net li.net i.net li.net i.net li.net i.net li.net i.net li.net i.net li.net i.net.pds.pds COMMON HALF YEARLY EXAMINATION DECEMBER 2018 STD : XI SUBJECT: COMPUTER SCIENCE

More information

Introduction to Scientific Computing and Problem Solving

Introduction to Scientific Computing and Problem Solving Introduction to Scientific Computing and Problem Solving Lecture #22 Pointers CS4 - Introduction to Scientific Computing and Problem Solving 2010-22.0 Announcements HW8 due tomorrow at 2:30pm What s left:

More information

Graphing Conic Sections

Graphing Conic Sections Grphing Conic Sections Definition of Circle Set of ll points in plne tht re n equl distnce, clled the rdius, from fixed point in tht plne, clled the center. Grphing Circle (x h) 2 + (y k) 2 = r 2 where

More information

The Fundamental Theorem of Calculus

The Fundamental Theorem of Calculus MATH 6 The Fundmentl Theorem of Clculus The Fundmentl Theorem of Clculus (FTC) gives method of finding the signed re etween the grph of f nd the x-xis on the intervl [, ]. The theorem is: FTC: If f is

More information

Questions About Numbers. Number Systems and Arithmetic. Introduction to Binary Numbers. Negative Numbers?

Questions About Numbers. Number Systems and Arithmetic. Introduction to Binary Numbers. Negative Numbers? Questions About Numbers Number Systems nd Arithmetic or Computers go to elementry school How do you represent negtive numbers? frctions? relly lrge numbers? relly smll numbers? How do you do rithmetic?

More information

EECS 281: Homework #4 Due: Thursday, October 7, 2004

EECS 281: Homework #4 Due: Thursday, October 7, 2004 EECS 28: Homework #4 Due: Thursdy, October 7, 24 Nme: Emil:. Convert the 24-bit number x44243 to mime bse64: QUJD First, set is to brek 8-bit blocks into 6-bit blocks, nd then convert: x44243 b b 6 2 9

More information

CS 241 Week 4 Tutorial Solutions

CS 241 Week 4 Tutorial Solutions CS 4 Week 4 Tutoril Solutions Writing n Assemler, Prt & Regulr Lnguges Prt Winter 8 Assemling instrutions utomtilly. slt $d, $s, $t. Solution: $d, $s, nd $t ll fit in -it signed integers sine they re 5-it

More information

Grade 7/8 Math Circles Geometric Arithmetic October 31, 2012

Grade 7/8 Math Circles Geometric Arithmetic October 31, 2012 Fculty of Mthemtics Wterloo, Ontrio N2L 3G1 Grde 7/8 Mth Circles Geometric Arithmetic Octoer 31, 2012 Centre for Eduction in Mthemtics nd Computing Ancient Greece hs given irth to some of the most importnt

More information

vcloud Director Service Provider Admin Portal Guide vcloud Director 9.1

vcloud Director Service Provider Admin Portal Guide vcloud Director 9.1 vcloud Director Service Provider Admin Portl Guide vcloud Director 9. vcloud Director Service Provider Admin Portl Guide You cn find the most up-to-dte technicl documenttion on the VMwre website t: https://docs.vmwre.com/

More information

Compression Outline :Algorithms in the Real World. Lempel-Ziv Algorithms. LZ77: Sliding Window Lempel-Ziv

Compression Outline :Algorithms in the Real World. Lempel-Ziv Algorithms. LZ77: Sliding Window Lempel-Ziv Compression Outline 15-853:Algorithms in the Rel World Dt Compression III Introduction: Lossy vs. Lossless, Benchmrks, Informtion Theory: Entropy, etc. Proility Coding: Huffmn + Arithmetic Coding Applictions

More information

Section 5.3 : Finding Area Between Curves

Section 5.3 : Finding Area Between Curves MATH 9 Section 5. : Finding Are Between Curves Importnt: In this section we will lern just how to set up the integrls to find re etween curves. The finl nswer for ech emple in this hndout is given for

More information

TO REGULAR EXPRESSIONS

TO REGULAR EXPRESSIONS Suject :- Computer Science Course Nme :- Theory Of Computtion DA TO REGULAR EXPRESSIONS Report Sumitted y:- Ajy Singh Meen 07000505 jysmeen@cse.iit.c.in BASIC DEINITIONS DA:- A finite stte mchine where

More information