Data Types in C Language



PREVIOUS                                                                                                                    NEXT

 

Data Types in C Language

What is the meaning of data types..
C program is combination of statements that are executed one after another and to give a desired output. When computing, the data is stored in the memory. When writing a program in c language the programmer may need one byte or more than one byte to store the data in the Data Segment memory as required by the program. So the compiler must know which data requires how much memory to store.

The c language has different data types, which tells the compiler that which data type takes how much memory to store the data.


In c language the data types are divided into three categories.
  • Built in Data Types
  • Derived Data types
  • User Defined Data Types
Built in Data Types


The built in data types are also divided into three types
  1. Integral Type Data Types  >> int , char
  2. Void
  3. Floating Type >> float , double
In general built in data types are int, char, void, float, double
Derived Data Types

The derived data types are array, function, pointer type.
User Defined Data Types
The user defined data types are structure, union type.
There are several modifiers that are preceding the data types to serve the need of various situations.
The Modifiers are
  • signed
  • unsigned
  • long
  • short
signed, unsigned, long, short modifiers are applied to character and integer type data types. The modifier long may also be applied to double data type. The data type storage and representation are machine depended.
The void data type is introduced in ANSI C. The void data type is used as return type of a function declaration and function definition when the function is not returning any value and also may be used as a function parameter indicating the compiler that the function has empty argument list.


The size and range of Data Types
The size of the data type is depending on the size of the processor i.e. 16 bit or 32 bit processor.
In this article the size of the data types are given for a 16 bit compiler

Data Type
Bytes
Range
Format
char
1
-128  to 127
%c
unsigned char
1
0  to  255
%c
int
2
-32768  to 32767
%d
unsigned int
2
0  to  65535
%u
short int
2
-31768  to 32767
%d
unsigned short int
2
0  to  65535
%u
long int
4
-2147483648 to 2147483647
%ld
unsigned long int
4
0  to   4294967295
%lu
float
4
3.4E  -38  to  3.4E +38
%f
double
8
1.7E -308  to  1.7E +308
%lf
long double
10
3.4E -4932  to  1.1 E +4932
%Lf



Operators Precedence and Associativity in C Language


Operator
Description
Associativity
()
[]
.
->
++  --
Parentheses (function call)
Brackets (array subscript)
Member selection via object name
Member selection via pointer
Post-fix increment/decrement
left-to-right
++  --
+  -
!  ~
(type)
*
&
sizeof
Prefix increment/decrement
Unary plus and minus
Logical negation and bitwise complement Cast (change type)
De-reference
Address
Determine size in bytes
right-to-left
*  /  %
Multiplication / division / modulus
left-to-right
+  -
Addition and subtraction
left-to-right
<<  >>
Bitwise shift left and Bitwise shift right
left-to-right
<  <=
>  >=
Relational less than/less than or equal to
Relational greater than/greater than or equal to
left-to-right
==  !=
Relational is equal to and is not equal to
left-to-right
&
Bitwise AND
left-to-right
^
Bitwise exclusive OR
left-to-right
|
Bitwise inclusive OR
left-to-right
&&
Logical AND
left-to-right
||
Logical OR
left-to-right
?:
Ternary conditional
right-to-left
=
+=  -=
*=  /=
%=  &=
^=  |=
<<=  >>=
Assignment
Addition / subtraction assignment
Multiplication / division assignment
Modulus / bitwise AND assignment
Bitwise exclusive / inclusive OR assignment Bitwise shift left/right assignment
right-to-left
,
Comma (separate expressions)
left-to-right


PREVIOUS                                                                                                            NEXT

No comments:

Post a Comment