Hello!
Please, can someone help me find a link showing the simplest use of SIGNED CHAR!!!
First time in touch with that, no idea what it can be used for (==what it acutaly is)
signed char is an integer type that is smaller than int which means it can't hold as big and small values as int can. signed char is always one byte while int is usually 4 bytes. If you want to know the max and min values of signed char you can use std::numeric_limits.
#include <iostream>
#include <limits>
int main ()
{
std::cout << "maximum value of signed char: "
<< static_cast<int>(std::numeric_limits<signedchar>::max())
<< std::endl;
std::cout << "minimum value of signed char: "
<< static_cast<int>(std::numeric_limits<signedchar>::min())
<< std::endl;
std::cout << "maximum value of int: "
<< std::numeric_limits<int>::max()
<< std::endl;
std::cout << "minimum value of int: "
<< std::numeric_limits<int>::min()
<< std::endl;
}
Note that I had to cast the signed char to an int before printing it to avoid that it's printed as a character symbol.
A pointer to signed char is (unfortunately) the way how zero terminated c-strings are usually represented, i.e. functions like strcpy, strcmp, etc. are using this
A letter is always stored as a number. It's how you use that number that makes the difference. Normally you would use char instead of signedchar to store letters because that's the type that the standard library functions expect.
Hello!
I understand that, probelm is I cant imagine signed char(s) just because I cant imagine negative ascii value...I am not sure if I explained the problem well, my q qas simply , if I operate with char type variable in my program, how do I decide if to make it char or signed char type...problem is formula above, because I simply don't understnad what is acutlaly happening in there..
probelm is I cant imagine signed char(s) just because I cant imagine negative ascii value
signedchar and unsignedchar are simply signed and unsigned values, just like ints which can also be signed or unsigned, except they are stored in 8 bits. They do not have to represent an ASCII value. The choice of a signed or unsigned char verses an int made when the size of storage is critical. Whether signed or unsigned depends on whether the value can represent a negative number.
The char type is distinct from both signed char and unsigned char. Only the char type should ever be used for holding characters - the implementation may chose for it to be either signed or unsigned, and you should not rely on one or the other. In all cases however, they all store numbers. Characters are numbers.