By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,820 Members | 1,187 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,820 IT Pros & Developers. It's quick & easy.

short in c

P: 28
can any one tell me whats the size of short integer in c language with windows platform and vc++ compiler with pentium 4 processor .can short is platform dependent in c? explain ,whats the use of short?
Jun 21 '06 #1
Share this Question
Share on Google+
3 Replies


Banfa
Expert Mod 5K+
P: 8,916
The only things you can really rely on are
  • sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long)
  • sizeof(short) >= 2
  • sizeof(int) >= 2
  • sizeof(long) >= 4

in MSVC short is 2 bytes, int and long are 4 bytes. Normally I would only use short where space was a primium. Int is useful as it is supposed to be the most efficient size of integer for the platform in use.
Jun 21 '06 #2

P: 28
hi thanx for the reply.in some archtectures int and short int is of same size .whats the use of short in that architectures
Jun 22 '06 #3

Banfa
Expert Mod 5K+
P: 8,916
true use short if you are writing portable code and space saving is important. On most platforms I have used (all actually) short is 2 bytes, long is 4 bytes and int varies between the 2.
Jun 22 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.