loader image
Teachics

C Data Types

In this tutorial, you will learn primary data types in C programming.

Data types are used to determine the size and type of data stored in a variable. For example,

int mark;

Here mark is a variable of type int. That is mark can store integer values.

C supports the following classes of data types:

  • Primary data types.
  • Derived data types.
  • User-defined data types.

C supports five primary (fundamental) datatypes namely integer(int), character(char), floating-point(float), double-precision floating-point(double) and void(void). Many of them also include additional data types, such as long int and long double.

The following table contains various data types along with their size, range of values and format specifier.

Type Size (bytes) Range of values Format specifier
int 2 -32,768 to 32767 %d
char 1 -128 to 127 %c
float 4 3.4E -38 to 3.4E +38 %f
double 8 1.7E -308 to 1.7E +308 %lf
short int 1 -128 to 127 %hd
unsigned int 2 0 to 65535 %u
unsigned short int 1 0 t0 256 %hu
long int 4 -2,147,483,648 to 2,147,483,647 %ld
unsigned long int 4 0 to 4,294,967,295 %lu
long double 10 3.4E -4932 to 1.1E +4932 %Lf

Integer

Integers are whole numbers having a range of values that are supported by a certain computer. In C, there are three types of integer storage: short int, int, and long int, which are available in both signed and unsigned forms. That is integers can store both zero, positive and negative values but no decimal values.

int roll;
int roll, mark;
short int id;
signed int x;

short int represents relatively small integer values and takes half the storage space of a typical int number. unsigned int employ all of the bits for the magnitude of the number and are always positive. Because the default declaration implies a signed number, the use of the qualifier signed on integers is optional.

Floating point

Floating-point variables are used to store real numbers with 6 digits of precision. In C, floating-point numbers are defined by the keyword float. To define a number with 14 numbers of precision, the type double can be used. These are referred to as double-precision numbers. long double can be used to increase precision even further.

float rate;
double price;

Character

The char data type can be used to define a single character.

char demo = 'x';

Void

The void type has no values. This is typically used to specify the type of function that returns no value to the caller function.

Derived Data Types and User-Defined Data Types

Derived types are data types that are derived from fundamental data types. Arrays, pointers, function types, structures, and so on are examples.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments