The ones who are crazy enough to think they can change the world are the ones who do.
- Steve Jobs

C Data Types

What Is Data Type?

Data Type is nothing more than what type the data belongs to. In other words Data types are the storage format to store a data.

Why Data Types?

Data types are widely used in 90's programming languages like C, java and much more. Data types tells the compiler how to treat the data while performing any mathematical operation in it. Modern Compliers and Interpreters are capable of finding the types of data automatically so that users are provided with no-headache of mentioning data types. Languages like python, javascript, php etc are datatype free programming language.

C Data Types

C programming have minimal set of basic data types. Complex data types can be built using these basic data types. Data types are also known as primitive types. In C programming, the memory size of data types may change according to 32 (4 bytes) or 64 (8 bytes) bit operating system.

Types of Data Types

In C, 5 basic data types to define data.

  • int represent integer.
  • char represent character.
  • float represent floating point.
  • double represent 2 * integer.
  • void represent valueless.
Types of data type in C

Data Type's Size and Range

The following table will demonstrate Data type's size and Data type's range for clarity view.

Data Type Size (bits) Range
void 1 byte or 8 bits nothing
char 1 byte or 8 bits -128 to 127
int 2 byte or 16 bits || 4 byte or 32 bits -32768 to 32767 or -2,147,483,648 to 2,147,483,647
float 4 bytes or 32bits || 8 byte or 64 bits 3.4e-38 to 3.4e+38
double 8 byte or 64 bits 1.7e-308 to 1.7e+308

Conceptual Data Types

There are 2 types of conceptual data types in C programming

Derived data type Enumeration Data Type
array, pointer, structure, union enum

Format Specifiers

Format Spectifiers in Programming language tells us which type of data to store and which type of data to print or to output.

Data Type Keyword Format Specifier
character char %c
signed integer int %d or %i of %l
unsigned integer unsigned int %u or %lu
long double long double %ld
string char %s
floating point float %f
double floating point double %lf

Char Data Type in C

Char is a Data Type to store a single character. Generaly, char Data Type occupies 1 bytes i.e) 8 bits.

char Data Type Program

chardatatype.c
#include <stdio.h>
int main()
{
char a = 'b';
printf("The character of a = %c ",a);
return 0;
}
  • The character of a = b

Note:

Here char data type store a character b in variable a.

Integer Data Type

Integer is a Data Type to store an integer value. Generaly, Integer Data Type occupies 2 bytes or 4 bytes its highly depend on your operating system bit rates.

Integer Data Type Program

intdatatype.c
#include <stdio.h>
int main()
{
int a = 8;
printf("The value of a = %d ",a);
return 0;
}
  • The value of a = 8

Note:

Here int data type store an integer value 8 in variable a.

Float Data Type

Float is a Data Type to store decimal point values. Generaly, Float Data Type occupies 4 bytes.

Float Data Type Program

floatdatatype.c
#include <stdio.h>
int main()
{
float a = 8.987654321;
printf("The value of a = %0.9f",a);
return 0;
}
  • The value of a = 8.987654686

Note:

Here float data type store an decimal point value 8.987654686 in variable a. Note that float data types precision is limited up to 6 digit after a decimal point. After six digit some garbage value will be displayed by the compiler. %0.9f represent, Display 9 numbers after decimal point.

Double Data Type

Double is a Data Type to store decimal point values with more accuracy than float. Generaly, Double Data Type occupies 8 bytes.

Double Data Type Program

doubledatatype.c
#include <stdio.h>
int main()
{
double a = 8.987654321;
printf("The value of a = %lf",a);
return 0;
}
  • The value of a = 8.987654321

Note:

Here double data type store an decimal point value 8.987654321 in variable a with more precision.

Report Us

We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.

Report