Connecting Tech Pros Worldwide Forums | Help | Site Map

What is the default type & size of a numeric constant in C?

Member
 
Join Date: Jul 2008
Posts: 62
#1: Oct 7 '09
If I have a function

Expand|Select|Wrap|Line Numbers
  1. funct( uint32 x )
  2. {
  3.  stuff
  4. }
  5.  
and call it:
Expand|Select|Wrap|Line Numbers
  1. funct( 3 );
  2.  
what is the type and size of 3? Is it a long unsigned integer? Or 16 bits or what?

What happens if I call:

Expand|Select|Wrap|Line Numbers
  1. funct( -3 );
  2.  
? Will the -3 be converted? I know this should be common knowledge but I can't find this information and don't know for sure.

Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,384
#2: Oct 7 '09

re: What is the default type & size of a numeric constant in C?


You can find this in any book on C or by Googling for it.

Symbolic constants like 3 are type int. Use sizeof(int) to see how large the the variable is on your machine. Constants like 3.14 are type double. Again, use sizeof(double).

As to what is converted research the topic "automatic comversions". In the case of calculations research "promotions".
Banfa's Avatar
Administrator
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,210
#3: Oct 8 '09

re: What is the default type & size of a numeric constant in C?


You can create constants of type unsigned int, long, unsigned long, float and in C++ char. Looking at any basic C++ reference should tell you how.
Reply