C language issues CSC 172 SPRING 2002 EXTRA LECTURE.

Slides:



Advertisements
Similar presentations
Lectures 10 & 11.
Advertisements

Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
Pointer Variables The normal variables hold values. For example, int j; j = 2; Then a reference to j in an expression will be identified with the value.
Structures Spring 2013Programming and Data Structure1.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Pointers Pointer Arithmetic Dale Roberts, Lecturer Computer.
This Time Pointers (declaration and operations) Passing Pointers to Functions Const Pointers Bubble Sort Using Pass-by-Reference Pointer Arithmetic Arrays.
Kernighan/Ritchie: Kelley/Pohl:
C Pointers Systems Programming Concepts. PointersPointers  Pointers and Addresses  Pointers  Using Pointers in Call by Reference  Swap – A Pointer.
1 Pointers A pointer variable holds an address We may add or subtract an integer to get a different address. Adding an integer k to a pointer p with base.
6/10/2015C++ for Java Programmers1 Pointers and References Timothy Budd.
CS100A, Fall 1997, Lecture 241 CS100A, Fall 1997 Lecture 24, Tuesday 25 November (There were no written notes for lecture 23 on Nov. 20.) Data Structures.
C and Data Structures Baojian Hua
Introduction to C Programming CE
0 Chap. 5 Pointers and Arrays 5.1Pointers and Adresses 5.2Pointers and Function Arguments 5.3Pointers and Arrays 5.4Address Arithmetic 5.5Character Pointers.
Pointers and Arrays C and Data Structures Baojian Hua
Heterogeneous Structures 4 Collection of values of possibly differing types 4 Name the collection; name the components 4 Example: student record harveyC.
Pointers: Part I. Why pointers? - low-level, but efficient manipulation of memory - dynamic objects  Objects whose memory is allocated during program.
Review on pointers and dynamic objects. Memory Management  Static Memory Allocation  Memory is allocated at compiling time  Dynamic Memory  Memory.
CS113 Introduction to C Instructor: Ioannis A. Vetsikas Lecture 6 : September 6.
1 Variables, Pointers, and Arrays Professor Jennifer Rexford COS 217
Programming Pointers. Variables in Memory x i c The compiler determines where variables are placed in memory This placement cannot.
Programming in C Pointer Basics.
Pointers CSE 2451 Rong Shi.
Engineering Computing I Chapter 6 Structures. Sgtructures  A structure is a collection of one or more variables, possibly of different types, grouped.
Pointer Data Type and Pointer Variables. Objectives: Pointer Data Type and Pointer Variables Pointer Declaration Pointer Operators Initializing Pointer.
Chapter 0.2 – Pointers and Memory. Type Specifiers  const  may be initialised but not used in any subsequent assignment  common and useful  volatile.
CS-1030 Dr. Mark L. Hornick 1 Pointers are fun!
0 4.3 First Large Coding Example: calculator (kr76-79): Example of a Stack Machine Description of the problem and approach Pseudo code Flat implementation.
Week 6 - Wednesday.  What did we talk about last time?  Exam 1!  And before that…  Review!  And before that…  Arrays and strings.
19&20-2 Know how to declare pointer variables. Understand the & (address) and *(indirection) operators. Dynamic Memory Allocation Related Chapter: ABC.
Weeks 5-6 Pointers and Arrays Basic pointer type Pointers and Arrays Address arithmetic Pointer Arrays User-defined data types Structures Unions Pointers.
Pointers Programming Applications. Pointer A pointer is a variable whose value is a memory address representing the location of the chunk of memory on.
POINTERS.
Review 1 List Data Structure List operations List Implementation Array Linked List.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
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.
Lecture 17: The Last Puzzle Piece with Functions.
Pointers It provides a way of accessing a variable without referring to its name. The mechanism used for this is the address of the variable.
Lecture 10: 2/17/2003CS148 Spring CS148 Introduction to Programming II Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
What we will cover A crash course in the basics of C “Teach yourself C in 21 days”
Engineering Computing I Chapter 5 Pointers and Arrays.
Pointer Tran, Van Hoai. Pointers and Addresses  Pointer: group of cells (2,4 cells) Variable: group of cells Pointer is also a variable  Each cell (or.
17-Feb-02 Sudeshna Sarkar, CSE, IT Kharagpur1 Arrays and Pointers Lecture 17 18/2/2002.
CSci 162 Lecture 6 Martin van Bommel. Functions on Structures Rather than pass a copy of structure to a function, or return a copy back as the function.
Structures CSE 2031 Fall March Basics of Structures (6.1) struct point { int x; int y; }; keyword struct introduces a structure declaration.
Lecture 20-something CIS 208 Wednesday, April 27 th, 2005.
Chapter 5 Pointers and Arrays Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh.
CE-2810 Dr. Mark L. Hornick 1 “Classes” in C. CS-280 Dr. Mark L. Hornick 2 A struct is a complex datatype that can consist of Primitive datatypes Ints,
CS 100Lecture 221 Announcements P5 due Thursday Final Exam: Tuesday August 10, 8AM - 10AM, Olin 155 Want references? Remember to drop off a picture and.
1 Structures & Unions. 2 User-Defined Types C provides facilities to define one’s own types. These may be a composite of basic types ( int, double, etc)
Object Oriented Programming Lecture 2: BallWorld.
Arrays and Pointers (part 1) CSE 2031 Fall July 2016.
CSC 215 Pointers and Arrays. Pointers C provides two unary operators, & and *, for manipulating data using pointers The operator &, when applied to a.
Lecture 5 Pointers 1. Variable, memory location, address, value
INC 161 , CPE 100 Computer Programming
CSC 172 DATA STRUCTURES.
Homework / Exam Continuing K&R Chapter 6 Exam 2 after next class
Lecture 9 Structure 1. Concepts of structure Pointers of structures
Instructor: Ioannis A. Vetsikas
Pointers & Functions.
Programming in C Pointer Basics.
Programming in C Pointer Basics.
Pointers Lecture 2 Tue, Jan 24, 2006.
CSE 3302 Programming Languages
Variables, Pointers, and Arrays
Pointers & Functions.
Programming in C Pointer Basics.
Arrays and Pointers CSE 2031 Fall May 2019.
Structures EECS July 2019.
Arrays and Pointers CSE 2031 Fall July 2019.
Presentation transcript:

C language issues CSC 172 SPRING 2002 EXTRA LECTURE

C and JAVA For the most part, they are very similar However one major difference is the syntax of indirection JAVA hides indirection (references) C makes indirection explicit (pointers)

Pointers in C char c; // in C any byte can be a char If c is a char and p is a pointer that points to it The unary operator “&” gives the address of an object p = &c ; p c

Indirection/dereferencing The unary operator “*” is the dereferencing operator int x = 1, y = 2, z [10]; int *ip; // ip is a pointer to int ip = &x; // ip now points to x y = *ip ; // y is now 1 *ip = 0; // x is now zero ip = &z[0]; // ip now points to z[0];

Pointers and function args C passes arguments to functions by value void swap (int x, int y) { /* does not work */ int temp; temp = x; x = y; y = temp; }

We have to pass in pointers swap(&a,&b); void swap (int *px, int *py) { /* works */ int temp; temp = *px; *px = *py; *py = temp; } In caller: a: b: In swap: py: px:

Pointers and Arrays int a[10]; a: a[0]a[1]a[9]

Pointers and Arrays int *pa; pa = &a[0]; a: a[0]a[1]a[9] pa: pa+1 pa+2 pa = a ; // equivalent

Structures Back in the old days, before classes and OO, when dinosaurs had to program, they wrote? struct point { int x; int y; }

Using structs Syntax: structure-name.member struct point pt; pt.x=3; pt.y=4;

Pointers to structs struct point origin, *pp; pp = &origin; Then, the following are equivalent origin.x (*pp).x pp->x