if we use short then we can save memory.But eventhough if we use short it occupies 2 bytes of memory so how can we save memort?
there is no guarentee that a short will occupy 2 bytes of memory. The only thing we can be sure of is that char <= short <= int <= long. Notice that on some os all could be the same size.
On operating systems where short is 2 bytes and int/long are 4 bytes, using short will save 2 bytes over using int or long. However it may not be possible to use short if the value you want to store will not fit in a short.
We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.