BobaMosfet
- Joined Jul 1, 2009
- 2,211
Why don't you find out for yourself? It's just memory. When you put a value in quotes (double or single) you're telling the compiler to treat it as a string- meaning, use an ASCII value to represent each character, not its actual decimal value. When you don't, as with int, long, etc- you're getting it's actual value.@BobaMosfet
int x=6 ;
char c='6';
printf("\n%c",x);
printf("\n%d",x);
printf("\n%c",c);
printf("\n%d",c);
what am i telling to the compiler for each of variable declaration and 4 output statements?
However, as I said, why don't you see for yourself:
Code:
char c = 6;
char a = '6';
int i = 0;
unsigned char memory[10];
unsigned char *memAddr;
memAddr = (unsigned char*)((long)&c - 4L); // get the address of memory location 4 bytes before where 'c' is in memory
for(i=0;i<9;i++)
memory[i] = *memAddr++;
memory[9] = 0x00; // add a terminating byte (c-style)
printf("%X\n",memory); // Output Hex for each character in String
memAddr = (unsigned char*)((long)&a - 4L); // get the address of memory location 4 bytes before where 'a' is in memory
for(i=0;i<9;i++)
memory[i] = *memAddr++;
memory[9] = 0x00; // add a terminating byte (c-style)
printf("%X\n",memory); // Output Hex for each character in String
000132780632232057 // 0x06 is a 6
4318A7FE3623C49820 // 0x36 is a '6'
NOTICE that I am using 'char' (byte-sized aka '8-bit') sized variable types in all the above to help you see things in memory at a byte level. int's use 2 bytes, longs use 4 bytes (compiler defined- but that is typical for 32-bit systems). If you represented 6 in 8-bits, 16-bits, or 32-bits, it would be: 0x06, 0x0006, and 0x00000006.
This may help:
Title: Standard C [Quick Ref]
Author(s): P.J.Plauger, Jim Brodie
ISBN: 1-55615-158-6
Last edited: