Introduction To C++ 02
Introduction To C++ 02
#include <iostream>
#define LENGTH 10
#define WIDTH 5
int main() {
int area;
return 0;
When the above code is compiled and executed, it produces the following
result −
50
The const Keyword
You can use const prefix to declare constants with a specific type as follows
−
const type variable = value;
#include <iostream>
int main() {
int area;
return 0;
When the above code is compiled and executed, it produces the following
result −
50
Operators in C++
An operator is a symbol that tells the compiler to perform specific
mathematical or logical manipulations. C++ is rich in built-in operators and
provide the following types of operators −
Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Assignment Operators
Misc Operators
Arithmetic Operators
There are following arithmetic operators supported by C++ language −
Relational Operators
There are following relational operators supported by C++ language
Logical Operators
There are following logical operators supported by C++ language.
Assignment Operators
There are following assignment operators supported by C++ language –
Decision making structures require that the programmer specify one or more
conditions to be evaluated or tested by the program, along with a statement
or statements to be executed if the condition is determined to be true, and
optionally, other statements to be executed if the condition is determined to
be false.
if (testExpression)
// statements
#include <iostream>
using namespace std;
int main()
{
int number;
cout << "Enter an integer: ";
cin >> number;
}
Output 1
Enter an integer: 5
Output 2
Enter a number: -5
C++ if...else
The if else executes the codes inside the body of if statement if the test expression is
true and skips the codes inside the body of else.
If the test expression is false, it executes the codes inside the body of else statement
and skips the codes inside the body of if.
#include <iostream>
using namespace std;
int main()
{
int number;
cout << "Enter an integer: ";
cin >> number;
if ( number >= 0)
{
cout << "You entered a positive integer: " << number << endl;
}
else
{
cout << "You entered a negative integer: " << number << endl;
}
Output
Enter an integer: -4