So am trying to write a trivial program just for fun. Intent is to print the value of an integer using char pointer
So you can see I have an integer a, which I print and then I use a char* b to get the higher byte location of the integer and then get the lower byte using post-increment operation of char* b
But on https://code.sololearn.com the line which prints *b and *b++, throws warning for *b++. Am interested in knowing what is the way to remove that warning.
#include <stdio.h>
int main(void) {
int a = 0xaabb;
printf("%x\n",a);
unsigned char *b = (unsigned char*) &a;
printf("%x%x\n",*b, *b++);
return 0;
}
union, e.g.typedef union { unsigned char bytes[4]; int n; } uc2n;Thenuc2n convert = { .n = 0xaabb };now you can useconvert.bytes[0] - convert.bytes[3]to access each byte of theint.bis placed as an argument. A post-increment happens at some time between thatbbeing used, and the next sequence point.