Pointers II-189
The value of ‘v’ is
10 and it is stored at location 4060. Address of ‘v’ 4060 is assigned to variable ‘p’.
Address of pointer variable ‘p’ is 4062. Here, ‘p’ is pointer type variable, which points to the variable
‘v’. Hence, it must be declared as int v=10 and pointer variable as int *p;.
6. Prove that pointer of any data type requires two bytes.
Ans: The float variable requires 4 bytes of memory for storage, but pointer to a float requires only
2 bytes, as it stores the address of a float variable, which is an unsigned integer.
Similarly, the integer variable requires 2 bytes of memory for storage, but integer pointer to a float
requires only 2 bytes, as it stores the address of a float variable that is an unsigned integer.
Run the following program and verify the memory requirement to integer and float pointer.
4061
4060
v
10
Figure 9.1 Variable Addresses and Value
void main()
{
float a;
float *p;
int b,*pa;
clrscr();
p=&a;
pa=&b;
printf("
size of a=%d size of p=%d",sizeof(a), sizeof(p));
printf("
Address of a=%u and with pointer address of a=%u",&a,
p);
printf("
size of b=%d size of pa=%d",sizeof(b), sizeof(pa));
getche();
}
OUTPUT:
size of a=4 size of p=2
Address of a=65486 and with pointer address of a=65486
size of b=2 size of pa=2
Explanation: Memory required for floating and integer numbers are 4 and 2 bytes, respectively.
However, memory required to pointers of any data type is 2 bytes.
7. Explain the effect of ++ and –– operators with pointer of all data type.
Ans: Consider the following pointer declaration.
int *x;
++ and −− operators increment the normal variables, but when applied to a pointer of any data type they
point to the immediate next and previous memory locations.
M09_ITL-ESL4791_02_SE_C09.indd 189 12/22/2012 5:04:02 PM