A
arnuld
#include <stdio.h>
#include <limits.h>
int main(void)
{
signed char a = 'a';
unsigned char b = 'b';
printf("a = %u\n", sizeof(a));
printf("b = %u\n", sizeof(b));
printf("CHAR_MAX: %d\n", CHAR_MAX);
printf("CHAR_MIN: %d\n", CHAR_MIN);
printf("UCHAR_MAX: %d\n", UCHAR_MAX);
printf("SCHAR_MAX: %d\n", SCHAR_MAX);
printf("LONG_MAX: %ld\n", LONG_MAX);
printf("ULONG_MAX: %lu\n", ULONG_MAX);
return 0;
}
============== OUTPUT ================
[arnuld@dune programs]$ ./a.out
a = 1
b = 1
CHAR_MAX: 127
CHAR_MIN: -128
UCHAR_MAX: 255
SCHAR_MAX: 127
LONG_MAX: 2147483647
ULONG_MAX: 4294967295
[arnuld@dune programs]$
Both signed and unsigned char can hold only 1 byte, then what exactly is
the difference ?
/signed char/ can hold values from -128 to 127 but what is the meaning of
128 or -127 here. In case of /long/ and /unsigned long/ the value
represented is double for the later and that can be stored as is but the
value of CHAR_MAX (255) can not be stored, either it will be '2' or '5',
it can never ever be '-2'. So whats the meaning of -128 to 127 or 0 to
255 ?
ASCII table has values from 0 to 127 (all are single characters, then I
wonder what values you can store before zero and after 127 ?
#include <limits.h>
int main(void)
{
signed char a = 'a';
unsigned char b = 'b';
printf("a = %u\n", sizeof(a));
printf("b = %u\n", sizeof(b));
printf("CHAR_MAX: %d\n", CHAR_MAX);
printf("CHAR_MIN: %d\n", CHAR_MIN);
printf("UCHAR_MAX: %d\n", UCHAR_MAX);
printf("SCHAR_MAX: %d\n", SCHAR_MAX);
printf("LONG_MAX: %ld\n", LONG_MAX);
printf("ULONG_MAX: %lu\n", ULONG_MAX);
return 0;
}
============== OUTPUT ================
[arnuld@dune programs]$ ./a.out
a = 1
b = 1
CHAR_MAX: 127
CHAR_MIN: -128
UCHAR_MAX: 255
SCHAR_MAX: 127
LONG_MAX: 2147483647
ULONG_MAX: 4294967295
[arnuld@dune programs]$
Both signed and unsigned char can hold only 1 byte, then what exactly is
the difference ?
/signed char/ can hold values from -128 to 127 but what is the meaning of
128 or -127 here. In case of /long/ and /unsigned long/ the value
represented is double for the later and that can be stored as is but the
value of CHAR_MAX (255) can not be stored, either it will be '2' or '5',
it can never ever be '-2'. So whats the meaning of -128 to 127 or 0 to
255 ?
ASCII table has values from 0 to 127 (all are single characters, then I
wonder what values you can store before zero and after 127 ?