Pointers C-Language

Only available on StudyMode
  • Topic: Pointer, C, Memory address
  • Pages : 41 (5501 words )
  • Download(s) : 196
  • Published : June 1, 2013
Open Document
Text Preview
Sir Syed University of Engineering and Technology.

Computer Programming & Problem Solving ( CPPS )

Pointers
Chapter No 7

Compiled By:
Sir Syed University of Engineering & Technology Computer Engineering Department University Road, Karachi-75300, PAKISTAN

Muzammil Ahmad Khan Muhammad Kashif Shaikh

SPRING 2009

Course Instructors
? Muhammad Kashif Shaikh
Assistant Professor, CED Room Number: BS-04 Tel: 111-994-994, Section A, B Ext. 326 (Computer, Batch 2009) mukhan@ssuet.edu.pk mkshaikh@ssuet.edu.pk

? Muzammil Ahmad Khan
Assistant Professor, CED Room Number: BS-04 Tel: 111-994-994, Section C, D CPPS - Chapter No 7 Pointers

Ext. 326 (Computer, Batch 2009)

2

Computer Programming and Problem Solving

1

Sir Syed University of Engineering and Technology.
SPRING 2009

Course Instructors
? Zeeshan Karim
Lecturer, CED Room Number: Tel: 111-994-994, Section E muhzahma@ssuet.edu.pk AG-06 Ext. 301 (Computer, Batch 2009)

CPPS - Chapter No 7 Pointers

3

SPRING 2009

Course Books
? Text Book:
Turbo C Programming For The PC ( Revised Edition )
By Robert Lafore

? Reference Books:
1. 2. Let Us C
By Yashavant Kanetkar

C By Dissection ( Second Edition )
By Al Kelly & Ira Pohl

CPPS - Chapter No 7 Pointers

4

Computer Programming and Problem Solving

2

Sir Syed University of Engineering and Technology.
SPRING 2009

Course Website
?http://www.ssuet.edu.pk/courses/ce102/c ?http://taimoor/ce102/c

CPPS - Chapter No 7 Pointers

5

SPRING 2009

Marks Distribution
? Mid Term _______________________________ ? Assignments + Class Performance + Behavior 25

Class Test + Project _______________________ 15 ? Semester Final Paper______________________ 60 ? Total Marks _____________________________ 100

CPPS - Chapter No 7 Pointers

6

Computer Programming and Problem Solving

3

Sir Syed University of Engineering and Technology.
SPRING 2009

Contents
? Pointer Overview ? Why are Pointers used? ? Returning Data from Functions ? Passing Value to a Function ? Passing Addresses to a Function ? Defining Pointer Variables ? Pointers without Functions ? Pointers and Arrays ? Pointers and Strings CPPS - Chapter No 7 Pointers

7

SPRING 2009

Overview
? Pointers are regarded by most people as one of
the most difficult topics in C Language. ? Pointer provides a way of accessing a variable or a more complex kind of data, such as an array without referring to the variable directly. ? Pointers are variables that contain memory addresses as their values. ? The mechanism used for this is the address of the variable. In effect, the address acts as an intermediary between the variable and the program accessing it. CPPS - Chapter No 7 Pointers

8

Computer Programming and Problem Solving

4

Sir Syed University of Engineering and Technology.
SPRING 2009

Why are Pointers used ?
? Pointers are used in situations when passing
actual values is difficult or undesirable. 1. To return more than one value from a function. 2. To pass arrays and strings more conveniently from one function to another. 3. To manipulate arrays more easily by moving pointers to them, instead of moving the arrays themselves.

CPPS - Chapter No 7 Pointers

9

SPRING 2009

Why are Pointers used ?
4. To create complex data structures, such as linked
list and binary tress, where one data structures must contain references to other data structures. 5. To communicate information about memory as in the function malloc( ), which returns the location of free memory by using a pointers. 6. “ A pointer constant is an address; a pointer variable is a place to store addresses.”

CPPS - Chapter No 7 Pointers

10

Computer Programming and Problem Solving

5

Sir Syed University of Engineering and Technology.
SPRING 2009

Pointers
? Pointer is a variable that contains the address of
a variable
C …
172 173

7
174

3
175

4
176 177 178 179 180 181

…...
tracking img