Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

What's the difference between int and short int in C?

Status
Not open for further replies.

A.Anand Srinivasan

Advanced Member level 5
Advanced Member level 5
Joined
Oct 15, 2005
Messages
1,792
Helped
257
Reputation
514
Reaction score
39
Trophy points
1,328
Location
India
Activity points
10,678
i was referring some C books and found that int and short int have the same range... then what is the use of two with same range but different names........
 

Re: int and short int

Sometimes they don't have the same range. In some embedded applications an int is 32b and a short in is 16b a word is also 16b but isn't treated the same as an int by the compiler.

Swingbyte
 

int and short int

I believe the only standard ANSI C imposes is that a short can be equal or smaller in size than an int, but never greater. I always get mixed up on compilers for different compilers for different sized micros as towhat the sizes are and end up looking it up in the compiler documentation. I have a PIC compiler where an int is 8 bits, on Windows an int is 32 bits and i beleive a short is 16 bits, but I can't remember..
 

Re: int and short int

According to C standard max short size is 2 bytes. Int can be more than that.
Only in machine where int is 2 bytes, both short and ant are same. Other wise they r different.
 
int and short int

booklog, The ISO C standard says the *minimum* range of short is -32767 to +32767. It can have greater range.

The standard says short must be a subrange of int. They can both be 32-bit, for example.

Be careful with the term "byte" in C. It usually means 8 bits, but it can be larger.
 

int and short int

On a 16-bit processor, int and short int are both 2 bytes, whereas on a 32-bit processor, int = 4 bytes and short int = 2 bytes
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top