0% found this document useful (0 votes)
19 views

Datatype in C:: Type Storage Size Value Range

This document discusses data types in C including their storage sizes and value ranges. It covers integer types like char, int, short, long and floating-point types like float, double, and long double. It also shows examples to get the storage size of types using sizeof operator and printing the float type's storage size and value range. Important concepts mentioned are that C provides no error checking for user input and it is the programmer's responsibility to validate data.

Uploaded by

Harsh Tripathi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Datatype in C:: Type Storage Size Value Range

This document discusses data types in C including their storage sizes and value ranges. It covers integer types like char, int, short, long and floating-point types like float, double, and long double. It also shows examples to get the storage size of types using sizeof operator and printing the float type's storage size and value range. Important concepts mentioned are that C provides no error checking for user input and it is the programmer's responsibility to validate data.

Uploaded by

Harsh Tripathi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Datatype in c:

Type Storage size Value range

char 1 byte -128 to 127 or 0 to 255

unsigned char 1 byte 0 to 255

signed char 1 byte -128 to 127

int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to


2,147,483,647

unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295

short 2 bytes -32,768 to 32,767

unsigned short 2 bytes 0 to 65,535

long 4 bytes -2,147,483,648 to 2,147,483,647

unsigned long 4 bytes 0 to 4,294,967,295

To get the exact size of a type or a variable on a particular platform, you


can use the sizeof operator. The expressions sizeof(type) yields the storage
size of the object or type in bytes. Given below is an example to get the
size of int type on any machine

#include <stdio.h>

#include <limits.h>

int main() {
printf("Storage size for int : %d \n", sizeof(int));

return 0;

When you compile and execute the above program, it produces the
following result on Linux

Storage size for int : 4

Floating-Point Types
The following table provide the details of standard floating-point types with
storage sizes and value ranges and their precision

Type Storage size Value range Precision

float 4 byte 1.2E-38 to 3.4E+38 6 decimal places

double 8 byte 2.3E-308 to 1.7E+308 15 decimal places

long double 10 byte 3.4E-4932 to 1.1E+4932 19 decimal places

The header file float.h defines macros that allow you to use these values
and other details about the binary representation of real numbers in your
programs. The following example prints the storage space taken by a float
type and its range values

Some important concepts


the c language provides no error checking for user input. The user is expected to enter
the correct data type. For instance, if a user entered a character when an integer value
was expected, the program may enter an infinite loop or abort abnormally.

its up to the programmer to validate data for correct type and range of values.

You might also like