954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

pointers, hexaceimal to decimal conversion

int main(){

int near * ptr=( int *)0XFFFF;
ptr++;
ptr++;
printf(“%p”,ptr);


return 0;
}

Output:0003
why the op is 3 and how to convert 0XFFFF into its decimal equivalent?

shuchi0113
Newbie Poster
2 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

Well, this goes back to 16-bit addressing (as revealed by your use of near).
In 16 bits, the size of an int (being 16 bits) is 2 bytes.
You increment it twice. But the compiler knows it's an int pointer, so it increments it by 2 each time.
So you're adding 4 to a value already holding 0xFFFF. Adding 1 to 0xFFFF in 16 bits rolls over to zero. What do you figure you have left?

DeanMSands3
Junior Poster
185 posts since Jan 2012
Reputation Points: 37
Solved Threads: 26
 

hey thanks......

shuchi0113
Newbie Poster
2 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: