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.
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.
Data Types | Memory Size | Range | Format |
---|---|---|---|
char | 1 byte | −128 to 127 | %c |
signed char | 1 byte | −128 to 127 | %c |
unsigned char | 1 byte | 0 to 255 | %c |
short | 2 byte | −32,768 to 32,767 | %d |
signed short | 2 byte | −32,768 to 32,767 | %d |
unsigned short | 2 byte | 0 to 65,535 | %u |
int | 2 byte | −32,768 to 32,767 | %d |
signed int | 2 byte | −32,768 to 32,767 | %d |
unsigned int | 2 byte | 0 to 65,535 | %u |
short int | 2 byte | −32,768 to 32,767 | %d |
signed short int | 2 byte | −32,768 to 32,767 | %d |
unsigned short int | 2 byte | 0 to 65,535 | %u |
long int | 4 byte | -2,147,483,648 to 2,147,483,647 | %ld |
signed long int | 4 byte | -2,147,483,648 to 2,147,483,647 | %ld |
unsigned long int | 4 byte | 0 to 4,294,967,295 | %lu |
float | 4 byte | %f | |
double | 8 byte | %lf | |
long double | 10 byte | %Lf |
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.
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
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…