Pointer Lecture 2 Course Name: High Level Programming Language Year : 2010.

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

C++ crash course Class 10 practice problems. Pointers The following function is trying to swap the contents of two variables. Why isnt it working? void.
C’ POINTERS Basic&Examples. Q:what’s the output? int array[] = { 45, 67, 89 }; int *array_ptr = array; printf(" first element: %i\n", *(array_ptr++));
Lectures 10 & 11.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 16P. 1Winter Quarter Strings Lecture 16.
Introduction to Programming Lecture 15. In Today’s Lecture Pointers and Arrays Manipulations Pointers and Arrays Manipulations Pointers Expression Pointers.
1 Chapter Thirteen Pointers. 2 Pointers A pointer is a sign used to point out the direction.
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.
Data Structures (Second Part) Lecture 2 : Pointers Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University.
Programming and Data Structure
© Janice Regan, CMPT 128, February CMPT 128: Introduction to Computing Science for Engineering Students Pointers.
Introduction to Programming Lecture 39. Copy Constructor.
Lecture 20 Arrays and Strings
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.
Current Assignments Homework 5 will be available tomorrow and is due on Sunday. Arrays and Pointers Project 2 due tonight by midnight. Exam 2 on Monday.
Array_strcpy void array_strcpy(char dest[], char src[]) { int i = 0; while (src[i] != '\0') { dest[i] = src[i]; i++; } dest[i] = '\0'; }
Week 8 Arrays Part 2 String & Pointer
Pointers in C Rohit Khokher
1 C++ Syntax and Semantics The Development Process.
By Senem Kumova Metin 1 POINTERS + ARRAYS + STRINGS REVIEW.
This Time Pointers (declaration and operations) Passing Pointers to Functions Const Pointers Bubble Sort Using Pass-by-Reference Pointer Arithmetic Arrays.
Engineering Problem Solving With C++ An Object Based Approach Chapter 9 Pointers and Creating Data Structures.
Pointers Ethan Cerami Fundamentals of Computer New York University.
Arrays Hanly - Chapter 7 Friedman-Koffman - Chapter 9.
Pointers. Topics Pointers Pointer Arithmetic Pointers and Arrays.
Introduction to Data Structure, Spring 2007 Slide- 1 California State University, Fresno Introduction to Data Structure C Programming Concepts Ming Li.
1 More on Pointers. 2 Reminder 3 Pointers Pointer is a variable that contains the address of a variable Here P is said to point to the variable C C 7.
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.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
Programming Pointers. COMP104 Lecture 32 / Slide 2 Pointers l Pointers are objects whose values are the locations of other objects l Pointers are memory.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 14P. 1Winter Quarter Pointers Lecture 14.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 14P. 1Winter Quarter Pointers Lecture 14.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 12: Pointers continued, C strings.
EGR 2261 Unit 8 One-dimensional Arrays  Read Malik, pages in Chapter 8.  Homework #8 and Lab #8 due next week.  Quiz next week.
Week 6 - Wednesday.  What did we talk about last time?  Exam 1!  And before that…  Review!  And before that…  Arrays and strings.
CPSC 252 Dynamic Memory Allocation Page 1 Dynamic memory allocation Our first IntVector class has some serious limitations the capacity is fixed at MAX_SIZE.
1 Pointers and Strings Chapter 5 2 What You Will Learn...  How to use pointers Passing arguments to functions with pointers See relationship of pointers.
Problem Solving and Program Design in C (5th Edition) by Jeri R. Hanly and Elliot B. Koffman Chapter 6 (Pointers) © CPCS
Spring 2005, Gülcihan Özdemir Dağ Lecture 6, Page 1 BIL104E: Introduction to Scientific and Engineering Computing, Spring Lecture 6 Outline 6.1Introduction.
 2000 Deitel & Associates, Inc. All rights reserved Introduction Pointers –Powerful, but difficult to master –Simulate call-by-reference –Close.
Pointers A pointer is a variable that contains a memory address as it’s value. The memory address points to the actual data. –A pointer is an indirect.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 3 – August 28, 2001.
 Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create.
Weeks 5-6 Pointers and Arrays Basic pointer type Pointers and Arrays Address arithmetic Pointer Arrays User-defined data types Structures Unions Pointers.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 13: Data structures in C.
1 Homework HW4 due today HW5 is on-line Starting K&R Chapter 5 –Skipping sections for now –Not covering section 5.12.
Pointers *, &, array similarities, functions, sizeof.
Lecture 7 Pointers & Refrence 1. Background 1.1 Variables and Memory  When you declare a variable, the computer associates the variable name with a particular.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
Welcome to CISC220H Data Structures in C++ sakai.udel.edu Office Hours: Mon/Wed 3:30PM - 4:30PM TA: Adnan Ozsoy.
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.
1 CSC103: Introduction to Computer and Programming Lecture No 24.
Lecture – Pointers1 C++ Pointers Joseph Spring/Bob Dickerson School of Computer Science Operating Systems and Computer Networks Based on notes by Bob Dickerson.
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
Lecture 10: 2/17/2003CS148 Spring CS148 Introduction to Programming II Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
1 Object-Oriented Programming Using C++ A tutorial for pointers.
Pointers and Arrays An array's name is a constant whose value is the address of the array's first element. For this reason, the value of an array's name.
C programming---Pointers The first step: visualizing what pointers represent at the machine level. In most modern computers, main memory is divided into.
Welcome to CISC220 Data Structures in C++ sakai.udel.edu Office Hours: Tues 3PM - 4PM / Thurs 1PM - 2PM TA: David.
P OINTERS A pointer is an address All data is stored in memory in some location that is indexed with an address Can refer to variables by name or by memory.
Introduction to Programming Lecture 12. Today’s Lecture Includes Strings ( character arrays ) Strings ( character arrays ) Algorithms using arrays Algorithms.
Object Oriented Programming Lecture 2: BallWorld.
Basic Concepts:- Invalid use of Address Operator &75 &(‘a’) &(a+b)
C++ Programming Lecture 18 Pointers – Part II The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
C++ Pointers and Strings
C Programming Lecture-8 Pointers and Memory Management
CSCE 206 Lab Structured Programming in C
C++ Pointers and Strings
Presentation transcript:

Pointer Lecture 2 Course Name: High Level Programming Language Year : 2010

3 Learning Outcomes At the end of this lecture, students are capable of: Using pointer in C Language through an understanding of microprocessor architecture

4 Outline Material Pointer and Architecture Computer Usage Of Pointer Variable Pointer

5 Pointer and Arsitektur Komputer Pointer is an address!!! 33 k ? Uninitialized integer pointer (pointing to a random location) Null pointer (pointing to a NULL location or to a grounding location “0”) integer pointer (pointing to a variable k)

6 Pointer and Architecture Computer Function of pointer: –It can refer to one object now and a different object later Generally, a pointer in C program functions to: –Return two or more value from a function –Operate on data type string –Operate on arrays and struct –Data structure that changes size (next week)

7 Usage Of Pointer int x = 10; int *p; p = &x; *p = 20; Pointer declaration to data type integer & is an address operator that takes the address of x * dereference operator takes value from p

8 Usage Of Pointer int x = 10; int *p; p = &x; p takes the address of the variable x p x10

9 Usage Of Pointer int x = 10; int *p; p = &x; *p = 20; *p is the value inside the address p p x20

Conclusions Pointer variable contains address, not data value, always remember that! Pointer refers only to one particular object at one time, though later, it can be altered to different object. Dereference Pointer is used to access a content of a particular memory allocation. 10

11 Topic For Next Week Variable Pointer –Assignment: Read book of “CppEssentials.pdf” chapter 5 pages 65 until 79. –Do the following exercises (taken from “exercises” page 80 of book “CppEssentials.pdf”): 1. Define a function to input a list of names and store them as dynamically-allocated strings in an array, and a function to output them: void ReadNames (char *names[], const int size); void WriteNames (char *names[], const int size);

12 Topic For Next Week Continued. Write another function which sorts the list using bubble sort: void BubbleSort(char *names[], const int size); Bubble sort involves repeated scans of the list, where during each scan adjacent items are compared and swapped if out of order. A scan that involves no swapping indicates that the list is sorted.

13 Topic For Next Week 2. Rewrite the following function using pointer arithmetic: char* ReverseString (char *str) { int len = strlen(str); char *result = new char[len + 1]; for (register I = 0; I < len; ++i) result[i] = str[len – i – 1]; result[len] = ‘\0’; return result; }