• admin@embedclogic.com

Fundamental Data Types

Fundamental data types are the basic data types and all other data types are made from these basic data types. following data types put in the fundamental category –

char

int

float

double

void

Fundamental data types are further classified on the basis of –

— size

— sign

char data type

size of char is fixed 1 byte so it is not classified on the basis of size but On the basis of the sign, char data type is divided into two categories –

1. signed char:  Takes both positive and negative value between the defined range.

signed char and char data type both have a similar meaning.

2. unsigned char:   Takes the only positive value between the defined range.

See the table for size, range and other details:

Fundamental typeMemory Size Range(for 32-bit platform)Format Specifier
char1 byte-128 to +127%c (%d for Numerical output)
signed char1 byte-128 to +127%c (%d for Numerical output)
unsigned char1 byte 0 to 255%c (%u for Numerical output)
Examples

When a variable has data according to its data type-

When a variable has data beyond to its range-

When a variable has an incorrect data type for its data-

int data type

int data type is used to declare an integer variable. It is divided into three categories on the basis of size –

int           

short int 

long int   

all the above three have two categories of the data type to store the data with and without a sign. See below table for detail –

Fundamental typesMemory Size Range(for 32-bit platform)Format Specifier
short int2 byte-32768 to 32767%d
signed short int2 byte-32768 to 32767%d
unsigned short int2 byte0 to 65535%u
int4 byte-2147483648 to 2147483647%d
signed int4 byte-2147483648 to 2147483647%d
unsigned int4 byte0 to 4294967295%u
long int8 byte-9223372036854775808 to 9223372036854775807%ld
signed long int8 byte-9223372036854775808 to 9223372036854775807%ld
unsigned long int8 byte0 to 18446744073709551615%lu
Example
ExampleCorrect/IncorrectRemark
short int i_var=30000;correctvalue In defined range
short int i_var=-32769;Incorrectdefined range for short int is -32768 to +32767
unsigned short int i_var=-3890;Incorrectunsigned is only for positive values
unsigned int i_var=70000;correctvalue In defined range
unsigned int i_var=70000;
printf("i_var=%d",i_var);
Incorrect%d is not valid specifier for range >32767
int i_var= -70000;
printf("i_var=%u",i_var);
Incorrect%u is not valid for signed value.%d shall use

Float data type

the float data type is used to declare the variable which holds the real value or decimal values. It is divided into three categories on the basis of size and precision.

see the table for detail :

Fundamental typesMemory Size Range(for 32-bit platform)Format Specifier
float4 byte1.175494e-38 to 3.402823e+38%f or %e(for exponential output)
double8 byte2.225074e-308 to 1.797693e+308%lf or %le(for exponential output)
long double16 byte3.362103e-4932 to 1.189731e+4932%Lf or %Le(for exponential output)
Example

Note: we can see float has the least precision compare to double and long double.

void data type

void is an empty data type and it is used  –

— When the function doesn’t return any output

— When the function doesn’t take any input

— In Generic pointer declaration

void data type when the function doesn’t return any output

Note: In c99, main has default return data type 0 to avoid the uncertainty of return type.

void add (int x, int y)  —–> void before function name add reflects the data type of function’s return value. here function doesn’t return any value so it is void.

void data type when the function doesn’t take any input:

int add(void)- void in function argument because add takes no input while in output it returns integer value so output type is int.

void data type for general purpose pointer declaration:

void data type also uses to declare a generic pointer i.e a pointer without predefined fixed data type like char, int, float, double etc.

Note-Before de-referencing of the void pointer, first do typecast with the respective data type pointer.

v_ptr=&i_var;

*v_ptr will not give the stored value you have to go through typecasting like this –

v_ptr ——–typecast with int * as stored data is int type–> (int )v_ptr ———–dereference—>((int *)v_ptr )