DATA TYPES IN C

 

Data Types in C

Data type specifies which type of data can be stored in a variable. For example, an int variable store integer value, char variable store characters, float variable store float value etc. These int, char and float keywords are data types that basically defines the type of data. In this guide, you will learn about data types in C language with examples.

The reason why we specify the data type of variable while declaring it, so that compiler know which type of data this variable can accept.

Types of Data Types in C

1. Primary data type
2. Derived data type: Array, pointers, struct, and union are the derived data types in C. We will discuss these in separate tutorials.
3. Enumerated data type: User defined data type, declared using enum keyword.
4. Void data type: Mostly used as a return type of function that does not return anything.
5. Boolean data type: Represents variables that can store either true or false. Represented by bool keyword.

Primary Data type in C

The following 5 data types in C are known as primary data types:
1. int: The int data type is used for integer values such as 5, 86, 99, 1002 etc.
2. char: The char data type is used for character values such as ‘A’, ‘p’, ‘u’, ‘M’ etc.
3. float: The float data type is used for decimal points values or real values such as 5.5, 10.91 etc.
4. double: The large floating point values are stored in double variables.
5. void: This is generally used as a return type of a function that does not return anything.

DATA TYPEMEMORY SIZERANGE
int2 bytes−32,768 to 32,767
signed int2 bytes−32,768 to 32,767
unsigned int2 bytes0 to 65,535
short int2 bytes−32,768 to 32,767
signed short int2 bytes−32,768 to 32,767
unsigned short int2 bytes0 to 65,535
long int4 bytes-2,147,483,648 to 2,147,483,647
signed long int4 bytes-2,147,483,648 to 2,147,483,647
unsigned long int4 bytes0 to 4,294,967,295
char1 byte-128 to 127
signed char1 byte-128 to 127
unsigned char1 byte0 to 255
float4 bytes3.4E-38 to 3.4E+38
double8 bytes1.7E-308 to 1.7E+308
long double10 bytes

Data Type in C Example

#include <stdio.h>
int main()
{
  int num = 100;
  char ch = 'P';
  double bigNum = 10000.29;
  printf("Character value: %c and char size: %lu byte.\n",
  ch, sizeof(char));

  printf("Integer value: %d and int size: %lu byte.\n",
  num, sizeof(int));

  printf("Double value: %lf and double size: %lu byte.\n",
  bigNum, sizeof(double));

  return 0;
}

Output:


3.4E-4932 to 1.1E+493





Comments

Popular posts from this blog

Program to find the average of two numbers

Program to add two integer numbers