



















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Dr. Mehandi Nandakumar delivered this lecture at Baddi University of Emerging Sciences and Technologies for Introduction to Computer Programming course. Its main points are: Pointer, Memory, Address, C, C , Dynamic, Memory, Allocation, Float, Variable, Characters
Typology: Slides
1 / 59
This page cannot be seen from the preview
Don't miss anything!




















































Points to an item
-^
Holds the memory address of the item
-^
Has its own memory storage
-^
Occupies space in memory
-^
Hence can itself be accessed too
-^
Allows C/C++ to support dynamic memory allocation
-^
If
x^
contains the address of
y
,^ x
is said to “point to”
y
Pointer variables are declared as
*type *var-name;* e.g.
int *p;
pointer p contains the memory address of an int variable
float *fl;
points to a float variable
Pointer Operators
-^
Pointer Operators
Pointers
int
a=1,
b=2,
*p;
-^
p=&a;
//p
is
assigned
the
address
of
a
b=p;*
//b
is
assigned
the
value
pointed
to
by
p
p
a
b=p*
b=a
a^
b^
p
a^
b^
p
a^
b^
p
int main(){
*int balance;int balptr;int value;balance
balptr
= &balance;
value
*= balptr;
cout << "balance is: " << value << '\n';cout << "Memory address where balance is stored is: ”
<< balptr << endl; return 0;
}
Pointer Operators
bytes according to base type.
int *p;double f;// ...p = &f; // ERROR
Base Type
int p;int x = 12;p=&x;cout << x << endl;//Assign a value to the location pointed to by pp = 101;cout << x << endl;
//what is value of x?
cout << *p << endl;cout << p << endl;cout << &x << endl;
Assigning Values Through a Pointer
(*p)++;
//increment value to the location pointed to by p
int main(){
*int p, num;p^
= # p = 454;cout << num << ' ';(p)++; /*
*parentheses are necessary because * operatorhas lower precedence than ++operator /
cout << num << ' ';(p) - -;cout << num << '\n';return 0;*
}^
//Output?
Assigning Values Through a Pointer
//Output is 454 455 454
Assigning Values Through a Pointer
address 4000
// now p1 will be 4001
next character.
decrease by length of base type.
Pointer Arithmetic
base type).
Pointer Arithmetic
pointers and arrays.
Pointers and Arrays
Pointers and Arrays