Data types in C Programming

A Data Type in C is a metadata that represents the program data, which also tells the compiler or interpreter about the data. These data types also defines all its proper operations on corresponding data.

Every variable that we use in the C Program created with specific data types. Based on the type of data and its storage, data types classify as two types.

  1. Primary data types.
  2. Derived data types.

Primary data types

Basically three kinds of data available in C Programming language.

  1. Integer data
  2. Numeric data (with scale)
  3. Character data

In addition to these three basic types of content, we have one more “void” data type, which represents nothing (NULL).

Data types used to store integer type of data are

  1. int,”signed” or “signed int” which is of 2 bytes size and value ranges from -32768 to 32767 with format specifier ‘%i or %d.’
  2. unsigned” or “unsigned int” which is also of 2 bytes size ranges from 0 to 65535 with format specifier “%u.”
  3. short,”short int,”signed short,” or “signed short int,” which is of 1byte size and value ranges from -128 to 127 with format specifier “%hi.”
  4. unsigned short” or “unsigned short int,” which is also of 2bytes size and value ranges from 0 to 65535 with a format specifier “%hu.”

Data types used to store floating-point (real numbers) data are

  1. float,” which is 4bytes of size single-precision floating-points with format specifier ‘%f or %F.’
  2. double,” which is 8bytes of size double-precision floating-point data with format specifiers ‘%lf or %lF’.
  3. long double” which is 10bytes of size double-precision floating-point data with format specifiers ‘%Lf or %LF’.

Data types used to store character type data ares

  1. char” or “signed char,” which is of 1byte size, which ranges from -128 to 127 with format specifier ‘%c’ (‘%hhi’ for numeric output).
  2. unsigned char” which is also of 1byte size ranges from 0 to 255 with format specifier ‘%c’ (‘%hhu’ for numeric output).

Finally we have ‘void‘ type for nothing or not have any value (NULL).

Derived data types

Derived data types are classified as four types.

  1. Arrays
  2. Functions
  3. Pointers
  4. References

Arrays

Array data stores in continuous memory space, which is declared as follows.

int arr[10];  // which can store 10 integers data.

Here it allocates 40 continuous bytes of 10 items which are of 4 bytes each.

C Programming also has multi-dimensional arrays that can store the matrix type of comparable data.

We have whole different article on C arrays declaration and initialisation.

Functions

C functions are a set of instructions to do a meaningful job or task. Services are two different types, as follows.

  1. C Library defined functions (like abs, sqrt, pow…etc)
  2. C User defined functions (like any user defined functions to do some task “add()” ).

Every C program starts with a function called “main()”.

Pointers

Pointer is a C derived data types used to store C memory (addresses).

Pointer which stores the address of a.

To know the value of any pointer, a is at “*a.” We also can do different arithmetic operations on tips.

References

Reference in C Programming is an alternative way of representation of a variable. We represent the references with ‘&’ character.

int a = 20;
int& b = a; // b is reference to a.

References can’t be NULL where as pointers can be NULL.

It is all about primary and derived data types in C Programming. If you have any information about C data types, please let our readers know by commenting here below. Happy Learning!.

See more: