0% found this document useful (0 votes)
47 views

UNIT#3 Pointers: by Abhishek Verma

Pointer is a variable that stores the address of another variable. Pointers contain the address of the variable they are pointing to. There are pointer constants, which are addresses that exist on their own and cannot be changed, and pointer variables, which store addresses and can be changed. The & operator is used to get the address of a variable and assign it to a pointer variable. The * operator is used to dereference a pointer and access the value stored at the address it contains.

Uploaded by

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

UNIT#3 Pointers: by Abhishek Verma

Pointer is a variable that stores the address of another variable. Pointers contain the address of the variable they are pointing to. There are pointer constants, which are addresses that exist on their own and cannot be changed, and pointer variables, which store addresses and can be changed. The & operator is used to get the address of a variable and assign it to a pointer variable. The * operator is used to dereference a pointer and access the value stored at the address it contains.

Uploaded by

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

UNIT#3

POINTERS

By Abhishek Verma
Outline
 Features of pointers
 Pointer declaration
 Pointers and arrays
 Pointers and strings
Features of pointers
 Topics discussed in this section
 Pointer Constants
 Pointer Values
 Pointer Variables
 Accessing Variables Through Pointers
Pointer

Note

Pointer is nothing but a variable which stores


address of memory location, where that variable is
stored.
Pointer

Note

int a;
Address of a = &a
Value at address (&a) = *(&a)
Address and Indirection Operators

Inverse
& *
Character Constants and variables

Character ‘\n’ Variable


Constants . name
.
. aChar 14650
‘A’ A

‘G’ Starting
‘X’ Value address
.
.
‘a’
‘g’
‘z’ System
Memory
(RAM)
Pointer Constants
‘\n’ Variable
Character 00000
. name
Constants .
.
14645
.
aChar 14650 14650
‘A’ A
14653
‘G’
.
‘X’
Starting .
.
address .
.
.
‘a’
1048575
‘g’
‘z’ System
Memory
(RAM)
Pointer Constants

Note

Pointer constants, drawn from the set of addresses for a


computer, exist by themselves. We cannot change them;
we can only use them.
Pointer Constants

Note

Address of a variable can be accessed using the special


character ampersand (&) before variable name:
&aChar
Printing Character Address

//Print character address


#include<stdio.h>

int main () 142300


a A
{ 142300 142301
//Declaration 143001 b Z
char a=‘A’, b=‘Z’;
printf(“%p\n %p\n”, &a, &b);
}
Output
Note:
• Both a and b variables are of type char, and char takes 1 Byte in memory (Memory is Byte
addressable, i.e. a block is of a Byte.) System
• By using & before variables a and b, the address of variables, where they are stored in Memory
memory are printed. (RAM)
Pointer Constants

Note

A variable’s address is the first byte occupied


by the variable.
Integer Constants and Variables

Integer . Variable
Constants . name
.
. aInt 14650
-123 -123
14654 Starting
-122
. 14658 address
bInt 151
. 14662
.
151
152
. System
Memory
(RAM)
Pointer Variable

aInt -123
aInt -123 14650

ptr_a= &a Address of


variable a

ptr_a
ptr_a 14650
Pointer
variable

Physical representation Logical representation

You might also like