Professional Documents
Culture Documents
#include <iostream>
int main()
{
cout<<"Welcome to C++ Programming"<<endl;
return 0;
}
Output:
Welcome to C++ Programming
The smallest individual unit of a program written in any language is
called a token.
Special-Symbols
The following are some of the special symbols
+ - * /
. ; ? ,
<= != == >=
Word-symbols
int, float, double, char, void, return
Blank space is a character and is written ' ', with a space left
between the single quotes.
ASCII Character Set - p.1037
Each of the 128 values of the ASCII character set represents a
different character.
The value 65 represents 'A', and the value 43 represents '+'.
The value representing 'B' is 66, so 'A' is smaller than 'B'.
'+' is smaller than 'A' since 43 is smaller than 65.
The first 32 characters in the ASCII character set are nonprintable.
The 14th character in the set is the new line character.
In C++, the new line character is represented as '\n'.
The horizontal tab character is represented in C++ as '\t'.
The null character is represented as '\0'.
Floating-Point Data Types
• Scientific notation
43872918 = 4.3872918 *10^7 {10 to the power of seven},
.0000265 = 2.65 * 10^(-5) {10 to the power of minus five},
47.9832 = 4.7983 * 10^1 {10 to the power of one}
• Arithmetic Expressions
3 + 4
2 + 3 * 5
5.6 + 6.2 * 3
x + 2 * 5 + 6 / y
In the expression
–5
– has only one operand, which is 5 and so - acts as a unary
operator.
In the expression
+27
+ is a unary operator.
Example 2-4
Arithmetic
Expression Result Description
2 + 5 7
45 - 90 -45
2 * 7 14
5/2 2 In the division 5/2, the quotient is
2
34 % 5 4 In the division 34/5, the quotient is 6
and
the remainder is 4.
5.0 + 3.5 8.5
5.0/2.0 2.5
Order of Precedence
*, /, %
+, -
static_cast<dataTypeName>(expression)
static_cast<double>(25) = 25.0
static_cast<double>(5+3) = static_cast<double>(8)
= 8.0
static_cast<int>(7.8 + static_cast<double>(15)/2)
= static_cast<int>(7.8 + 7.5)
= static_cast<int>(15.3) = 15
Variable
The syntax for declaring one variable or multiple variables is
dataType identifier, identifier, . . .;
•Example 2-12
int counter;
char ch;
int x, y;
string name;
cin>>miles;
By using more than one variable in cin, more than one value can be read at a
time.
Suppose feet and inch are variables of the type int. A statement like
cin>>feet>>inch;
INCREMENT AND DECREMENT OPERATORS
++count; or count++;
increments the value of count by 1.
--count; or count--;
decrements the value of count by 1.
1.
x = 5;
y = ++x;
• After the second statement both x and y are 6.
2.
x = 5;
y = x++;
• After the second statement y is 5 and x is 6.
Example 2-16
Suppose a and b are int variables.
a = 5;
b = 2 + (++a);
After the second statement a is 6 and b is 8.
OUTPUT
The syntax of cout together with << is
cout<<expression or manipulator<<expression or
manipulator...;
cout<<29/4<<endl; 7
cout<<3.0/2<<endl; 1.5
cout<<"Hello there.\n"; Hello there.
cout<<"a"<<endl; 65
cout<<b<<‘\n’; 78
cout << endl;
When these two statements execute in the order given, first the cout
statement causes the following line of text to appear on the screen:
After seeing this line, users know that they must enter a number and
press the return key.
Compound assignment operator
op=
where op is any of the arithmetic operators.
I = I + 5;
I += 5;