Online Test Banks
Score higher
See Online Test Banks
Learning anything is easy
Browse Online Courses
Mobile Apps
Learning on the go
Explore Mobile Apps
Dummies Store
Shop for books and more
Start Shopping

C Language Variable Types

Part of the Beginning C Programming For Dummies Cheat Sheet

Rather than make all your variables floats, it’s more efficient to examine the type of data that’s stored and then choose an appropriate C variable type.

Type Value Range
_Bool 0 to 1
char –28 to 127
unsigned char 0 to255
short int –32,768 to 32,767
unsigned short int 0 to 65,535
int –2,147,483,648 to 2,147,483,647
unsigned int 0 to 4,294,967,295
long int –2,147,483,648 to 2,147,483,647
unsigned long int 0 to 4,294,967,295
float 1.17×10–38 to 3.40×1038
double 2.22×10–308 to 1.79×10308

Keep these C language variable type points in mind:

  • Ensure that you choose the proper variable type for the values you need to store.

  • The _Bool type stores only two values, 0 and 1, which can represent TRUE or FALSE or On or Off or any binary condition.

  • The char variable type stores character values, though it can also be used to store tiny integers.

  • Integers, or whole numbers, are stored in the int variable types.

  • Any type of value, from the very large to the very small, and any fractional values are stored in the float and double types.

  • Remember to use int values for functions that generate integers, such as getchar(). It’s easy to assume that the function returns a char value because of the function’s name.

  • C lacks a string variable type. Instead, an array of char variables is used.

  • Other variable types include structures and pointers.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus

Beginning C Programming For Dummies Cheat Sheet


Inside Sweepstakes

Win $500. Easy.