Need Help With Short And Long

I am a beginner trying to learn C++ i am learning it from a book
can someone explain what long and short and signed and unsigned dose
i need a detailed and short answer please i want to learn C++ without leaving
any holes in my learning curve


short is an integral data type that is at least two bytes, but could be more.
long is an integral data type that is at least four bytes, but could be more.
long long is an integral data type that is at least 8 bytes, but could be more.
int is an integral data type that is the same size or larger than short, but also the same size or smaller than long. It could be the same as one or the other, or it could be in the middle.

signed can come before char, short, int, long, or long long and ensures that the type can hold both positive and negative numbers.

unsigned can come before char, short, int, long, or long long and ensures that the type will only hold positive numbers.

Signed and Unsigned types both have the same number of total values, but the maximum positive value for signed is normally half the maximum positive value for unsigned.

In this post I use the word "byte" to mean 8 bits, however the standard defines the requirements in terms of bits, not bytes, because C++ does not require that a byte be 8 bits - it is allowed for a byte to be 11 bits, for example.
Last edited on
Could i have a few examples with use of varibles please
I don't know what you want from me, they're just numeric types. They store numbers. You can do math with them. Could you be more specific?
So in a real life big application what could they be used for

Also can you recommend me a good C++ book(not primer it has a few mistakes)
closed account (36k1hbRD)
you will never use long or long long unless its a big project just use int
For books: http://stackoverflow.com/q/388242/1959975
"C++ Primer" is a good book, "C++ Primer Plus" is by a different author and "has a few mistakes" (it's got pretty bad reviews).

Generally I never use any of the primitive types - not even int. I always use the type aliases like std::size_t, and in some cases the aliases like std::uint64_t. If you use primitive types directly in your program you're entering a realm of different behavior in different environments.
but in short and long i really could use a example of how it effects the integer
also can someone give me a suggestion of a book the teaches how a computer works eg bytes binary that stuff
You use them the same way as int. The difference is that they might be able to hold larger values than int is able to.
long long is an integral data type that is at least 8 bytes, but could be more.
No long long is maximum 8 bytes even on 64 bits systems.

signed can come before char, short, int, long, or long long and ensures that the type will only hold positive numbers.
I think you meant unsigned
SorinAlex wrote:
No long long is maximum 8 bytes even on 64 bits systems.
The C++ standard would like to have a word with you.

http://en.cppreference.com/w/cpp/language/types
http://i.imgur.com/BIZhSF6.png
Topic archived. No new replies allowed.