Data Types in C

  • February 9, 2022
  • C
Matrix multiplication

Data types in C refer to how much memory it occupies in storage and how the bit pattern stored is interpreted. To thoroughly define a variable, one needs to mention not only its type but also its storage class.

There are the following types of data types in C:
  • Basic Types: They are arithmetic types and are further classified into (a) integer types and (b) floating-point types. For instance, int, char, float, double.
  • Type void: The type specifier void indicates that no value is available.
  • Derived types: They include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union types and (e) Function types.
  • Enumeration Data Type: They are again arithmetic types and they are used to define variables that can only assign certain discrete integer values throughout the program.i.e., enum.

Different data types also have different ranges up to which they can store numbers. These ranges may vary from compiler to compiler. That is to say, for a 16-bit compiler and a 32-bit compiler the range of the data types may vary. Here a 16-bit compiler means that when it compiles a C program it generates machine language code that is targeted towards working on a 16-bit microprocessor like Intel 8086/8088. As against this, a 32-bit compiler like VC++ generates machine language code that is targeted towards a 32-bit microprocessor like Intel Pentium.

List of all data types in C:
Data TypesMemory SizeRangeFormat
char1 byte−128 to 127%c
signed char1 byte−128 to 127%c
unsigned char1 byte0 to 255%c
short2 byte−32,768 to 32,767%d
signed short2 byte−32,768 to 32,767%d
unsigned short2 byte0 to 65,535%u
int2 byte−32,768 to 32,767%d
signed int2 byte−32,768 to 32,767%d
unsigned int2 byte0 to 65,535%u
short int2 byte−32,768 to 32,767%d
signed short int2 byte−32,768 to 32,767%d
unsigned short int2 byte0 to 65,535%u
long int4 byte-2,147,483,648 to 2,147,483,647%ld
signed long int4 byte-2,147,483,648 to 2,147,483,647%ld
unsigned long int4 byte0 to 4,294,967,295%lu
float4 byte%f
double8 byte%lf
long double10 byte%Lf
sizeof() operator:

The sizeof() operator in C is used to check the size of a variable. 

example:

#include <stdio.h>
int main()
{
	int a = 30;
	char b = '!';
	double c = 8.9;
	// printing the variables defined
	// above along with their sizes
	printf("Size of char: %d",sizeof(char));
       printf("Size of int: %d",sizeof(int));
	printf("Size of double:%d",sizeof(double));
	
        return 0;
}

output:

Size of char:1
Size of int: 2
Size of double:8

note: also read about Keywords in C & Variables & Constants in C.

Follow Me

If you like my post please follow me to read my latest post on programming and technology.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Leave a Reply

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