0% found this document useful (0 votes)
109 views7 pages

Pointer To Pointer PDF

This document discusses pointers in C, including pointer to pointer, pointer type and arithmetic, pointers to constants, constant pointers, and combinations of constant and pointer qualifiers. It explains that a pointer to pointer variable stores the address of another pointer variable. Pointer type determines the data type being pointed to (int, char, float). Pointer arithmetic allows treating a pointer as an array index. Pointers can be declared as constant to prevent changing what is pointed to, or as a constant pointer to prevent changing the pointer itself.

Uploaded by

Shado H
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
109 views7 pages

Pointer To Pointer PDF

This document discusses pointers in C, including pointer to pointer, pointer type and arithmetic, pointers to constants, constant pointers, and combinations of constant and pointer qualifiers. It explains that a pointer to pointer variable stores the address of another pointer variable. Pointer type determines the data type being pointed to (int, char, float). Pointer arithmetic allows treating a pointer as an array index. Pointers can be declared as constant to prevent changing what is pointed to, or as a constant pointer to prevent changing the pointer itself.

Uploaded by

Shado H
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Pointers in C

POINTER TO POINTER, POINTER TYPE & POINTER


ARITHMETIC

28‐Jun‐20 ARJ 1
What is Pointer to Pointer?
Consider the following
statements… x ptr1        ptr2
- int x = 10;
- int *ptr1; // pointer variable 10 3456  4000 

- ptr1 = &x;
3456 4000       5000
- int **ptr2; // pointer to pointer variable
- ptr2 = &ptr1;

28‐Jun‐20 ARJ 2
Pointer Type & Arithmetic
Data type - int * ptr;
◦ int – 4 bytes ptr = &x;
◦ char – 1 byte
◦ float – 4 bytes printf(“%d”, *ptr);
Consider the declaration –
int x = 1030;
Byte4 Byte3 Byte2 Byte1
00000000 00000000 00000100 00000110
6003 6002 6001 6000

28‐Jun‐20 ARJ 4
Pointer to a Constant
const int x = 3; // assigning to x is legal only at declaration

const int * p = &x;


OR
int const * p = &x; // same as const int * p

*p = 4; //assignment of read-only location '*p'

28‐Jun‐20 ARJ 6
Constant Pointer
Suppose we want to change *p, but not p itself

int * const p = &x;

*p=4. // legal statement

p =&y; // illegal

28‐Jun‐20 ARJ 7
Constant Pointer to a Constant
We want to prevent changing either where the pointer points,
or the value it points at…

const int * const p = &x;

C:\TurboC++\Disk\TurboC3\BIN\ptr16.cpp

28‐Jun‐20 ARJ 8
Possible combinations of constant and
pointer
The same principle applies to pointers to pointers (to
pointers to pointers…).

28‐Jun‐20 ARJ 9

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy