-
Memory Location
Hi friends this is my first posting . i greet you all :) .
my query :
main()
{
int a=10;
printf("%x",&a);
printf("%x",&a++);
}
what should i write in the red portion so as to get the next memory location after
’a’ without using pointers . :confused:
Hope somebody solves my query .
Bye
Som
-
That should suffice.
Quzah.
-
Hi Quzah ,
thanx for your reply , but how do i get the next --next-- next addresses if i put the printf command in a loop .
Som
-
I fail to see what this proves you can do, if you can do it without pointers
Answer snipped
-
It should be trivial. Think about it for a bit. How do you normally work your way through an array? How do you do it if you want to skip ahead by two or three or N each time? Apply that same logic to this problem.
Post your attempt, and we'll give you hints. Or, if you wait around long enough, someone will doubtless show up and do the whole thing for you. It never fails.
Quzah.
-
thanx Quzah for the encouragement , it really pegged me to go and get the ans .:
printf("\n%x",&a + i+sizeof( a ));
with thanx
Som
-
Or you could always do:
Code:
for( i = 0; i < foo; i++ )
printf("%x\n", &a + (i*sizeof(a)) );
This way you don't have to add sizeof( a ) to what you have down as i in your version.
Quzah.