0% found this document useful (0 votes)
5 views3 pages

comp611-TurboC (Chap 2)

TurboC__(chap_2)

Uploaded by

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

comp611-TurboC (Chap 2)

TurboC__(chap_2)

Uploaded by

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

Chapter 2

Elementary C++
2.1 Program Layout

#include<header file name>


void main()
{
variable declaration;
executable statements;
}

#include<header file name>


main()
{
variable declaration;
executable statements;
return 0;
}

2.2 Data types


Type Size (byte) Range
char 1 0 to 255
int 2 -32,768 to +32,767
unsigned 2 0 to 65535
short int 1 -128 to +127
long int 4 -2,147,483,648 to -2,147,483,647
float 4 +/- 3.4E-38 to +/-3.4E+38
double 8 +/- 1.7E-308 to +/-1.7E308

2.3 Operator
Bit Operators
& AND (binary)
| OR (binary)
^ Exclusive OR (binary)
- One's complement (Unary)
>> Shift right (Unary, with number of bit position)
<< Shift left (Unary, with number of bit position)

Mathematic Operators
Operator Operation Expression
+ addition x+y
- substraction x-y
* multiplication x*y
/ division x/y
% modulus x%y
++ increment x++, ++x
-- decrement x--, --x

Assignment Operators
Operator Operation Equivalent to
= x=y x=y
+= x+=y x=x+y
-= x-=y x=x-y
*= x*=y x=x*y
/= x/=y x=x/y
%= x%/y x=x%y

Relational Operators
Equal ==
Greater than >
Less than <
Greater than or equal to >=
Less than or equal to <=
Not equal to !=

Logical Operators
AND &&
OR ||
NOT !
Comment
/* ------------------ */
//---------------------
Example
/*This is a comment*/
//This whole line is a comment
2.4 Name
Identifiers
An identifier is the symbolic name used to represent objects in a C
program. An identifier must
- consist only of alphanumeric character (letters and digits) and
underscore(_)
- start with a letter or an underscore.
- must not be the same as keywords.
- case sensitive
- must not contain space

Variable
A variable is a region of memory whose value can be changed by
a program.
eg. int c=10;
c++; //the value of c is changed to 11.

You might also like