Professional Documents
Culture Documents
Pointers
Topic & Structure of Lesson
int counter=100;
counter variable name
value of counter
100
int *ptr;
Memory allocation
10
x560
int *ptr; ptr
ptr=&counter;
x800
#include<stdio.h>
void main() {
int a, *aPtr;
a=100;
aPtr=&a;
printf(“\n The address of a is %p”, &a);
printf(“\n The value contained in aPtr is %p”, aPtr);
printf(“\n The value of a %d and de-referencing
aPtr %d returns the same value”, a,*aPtr);
}
#include<stdio.h>
void main()
{
char var=‘X’; // var a character variable, is declared and initialized to ‘X’
char *charPtr; //charPtr a pointer to a character is declared
charPtr=&var; //charPtr now holds (points to) the address of var
*charPtr=‘Y’; //The value which charPtr points to, is now changed to ‘Y’.
//using * in this manner is called dereferencing a pointer
printf(“\n Value of var now is : %c”,var);
// displays new value ‘Y’
}
Q&A