Data Types

Data Types

 

void

The void keyword indicates that a function doesn’t return any value.

void testFunction()
{
statement;
}

Here, function testFunction( ) cannot return a value because the return type is void.

Here, there is no input and there is no output of this function.

Boolean

A Boolean holds one of two values, true or false. Each Boolean variable occupies one byte of memory.

boolean val = false ; // declaration of variable with type boolean and initialize it with false
boolean state = true ; // declaration of variable with type boolean and initialize it with false
Char

The char keyword declares a character variable. For example:

char alphabet;
Char chr_a = ‘a’ ;//declaration of variable with type char and initialize it with character a
Char chr_c = 97 ;//declaration of variable with type char and initialize it with character 97

Here, alphabet is a character type variable. ‘a’ and 97 are ASCII values. For more, look at the ASCII character table.

unsigned char

Unsigned char is an unsigned data type that occupies one byte of memory. The unsigned char data type is used for numbers from 0 to 255.

Unsigned Char y = 121 ; // declaration of variable with type Unsigned char and initialize it with character y
byte

A byte stores an 8-bit unsigned number, from 0 to 255.

byte m = 25 ;//declaration of variable with type byte and initialize it with 25
int

keyword int is used for declaring integer variable. For example:

int i;

Here, i is a variable of type integer.

You can declare multiple variable at once in C programming. For example:

int i, sum, sub, data;

The short, long, signed and unsigned keywords are type modifiers that alters the meaning of a base data type to yield a new type.

short int smallInteger;
long int bigInteger;
signed int normalInteger;
unsigned int positiveInteger;
Data types Range
short int -32768 to 32767
long int -2147483648 to 214743648
signed int -32768 to 32767
unsigned int 0 to 65535
float and double

Floating type variables can hold real numbers such as: 2.34, -9.382, 5.0 etc. You can declare a floating point variables by using either float or double keyword. For example:

float account;
double Price;

Here, both account and Price are floating type variables.

Floating values can be represented in exponential form as well. For example:

float factor = 22.442e2;

Keywords double float is used for declaring floating type variables, where longNumber is a double precision floating type variable. For example:

double longNumber; 

What is the difference between float and double?

The size of float (single precision float data type) is 4 bytes. And the size of double (double precision float data type) is 8 bytes. Floating point variables has a precision of 6 digits whereas the precision of double is 14 digits.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s