CMPE 011 - Module 1-Intro
CMPE 011 - Module 1-Intro
1
std::cout << "Hello World!"; * Multiplication Multiplies two x*y
values
return 0;
} / Division Divides one value x/y
by another
IV. Comments
V. Variables Assignment Operators
Assignment operators are used to assign values to
VI. OC++ Conditions and If Statements
variables. In the example below, we use the assignment
Operators are used to perform operations on
operator (=) to assign the value 10 to a variable called x:
variables and values. In the example below, we use
the + operator to add together two values:
int x = 100 + 50; int x = 10;
Although the + operator is often used to add The addition assignment operator (+=) adds a
together two values, like in the example above, it can value to a variable:
also be used to add together a variable and a value, or a
variable and another variable: int x = 10;
x += 5;
int sum1 = 100 + 50; // 150 (100 + 50)
int sum2 = sum1 + 250; // 400 (150 + 250)
int sum3 = sum2 + sum2; // 800 (400 + 400) A list of all assignment operators:
/= x /= 3 x=x/3
Arithmetic Operators
Arithmetic operators are used to perform %= x %= 3 x=x%3
common mathematical operations.
&= x &= 3 x=x&3
|= x |= 3 x=x|3
OPERATOR Name Description Example
^= x ^= 3 x=x^3
+ Addition Adds together two x+y
values
>>= x >>= 3 x = x >> 3
- Subtraction Subtracts one x-y
value from another <<= x <<= 3 x = x << 3
2
VII. User Input
Assignment Operators
Comparison operators are used to compare two
values. Note: The return value of a comparison is either
true (1) or false (0). In the following example, we use the
greater than operator (>) to find out if 5 is greater than 3:
int x = 5;
int y = 3;
cout << (x > y); // returns 1 (true) because 5 is greater
than 3
== Equal to x == y
!= Not equal x != y
Logical Operators
Logical operators are used to determine the
logic between variables or values:
3
SOURCES:
● https://www.w3schools.com/cpp/cpp_operator
s.asp