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

Understanding Pointers in C Programming: Declaration, Address, and Dereferencing, Slides of Computer Fundamentals

An introduction to pointers in c programming, explaining how to declare pointers, get the address of a variable, and dereference a pointer. Pointers are powerful tools that provide faster access and are used in various ways, including simulating call-by-reference, accessing array information, and dynamic memory allocation.

Typology: Slides

2011/2012

Uploaded on 07/31/2012

karthik
karthik 🇮🇳

4.6

(16)

95 documents

1 / 18

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Today’s Lecture
Pointers
Declaring a pointer
Getting address of a variable
Dereferencing a pointer
Pointers and arrays
Pointers and functions
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download Understanding Pointers in C Programming: Declaration, Address, and Dereferencing and more Slides Computer Fundamentals in PDF only on Docsity!

Today’s Lecture

 Pointers

  • Declaring a pointer
  • Getting address of a variable
  • Dereferencing a pointer

 Pointers and arrays

 Pointers and functions

Pointers

 Pointers

  • Powerful and provide faster access

 C uses pointers in three different ways

  • Simulate call-by-reference
  • Access information stored in arrays (Close

relationship with arrays and strings)

  • Dynamic Memory Allocation

 Data structures that can grow or shrink

Address of a variable &

int x = 10;

printf("Address of x = %p\n", &x);

Output:

Address of x = 0040FE

%p outputs the memory location as a hexadecimal integer

Pointers

x

0040FE

Location Address of x

Declaring a pointer

int *myPtr ;

Variable myPtr is pointer to an integer

* means pointer to

Declaring pointers

int *ptr1 , *ptr2 , *ptr3 ;

Declaring pointers

*int ptr , x , a [ 10 ] ;

Declaring Pointers

double *dPtr ;

char *cPtr ;

float *fPtr;

Getting address of a variable

xPtr = &x;

 xPtr gets address of x

 xPtr “points to” x

Pointer example

xPtr

x

5

xPtr

500000 600000

x

600000 5

Address of x

is value of

xPtr

Dereferencing Operator *

*ptr is read as

“The value of whatever ptr points to”

*z = xPtr + 2 ;

Dereferencing a pointer

Accessing the variable

pointed to by a pointer