comp611-TurboC (Chap 2)
comp611-TurboC (Chap 2)
Elementary C++
2.1 Program Layout
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.