Chapter 9 Pointers Objectives

Slides:



Advertisements
Similar presentations
An introduction to pointers in c
Advertisements

Data Structures Using C++ 2E
© Janice Regan, CMPT 128, February CMPT 128: Introduction to Computing Science for Engineering Students Pointers.
Pointers Pointer - A pointer is a derived data type; that is it is a data type built from one of the standard types. Its value is any of the addresses.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Pointers.
1 The first step in understanding pointers is visualizing what they represent at the machine level. In most modern computers, main memory is divided into.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Pointers Applications
References Applications of Computer Programming in Earth Sciences Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
Pointers (Continuation) 1. Data Pointer A pointer is a programming language data type whose value refers directly to ("points to") another value stored.
Computer Science: A Structured Programming Approach Using C Masks In many programs, bits are used as binary flags: 0 is off, and 1 is on. To set.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To be able to use the bitwise logical operators in programs ❏ To be able to use.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand design concepts for fixed-length and variable- length strings ❏
Overloading Binary Operators Two ways to overload –As a member function of a class –As a friend function As member functions –General syntax Data Structures.
Computer Science: A Structured Programming Approach Using C1 4-6 Scope Scope determines the region of the program in which a defined object is visible.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To be able to list and describe the six expression categories ❏ To understand.
Data Structures Using C++ 2E Chapter 3 Pointers. Data Structures Using C++ 2E2 Objectives Learn about the pointer data type and pointer variables Explore.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To introduce the structure, union, and enumerated types ❏ To use the type definition.
Spring 2005, Gülcihan Özdemir Dağ Lecture 6, Page 1 BIL104E: Introduction to Scientific and Engineering Computing, Spring Lecture 6 Outline 6.1Introduction.
Topics discussed in this section:
Computer Science: A Structured Programming Approach Using C1 2-7 Input/Output Although our programs have implicitly shown how to print messages, we have.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 14: Pointers.
Chapter 8 Characters and Strings. Objectives In this chapter, you will learn: –To be able to use the functions of the character handling library ( ctype).
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the concept and use of pointers ❏ To be able to declare, define,
POINTERS IN C. Introduction  A pointer is a variable that holds a memory address  This address is the location of another object (typically another.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the relationship between arrays and pointers ❏ To understand the.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic properties and characteristics of external files ❏ To.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Pointers Introduction
© 2016 Pearson Education, Ltd. All rights reserved.
Chapter 7 Text Input/Output Objectives
Chapter 12 Enumerated, Structure, and Union Types Objectives
Introduction to the C Language
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
Chapter 7 Text Input/Output Objectives
FIGURE 4-10 Function Return Statements
More About Objects and Methods
FIGURE 9-5 Integer Constants and Variables
Chapter 8 Arrays Objectives
Topics discussed in this section:
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes
Introduction to the C Language
Using Arrays in C Only fixed-length arrays can be initialized when they are defined. Variable length arrays must be initialized by inputting or assigning.
Introduction to the C Language
FIGURE 4-10 Function Return Statements
4-2 Functions in C In C, the idea of top–down design is done using functions. A C program is made of one or more functions, one and only one of which.
Chapter 4 Functions Objectives
Topics discussed in this section:
Chapter 14 Bitwise Operators Objectives
Chapter 8 Arrays Objectives
Topics discussed in this section:
Lecture 18 Arrays and Pointer Arithmetic
Pointers.
Topics discussed in this section:
Introduction to C++ Programming Language
FIGURE 4-10 Function Return Statements
Topics discussed in this section:
Topics discussed in this section:
Topics discussed in this section:
Pointers Lecture 1 Thu, Jan 15, 2004.
4-2 Functions in C In C, the idea of top–down design is done using functions. A C program is made of one or more functions, one and only one of which.
Chapter 8 Arrays Objectives
C Programming Pointers
FIGURE 4-10 Function Return Statements
Topics discussed in this section:
Pointers and pointer applications
Introduction to Pointers
Introduction to Pointers
Presentation transcript:

Chapter 9 Pointers Objectives ❏ To understand the concept and use of pointers ❏ To be able to declare, define, and initialize pointers ❏ To write programs that access data through pointers ❏ To use pointers as parameters and return types ❏ To understand pointer compatibility, especially regarding pointers to pointers ❏ To understand the role of quality in software engineering Computer Science: A Structured Programming Approach Using C

FIGURE 9-1 Derived Types Computer Science: A Structured Programming Approach Using C

Topics discussed in this section: 9-1 Introduction A pointer is a constant or variable that contains an address that can be used to access data. Pointers are built on the basic concept of pointer constants. Topics discussed in this section: Pointer Constants Pointer Values Pointer Variables Accessing Variables Through Pointers Pointer Declaration and Definition Declaration versus Redirection Initialization of Pointer Variables Computer Science: A Structured Programming Approach Using C

FIGURE 9-2 Character Constants and Variables Computer Science: A Structured Programming Approach Using C

FIGURE 9-3 Pointer Constants Computer Science: A Structured Programming Approach Using C

Note Pointer constants, drawn from the set of addresses for a computer, exist by themselves. We cannot change them; we can only use them. Computer Science: A Structured Programming Approach Using C

Note An address expression, one of the expression types in the unary expression category, consists of an ampersand (&) and a variable name. Computer Science: A Structured Programming Approach Using C

FIGURE 9-4 Print Character Addresses Computer Science: A Structured Programming Approach Using C

A variable’s address is the first byte occupied by the variable. Note A variable’s address is the first byte occupied by the variable. Computer Science: A Structured Programming Approach Using C

FIGURE 9-5 Integer Constants and Variables Computer Science: A Structured Programming Approach Using C

FIGURE 9-6 Pointer Variable Computer Science: A Structured Programming Approach Using C

FIGURE 9-7 Multiple Pointers to a Variable Computer Science: A Structured Programming Approach Using C

Note A pointer that points to no variable contains the special null-pointer constant, NULL. Computer Science: A Structured Programming Approach Using C

Note An indirect expression, one of the expression types in the unary expression category, is coded with an asterisk (*) and an identifier. Computer Science: A Structured Programming Approach Using C

FIGURE 9-8 Accessing Variables Through Pointers Computer Science: A Structured Programming Approach Using C

FIGURE 9-9 Address and Indirection Operators Computer Science: A Structured Programming Approach Using C

FIGURE 9-10 Pointer Variable Declaration Computer Science: A Structured Programming Approach Using C

FIGURE 9-11 Declaring Pointer Variables Computer Science: A Structured Programming Approach Using C

Demonstrate Use of Pointers PROGRAM 9-1 Demonstrate Use of Pointers Computer Science: A Structured Programming Approach Using C

Demonstrate Use of Pointers PROGRAM 9-1 Demonstrate Use of Pointers Computer Science: A Structured Programming Approach Using C

FIGURE 9-12 Uninitialized Pointers Computer Science: A Structured Programming Approach Using C

FIGURE 9-13 Initializing Pointer Variables Computer Science: A Structured Programming Approach Using C

PROGRAM 9-2 Fun with Pointers Computer Science: A Structured Programming Approach Using C

PROGRAM 9-2 Fun with Pointers Computer Science: A Structured Programming Approach Using C

PROGRAM 9-2 Fun with Pointers Computer Science: A Structured Programming Approach Using C

FIGURE 9-14 Add Two Numbers Using Pointers Computer Science: A Structured Programming Approach Using C

Add Two Numbers Using Pointers PROGRAM 9-3 Add Two Numbers Using Pointers Computer Science: A Structured Programming Approach Using C

Add Two Numbers Using Pointers PROGRAM 9-3 Add Two Numbers Using Pointers Computer Science: A Structured Programming Approach Using C

FIGURE 9-15 Demonstrate Pointer Flexibility Computer Science: A Structured Programming Approach Using C

Using One Pointer for Many Variables PROGRAM 9-4 Using One Pointer for Many Variables Computer Science: A Structured Programming Approach Using C

Using One Pointer for Many Variables PROGRAM 9-4 Using One Pointer for Many Variables Computer Science: A Structured Programming Approach Using C

FIGURE 9-16 One Variable with Many Pointers Computer Science: A Structured Programming Approach Using C

Using A Variable with Many Pointers PROGRAM 9-5 Using A Variable with Many Pointers Computer Science: A Structured Programming Approach Using C

Using A Variable with Many Pointers PROGRAM 9-5 Using A Variable with Many Pointers Computer Science: A Structured Programming Approach Using C