0% found this document useful (0 votes)
8 views6 pages

C_Tutorial_Day_3

Uploaded by

Deepak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views6 pages

C_Tutorial_Day_3

Uploaded by

Deepak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Programming With C-Operators and Expressions

BASIC DATA TYPE


The C language support following basic data types:
 char a single byte that can hold one character
 int an integer
 float a single precision real number
 double a double precision real number

Further applying qualifiers to the above data types yield additional data types. A qualifier alters the characte-
ristics of data type such as its size and sign.
short and long qualifiers are used for altering size.
signed and unsigned qualifiers are used for altering sign.

The qualifier short is applicable with only int type whereas long is applicable with int type as well as with
double type.

The qualifiers signed and unsigned are combined with int and char data type.

Created and verified By: B. K. Deepak 23


Dated:20/12/2004
Rev:00
Programming With C-Operators and Expressions

After applying qualifiers the data type that we can use in C language are:
signed short int
unsigned short int
signed int
unsigned int
short int
int
signed long int
signed long
unsigned long int
unsigned long
long
float
double
long double
signed char
unsigned char

Created and verified By: B. K. Deepak 24


Dated:20/12/2004
Rev:00
Programming With C-Operators and Expressions

The data type above defined can be categorized as :

int : signed int , signed short int , short int


Its size is 16 bit and Range is -32768 to 32767
unsigned int: unsigned short int
Its size is 16 bit and Range is 0 to 65535
long: signed long int, signed long
Its size is 32 bit and Range is -2147483648 to 2147483647
unsigned long: unsigned long int
Its size is 32 bit and Range is 0 to 4294967295

If we have to store some values in variables then this must be informed to computer before storing the value.
This is known as data declaration. If we have to store integer values then we have to judge the type which
can hold the values. e.g. we have to add three numbers as 34567, 567 and -56. To store these values we
create three variables/identifiers let it be a, b and c. The content of a will be 34567 which is positive and
range is above 32767 therefore a can not be of int data type. It can be unsigned int type then we can store
up to 65535 in a. b and c can be of int type because 567 and -56 is within the range of -32768 to 32767. And
we have to think over the output that is the sum of a, b and c which can be of unsigned int (why?) type.

Created and verified By: B. K. Deepak 25


Dated:20/12/2004
Rev:00
Programming With C-Operators and Expressions

This can be now declared in C language as follows:


unsigned int a;
int b,c;
unsigned int d;
In data declaration data type follows by variable names. If more than one variables then it must be separated
by ( , ) commas and declaration statement terminated by ( ; ) semicolon. Data can be defined in more than
one line but it should be declared before any executable statement.
data_type var1,var2,var3;

Real Number Types are as follows:


float: Its size is 32 bits and range is 3.4 E -38 to 3.4 E +38. Precision is of 6 digits.
double: Its size is 64 bits and range is 1.7 E -308 to 1.7 E +308. Precision is of 15 digits.
long double: Its size is 80 bits and range is 3.4 E -4932 to 3.4 E +4932. Precision is of 19 digits.

Character types data are as follows:


unsigned char or char : Its size is of 8 bits and can hold up to 256 characters.
signed char: Its size is of 8 bit and can store 1st 127 characters.

Created and verified By: B. K. Deepak 26


Dated:20/12/2004
Rev:00
Programming With C-Operators and Expressions

The sizeof operator


To find out size of each data type we can use operator sizeof, that gives the size of any data type in bytes.
For example sizeof (int) will give the output 2 i.e. 2 bytes.

The typedef Statement


The typedef statement is used to give new names to existing data types.
For example:
typedef unsigned long int ulint;
declares ulint a new type, equivalent to unsigned long int. Now it can be used just as any other type used in
program. For example,
ulint a,b,c;
The above statement declares a, b and c as type ulint.

The const qualifier


The value which is not to be changed during a program operation is constant. The const qualifier is used to
make a value as constant and it can not be modified.
const float pi=3.1415926;

Created and verified By: B. K. Deepak 27


Dated:20/12/2004
Rev:00
Programming With C-Operators and Expressions

Enumeration Constants
An enumeration is a user defined type with values ranging over a finite set of identifiers called enumeration
constant. Enumeration is a convenient way to associate constant integer with meaningful name. It has the
advantage of generating values automatically. Use of enumeration constants, in general makes the program
easy to read and change at a later date.
For this we have to use keyword enum.
enum grades
{
F, D, C_MINUS, C, C_PLUS, B_MINUS, B, B_PLUS, A_MINUS, A, A_PLUS
}result;
enum grades final_result;
This declaration creates a new type grades and result and final_result as variable of this type, That can only
accept one of the values F,D,….. A_PLUS and no others. These eleven enumerators have the consecutive
integer values 0 (for F) through 10 (for A_PLUS).
The values need not be distinct in the same enumeration. For example
enum weather { hot, warm=0, cold, wet};
Here hot and warm both represent the value 0.

Created and verified By: B. K. Deepak 28


Dated:20/12/2004
Rev:00

You might also like