Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Pointers Part 4-Fundamentals of Computer-Lecture Slides, Slides of Computer Fundamentals

The course covers important and advance elements of C and C plus plus programming language. This course provides the student with the skills required to design, code, and test and execute programs of simple to intermediate complexity. It includes: Pointers, Arrays, Elements, Arguments, Strings, System, Data, Structures, Integer, Declaration, Relationship

Typology: Slides

2011/2012

Uploaded on 07/31/2012

karthik
karthik 🇮🇳

4.6

(16)

95 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Pointers)and)Arrays)
) )
) )
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Pointers Part 4-Fundamentals of Computer-Lecture Slides and more Slides Computer Fundamentals in PDF only on Docsity!

Pointers and Arrays

What are pointers for?

  • Here are some common uses:
    • Accessing array elements
    • Passing arguments to a function when the function needs to modify

the original argument

  • Passing arrays and strings to functions
  • Obtaining memory from the system
  • Creating data structures such as linked lists

Declaration of a Pointer Variable

y [ 0 ] (^) [0]

[1]

[2]

[3]

[4]

[5]

[6]

[7]

[8]

[9]

yptr

int y [ 10 ] ;

int *yptr ;

yptr = y ;

yptr is a pointer to integer

int y [ 10 ] ;

int *yptr ;

yptr = y ;

yptr ++ ;

The Relationship Between

Pointers and Arrays

  • Element b[ 3 ]
    • Can be accessed by *( bPtr + 3 )
      • Where n is the offset. Called pointer/offset notation
    • Can be accessed by bptr[ 3 ]
      • Called pointer/subscript notation
      • bPtr[ 3 ] same as b[ 3 ]
    • Can be accessed by performing pointer arithmetic on the array

itself

*( b + 3 )

Pointer Expressions and Pointer Arithmetic

  • Arithmetic operations can be performed on

pointers

  • Increment/decrement pointer (++ or --)
  • Add an integer to a pointer( + or += , - or -=)
  • Pointers may be subtracted from each other
  • Operations meaningless unless performed on an array
  • Subtracting pointers
    • Returns number of elements from one to the other. If vPtr2 = v[ 2 ]; vPtr = v[ 0 ];
    • vPtr2 - vPtr would produce 2
  • Pointer comparison ( <, == , > )
    • See which pointer points to the higher numbered array

element

  • Also, see if a pointer points to 0

Pointer Expressions and Pointer Arithmetic