All data types in C with examples

Data types are the backbone of every strongly type language. There are many data types in C. Today, you will understand data types in C with examples, primary data types, user-defined data types and fundamental data types.

Data types are the smallest unit used to declare any type of data that is supports by a language like C, C++ etc.

i.e. C supports integer, decimal and character data types. These data types known as primary or primitive data types. Also, we have different data types that are supported by the C language.

Let’s understand quickly-

C data types with examples
C Data Types

Primary data types in C

C support 3 primary or primitive data types.

  • Numbers (int)
  • Decimal numbers (float)
  • String (Char)

These three are primary data types. All other data types are derived from these data types.

You use integer and float data types for numeric values and char is used for strings.

An integer (int) and float are used for numerical manipulations. char is used for string operations.

Every data type has different storage ranges and it is measured in bytes.

How do you understand which data type is required in your program?

Read the program carefully and make a list of input and result values. e.g. I want to add 2 numbers and display the sum of their values.

So think you need 2 numeric values and they can be an integer as well as float values. So in this situation always take float values because float data type can store any integer values too.

Hope that you understand the above concept.

User define data types

User define data types are the driven data types. They are driven from primitive data types.

e.g. array, structure and union are the users define data types.

Below is the complete C data types with their storage and control string.

Data typesstoragevalue rangecontrol string
short int2-32,768 to 32,767%hd
unsigned short int20 to 65,535%hu
unsigned int40 to 4,294,967,295%u
int4-2,147,483,648 to 2,147,483,647%d
long int4-2,147,483,648 to 2,147,483,647%ld
unsigned long int40 to 4,294,967,295%lu
long long int8-(2^63) to (2^63)-1%lld
unsigned long long int80 to 18,446,744,073,709,551,615%llu
signed char1-128 to 127%c
unsigned char10 to 255%c
long double12%Lf

Do you know the control string?

Control string is the special string used with % sign like %c, %d, %f etc. You can check the above list for control string of each data type.

These are used with printf(), scanf() function to handle variables.

You can also read

Hope that you understand the data types in C. Please ask your questions in below comment box.

Don’t forget to share this post in your social family. If you love blogging you can visit our blog

Leave a Comment