prog i wrote works for some values of integer but not for all... why ??
program output
int value is abcdef78
first byte is 78 addr is 2686741
second byte is ffffffef addr is 2686742
third byte is ffffffcd addr is 2686743
fourth byte is ffffffab addr is 2686744
expected output
int value is abcdef78
first byte is 78 addr is 2686741
second byte is ef addr is 2686742
third byte is cd addr is 2686743
fourth byte is ab addr is 2686744
Process returned 0 (0x0) execution time : 0.015 s
Press any key to continue.
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i=0xabcdef78;
int *ip;
printf("int value is %x\n",i); // *ip contents of address
char c;
char *cp;
cp=&i;
c = *cp;
printf("first byte is %x addr is %d\n",*cp++,cp);
printf("second byte is %x addr is %d\n",*cp++,cp);
printf("third byte is %x addr is %d\n",*cp++,cp);
printf("fourth byte is %x addr is %d\n",*cp++,cp);
return 0;
}