C - Variable Types Introduction

Introduction

C variables holds specific types of values.

The four basic variable types used in C are shown in the following table.

TypeDescription
charSingle-character variable; stores one character of information
int Integer variable; stores integer (whole number) values
float Floating-point variable; stores real numbers
double Floating-point variable; stores very large or very small real numbers

To store an integer value, use an int variable.

To store a letter of the alphabet, use a char variable.

The char and int variable types are integer values. char has a shorter range.

char type is used to store characters - letters of the alphabet, numbers, and symbols.

The float and double types are both floating-point variables that can store very small or very large values.

_Bool is used to store binary values, 1 or 0, often referred to as TRUE and FALSE, respectively.

Type

Value Range

Conversion
Character
_Bool
0 to 1
%d
char
-128 to 127
%c
unsigned char
0 to 255
%u
short int
-32,768 to 32,767
%d
unsigned short int
0 to 65,535
%u
int
-2,147,483,648 to 2,147,483,647
%d
unsigned int
0 to 4,294,967,295
%u
long int
-2,147,483,648 to 2,147,483,647
%ld
unsigned long int
float
0 to 4,294,967,295
1.17?10^-38 to 3.40?10^38
%lu
%f
double
2.22?10^-308 to 1.79?10^308
%f

Related Topics

Exercise