-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperators.cpp
More file actions
40 lines (30 loc) · 2.02 KB
/
Operators.cpp
File metadata and controls
40 lines (30 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using namespace std;
#include<iostream>
int main()
{
int a,b,c=0;
cout<<"Enter First number: ";
cin>>a;
cout<<"Enter Second number: ";
cin>>b;
//Here "++a" indicates value of a will be printed after an increment. For example if entered a = 6, it will show 7, the incremented value.
//"++a" is known as preincrement operator.
/*Now "b++" is actually indicative of the value first printed and then being incremented. Which means the values will be
first shown for example b = 6 will be shown as is 6 in output and later on it's value will be increased to 7 which won't be shown.*/
cout<<"Unary Operations (numbers++) and (++numbers): "<< ++a <<" "<< b++ <<"\n";
//Binary Operations are simply the operations that take place in simplest form in physical world.
cout<<"Binary Operations (number+number): "<< a+b <<"\n";
//Here the brackets '(' and ')' are very important as they give the emphasis on executing the operation that way.
/*The (a>b) simply means to ask if the operation is true or not, whichever the result will be displayed whereas (a:b) does the same
now the use of '?' is to give the correct answer. If the first condition (a>b) is true that will be printed but if it is false, the later
condition will be printed. */
cout<<"Ternary Operator: "<< ((a>b) ? a:b) <<"\n";
//Here the relational operator is put in brackets to emphasize again the procedure, whatever the result it will be displayed.
cout<<"Relational Operator: "<< (a<b) <<"\n";
//The logical operator "&&" suggests 'and' and "||" suggests 'or' use of operations.
//Conditions are if (true&&false) the value will be false. If (true&&true) the value will be true as well. In case of last, it will be true as well.
cout<<"Logical Operator: "<< (true&&false) <<" "<< (true&&true) << (true||false) <<"\n";
//The assignment operator here in place of c simply means c=c+a, whatever the value of c will be added to a and the new value of c will be printed.
cout<<"Assignment Operator: Sum: c="<<(c+=a)<<"\n";
return 0;
}