COMS W3156: Software Engineering, Fall 2001 Lecture #20: C, continued Janak J Parekh

Slides:



Advertisements
Similar presentations
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Advertisements

STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Introduction to Programming Lecture 15. In Today’s Lecture Pointers and Arrays Manipulations Pointers and Arrays Manipulations Pointers Expression Pointers.
Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
David Notkin Autumn 2009 CSE303 Lecture 13 This space for rent.
1 Today’s lecture  Last lecture we started talking about control flow in MIPS (branches)  Finish up control-flow (branches) in MIPS —if/then —loops —case/switch.
CS324e - Elements of Graphics and Visualization A Little Java A Little Python.
MPI and C-Language Seminars Seminar Plan (1/3)  Aim: Introduce the ‘C’ Programming Language.  Plan to cover: Basic C, and programming techniques.
Constants and Data Types Constants Data Types Reading for this class: L&L,
Pointers Discussion 5 Section Housekeeping HW 1 Issues Array Issues Exam 1 Questions? Submitting on Time!
Introduction to Computers and Programming Lecture 7:
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
Pointer. Warning! Dangerous Curves C (and C++) have just about the most powerful, flexible and dangerous pointers in the world. –Most other languages.
COMS W3156: Software Engineering, Fall 2001 Lecture #21: C, C++ Janak J Parekh
CS 106 Introduction to Computer Science I 10 / 04 / 2006 Instructor: Michael Eckmann.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
Object References. Objects An array is a collection of values, all of the same type An object is a collection of values, which may be of different types.
Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);
Pointers CSE 2451 Rong Shi.
ARRAYS In this Lecture, we will try to develop understanding of some of the relatively complex concepts. The following are explained in this lecture with.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Introduction to Computer Systems and the Java Programming Language.
Week 6 - Wednesday.  What did we talk about last time?  Exam 1!  And before that…  Review!  And before that…  Arrays and strings.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 26: Exam 2 Preview.
Java Simple Types CSIS 3701: Advanced Object Oriented Programming.
SPL – Practical Session 2 Topics: – C++ Memory Management – Pointers.
Comp 248 Introduction to Programming Chapter 4 & 5 Defining Classes Part C Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
CS-1030 Dr. Mark L. Hornick 1 C++ Language Basic control statements and data types.
1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter read appendix B (3 pages on DOS) and and.
Lecture 22: Reviews for Exam 2. Functions Arrays Pointers Strings C Files.
Types(1). Lecture 52 Type(1)  A type is a collection of values and operations on those values. Integer type  values..., -2, -1, 0, 1, 2,...  operations.
Primitive variables Android Club types of variables: Primitive single value (starts with uppercase letter) Complex multiple value (starts with.
Topic 3: C Basics CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering University.
Cs2220: Engineering Software Class 3: Java Semantics Fall 2010 University of Virginia David Evans.
CS 139-Programming Fundamentals Lecture 11B - Arrays Adapted from a presentation by Dr. Rahman Fall 2014.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
C Programming Lecture 16 Pointers. Pointers b A pointer is simply a variable that, like other variables, provides a name for a location (address) in memory.
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
1.2 Primitive Data Types and Variables
A: A: double “4” A: “34” 4.
CSC 142 Computer Science II Zhen Jiang West Chester University
11 PART 2 ARRAYS. 22 PROCESSING ARRAY ELEMENTS Reassigning Array Reference Variables The third statement in the segment below copies the address stored.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Week 12 Methods for passing actual parameters to formal parameters.
Lecturer: Nguyen Thi Hien Software Engineering Department Home page: hienngong.wordpress.com Chapter 2: Language C++
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
C is a high level language (HLL)
Array contiguous memory locations that have the same name and type. Note: an array may contain primitive data BUT an array is a data structure a collection.
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives  Pointers  * symbol and & symbol  Pointer operations  Pointer.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Introduction to programming in java Lecture 21 Arrays – Part 1.
Pointers as arrays C++ Programming Technologies. Pointers vs. Arrays Pointers and arrays are strongly related. In fact, pointers and arrays are interchangeable.
C++ Programming Lecture 18 Pointers – Part II The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Objects as a programming concept
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
C Basics.
Chapter 2.
Introduction to the C Language
Review Operation Bingo
Unit-2 Objects and Classes
Introduction to Abstract Data Types
Local Variables, Global Variables and Variable Scope
C Programming Lecture-8 Pointers and Memory Management
C Programming Pointers
Chapter 3 Introduction to Classes, Objects Methods and Strings
Agenda Types and identifiers Practice Assignment Keywords in Java
Presentation transcript:

COMS W3156: Software Engineering, Fall 2001 Lecture #20: C, continued Janak J Parekh

Next class Finish up C discussion C++

Today’s class Continue C Guest lecture at 6

C for the Java programmer Java “ripped off” C –Java widely considered “C with classes” –More like C than C++ for/while, if-then-else, switch (broken) all adopted perfectly from C Operators, ++/--, etc. Functions very similar to methods But no objects!

C’s data types Similar to Java’s lower-case types –char, int, short, long, single, double –no boolean – use 0 or 1 Common practice: #define TRUE 1 C is not strongly typed –int i = ‘c’; –As a matter of fact, chars are just bytes Different structures have different sizes Formal mechanism for references: pointers –Address of structure in machine’s memory!

Pointers (I) Can accomplish similar functionality as references in Java, but far more manual (and flexible) Basically, a class of types that “point” to an arbitrary location in memory Why? –Call-by-value vs. call-by-reference

Pointers (II) “&” operator: get the address of a variable “*” operator: get the value stored at an address Declaring pointers: –int *ip = null; ip is of type “int *” ip can point to something

Pointer examples int x = 7; int *ip = &x; printf(“%d\n”, ip); // What does this print? printf(“%d\n”, *ip); *ip = 9; printf(“%d\n”, *ip); printf(“%d\n”, x);

Pointers: miscellany If ip == 4, and ints are 4 bytes long, what does ip+1 equal? –This is why pointers are “typed” C does not have arrays –Basically consecutive blocks of memory pointed to int a[7]; a == &a[0]; ++a == &a[1];

C’s use of pointers C does not have Strings either –Basically an array of chars (char *) Basically a pointer to a block of memory Char pointers are all over the place C’s loose typing: the meaning of “0” –False –End-of-string character –Null pointer (#define NULL 0)

Administrativia Prototype status D-Day 1 is next Wednesday No homeworks for a while: HW4 assigned on full implementation deadline –We can adjust the end date; do people want this?