Comp611-Turbo C (Chap 2)
Comp611-Turbo C (Chap 2)
Programming I
Comp-611
Chapter 2
Elementary C++
2.1 Program Layout
#include<header file name>
void main()
{
variable declaration;
executable statements;
}
#include<header file name>
void main()
{
variable declaration;
executable statements;
}
2.1 Program Layout
#include<header file name>
main()
{
variable declaration;
executable statements;
return 0;
}
2.2 Data types
Type Size Range
(byte)
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 –,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)
2.3 Operator
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
2.3 Operator
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
2.3 Operator
Relational Operators
Equal ==
Not equal to !=
2.3 Operator
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
2.4 Name
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.