Data Structures In C

A variable’s data type specifies the type of data that can be stored in it. Int variable stores integer values, char variable stores characters, float variable stores float values, and so on. These keywords int, char, and float are data types that define the type of data. This guide will teach you about data types in C using examples.
We specify the data type of a variable when declaring it so that the compiler knows what type of data this variable can accept.

Data type types in C

1. Type of primary data
2. Derived data type: In C, derived data types include arrays, pointers, structures, and unions. These will be covered in separate tutorials.
3. Enumerated data type: A user-defined data type that is declared with the enum keyword.
4. Void data type: Typically used as a function return type that does not return anything.
5. Boolean data type: This data type represents variables that can store either true or false values. The keyword bool represents this.

C is the primary data type.

Primary data types in C are the five data types listed below:
1. int: The int data type is used to represent integer values such as 5, 86, 99, 1002, and so on.
2. char: The char data type is used for character values like ‘A,’ ‘p,’ ‘u,’ ‘M,’ and so on.
3. float: The float data type is used for decimal points or real values like 5.5, 10.91, and so on.
4. double: Double variables are used to store large floating point values.
5. void: This is commonly used as the return type of a function that returns nothing.

int 2 bytes −32,768 to 32,767
signed int 2 bytes −32,768 to 32,767
unsigned int 2 bytes 0 to 65,535
short int 2 bytes −32,768 to 32,767
signed short int 2 bytes −32,768 to 32,767
unsigned short int 2 bytes 0 to 65,535
long int 4 bytes -2,147,483,648 to 2,147,483,647
signed long int 4 bytes -2,147,483,648 to 2,147,483,647
unsigned long int 4 bytes 0 to 4,294,967,295
char 1 byte -128 to 127
signed char 1 byte -128 to 127
unsigned char 1 byte 0 to 255
float 4 bytes 3.4E-38 to 3.4E+38
double 8 bytes 1.7E-308 to 1.7E+308
long double 10 bytes 3.4E-4932 to 1.1E+4932

Example of Data Type in C

#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;

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button