C Basics

Data Types

User Rating:  / 8
PoorBest 

Datatypes refer to sytem used for declaring and using variables or functions of different type. The type of variable determines space it requires.

The types in C can be categorized in following: -      

Type

Description

Basic Type

Standard and extended integer, complex and floating types.

Enumerated Type

Arithmetic types and are used to define variables that can only be assigned certain discrete integer values through out the program.

The type void

Tye type void indicates “no” value is available.

Derived Type

Pointer, Array, Structure, Union and Functions.

                                   

 

The basic types and the enumerated types together make up the arithmetic types.

The arithmetic types and the pointer types together are called the scalar types

Finally, array types and structure types are referred to collectively as the aggregate types .

Union types are not considered aggregate, because only one of their members can store a value at any given time.

A function type describes the type of value it returns and may also specify the types of all

parameters that are passed to the function.

Integer Types

Following table contain list of Integer types with Storage size, Minimum Value and Maximum Value.

Type

Description

Minimum Value

Maximum Value

char

Same as singed or unsigned char

unsigned char

one byte

0

255

signed char

one byte

-128

127

int

two bytes or four bytes

-32,768 or -2,147,483,648

32,767 or 2,147,483,647

unsigned int

two bytes or four bytes

0

65,535 or 2,147,483,647

short

two bytes

-32,768

32,767

unsigned short

two bytes

0

65,535

long

four bytes

-2,147,483,648

2,147,483,647

unsigned long

four bytes

0

4,294,967,295

 

Floating Point Types

Following table contain list of Floating Point types with Storage size, Value Range, Smallest positive value and Precision.

Type

Description

Value Range

Minimum Value

Precision

float (single precision)

4 bytes

±3.4E+38

1.2E-38

6 digits

double (double precision)

8 bytes

±1.7E+308

2.3E-308

15 digits

long double (extended precision)

10 bytes

±1.1E+4932

3.4E-4932

19 digits

To obtain the exact size of a type or a variable, use the sizeof operator. The expressions sizeof(type) and sizeofexpression gives the storage size of the object or type in bytes.

Example

 

#include <stdio.h>
#include <limits.h>
#include <float.h>
void main()
{
     printf(“Size \t Min Value \t Max Value\n”);
     printf(“%d \t %d \t %d”,sizeof(char),CHAR_MIN,CHAR_MAX);
     printf(“%d \t %d \t %d”,sizeof(int),INT_MIN,INT_MAX);
     printf(“Size \t Min Value \t Max Value \t Precision\n”);
     printf(“%d \t %E \t %E \t %d\n”, sizeof(float), FLT_MIN, FLT_MAX, FLT_DIG);
     getch();
}

The header file limits.h & float.h defines macros that allow you to use these values and other details about the binary representation of Integer and real numbers in your programs.

 

The Void Type

The void type specifies that no value is available.

Void can be used for following purpose.

1)    Void in function declarations

A function with no return value has return type void.

2)    Function parameters as void

A function with no parameters / arguments.

3)    Pointers to void

A pointer of type void * represents the address of an object, but not its type.

   Example : -  void free( void *ptr )

Enumerated Types

Enumerations are integer types that you define in a program. The definition of an enumeration begins with the keyword enum, followed by an identifier for the enumeration, and contains a list of the type's possible values, with a name for each value:

    enum [identifier] { enumerator-list };

The following example defines the enumerated type enum color:

    enum color { black, red, green, yellow, blue, white=7, gray };

Different constants in an enumeration may have the same value:

    enum { OFF, ON, STOP = 0, GO = 1, CLOSED = 0, OPEN = 1 };

 

 
 
 

                                                                                          About Us  ||  Contact Us  ||  Terms & Conditions  ||  Privacy Policy 

Referral Banners