datatypes helps us to hold data in a programming language.difference between constant and variable is explained,use of sizeof operator will help u understand size occupied by each datatypes.format specifier are needed to o/p the datatype value is also explained in detail.
5. Need of Datatypes in programming
vendor: what do u want sir/madam.
Customer: I want apple. How much does it costs?
Vendor: How many do u want sir/madam.
Customer : Answers according to his/her requirement.which
is a variable x( which changes every time).
Vendor : Now he calculates the rate(c.p + profit) and sells the
apples.
In order to do this calculation in programming we need a thing
that can hold a value (a number like 5 or 20 etc)
Thats where we need
7. Syntax of Datatypes in C
In the example:
Number of apple he /she wanted. <value>
Customer asked for apples. That identifies what he wants.
<identifier name>
To store this value we need a box in programming which is a type
integer in C<type>
Format for Datatypes declaration and definition is :
<type> <identifier name>=<value>
Ex:
Int apples =20;
8. Types of Datatypes
Datatype Use to hold Example
int for integer range numbers -5
float for decimal range numbers 99.99
char for character numbers A
double for more precision decimal numbers 99.999999
* Long <datatype> for hold big numbers 34,333
* short <datatype> for value inside 32,768 8987
signed <datatype> **for only positive numbers 88
Unsigned<datatype> **for positive and negative numbers -96
Except char Datatype.
In char we have -128 t0 127 range for unsigned char and 0 to 255 for signed char
9. Sizeof
This will give u the size(int value) of the variable.
Syntax:-
sizeof(<identifier name>);
Example:-
int a,b;
b=sizeof(a);
10. Table of Datatypes
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
*Size depends on how many bit processor u r running on
11. Types of Datatypes(cont..)
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
12. Printf advance
Syntax:-
Printf(<format string>,<list of arguments>);
Format string:-
%c char single character
%d (%i) int signed integer
%e (%E) float or double exponential format
%f float or double signed decimal
%g (%G) float or double use %f or %e as required
%o int unsigned octal value
%p pointer address stored in pointer
%s array of char sequence of characters
%u int unsigned decimal
%x (%X) int unsigned hex value
Example:
Printf(text %d,apples);