Unexpected behavior when printing 4-byte integer byte by byte
问题 I have this sample code for converting 32 bit integers to ip addresses. #include <stdio.h> int main() { unsigned int c ; unsigned char* cptr = (unsigned char*)&c ; while(1) { scanf("%d",&c) ; printf("Integer value: %u\n",c); printf("%u.%u.%u.%u \n",*cptr, *(cptr+1), *(cptr+2), *(cptr+3) ); } } This code gives incorrect output for input 2249459722 . But when i replace scanf("%d",&c) ; by scanf("%u",&c) ; The output comes out to be correct. P.S : I know about inet_ntop and inet_pton . I expect