Skip to content

Commit cdb7b8b

Browse files
committed
Revert "Added java code in operators.md"
This reverts commit 8832662.
1 parent 9a44bdc commit cdb7b8b

File tree

1 file changed

+66
-40
lines changed

1 file changed

+66
-40
lines changed

lessons/operators.md

Lines changed: 66 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: "Learn java"
77
---
88

99
Operators are symbols that tell the compiler to perform some specfic operations.
10-
In JAVA, there are many operators, and they are grouped into several categories.
10+
In C++, there are many operators, and they are grouped into several categories.
1111
We are going to learn some of the important operators only. You will see these operators in most of the section and this will cover almost every problem you will encounter in your programming journey.
1212

1313
Ok, So there are basically 6 categories of operators:
@@ -31,9 +31,9 @@ Arithmetric operators are used to perform arithmetic operations. They are used t
3131

3232
Ok so let's learn about the incrementer and decrementer operators now because they are very important.
3333

34-
### Incrementer and Decrementer Operators/ Unary Operators
34+
### Incrementer and Decrementer Operators
3535

36-
In Java there are two types of incrementer and decrementer operators:
36+
In C++ there are two types of incrementer and decrementer operators:
3737

3838
- **Incrementer Operator**: used to increment the value of the operand by 1.
3939
- **Decrementer Operator**: used to decrement the value of the operand by 1.
@@ -77,25 +77,25 @@ Logical operators are used to perform logical operations. They are used to perfo
7777

7878
let's see an example:
7979

80-
```Java
80+
```cpp
8181
// program to find whether a number is divible by both 3 and 5
8282
// or divisible by only one of them
83-
import java.util.Scanner;
84-
public class Main
85-
{
86-
public static void main(String[] args) {
87-
Scanner sc=new Scanner(System.in);
88-
System.out.println("Enter a number: ");
89-
int a=sc.nextInt();
90-
91-
if(a%3==0 && a%5==0)
92-
System.out.println("The number is divisible by both 3 and 5");
83+
84+
#include <iostream>
85+
using namespace std;
86+
87+
int main() {
88+
int a;
89+
cout<<"Enter a numbers: ";
90+
cin>>a;
91+
if(a%3==0 && a%5==0)
92+
cout<<"the number is divisible by both 3 and 5";
9393
else if(a%3==0 || a%5==0)
94-
System.out.println("The numbers is divisible by only one of them");
94+
cout<<"the numbers is divisible by only one of them";
9595
else
96-
System.out.println("The numbers is not divisible by any of them");
96+
cout<<"the numbers is not divisible by any of them";
97+
return 0;
9798
}
98-
}
9999
```
100100
101101
let's see the explanation:
@@ -174,7 +174,7 @@ eg: let 8 >> 1 == ?
174174
175175
here one thing to keep in mind that `>>` operator shifts the bits to the right and `<<` shifts the bits to the left. there is a way to find right shift and left shift of a number.
176176
177-
```java
177+
```cpp
178178
Right Shift --> a >> n ==> a * 2^n
179179
Left Shift --> a << n ==> a / 2^n
180180
```
@@ -183,39 +183,65 @@ Left Shift --> a << n ==> a / 2^n
183183
184184
This category contains the following operators:
185185
186+
- `sizof()`: it returns the size of the operand in bytes.
187+
188+
```cpp
189+
int a=5;
190+
cout<<"the size of a is "<<sizof(a)<<" bytes";
191+
```
192+
193+
The next one is:
194+
186195
- `condition ? true_expression : false_expression`: it evaluates the true_expression if the condition is true and false_expression if the condition is false.
187196
188-
```java
197+
```cpp
189198
// syntax
190199
// variable = Expression1 ? Expression2 : Expression3;
191200

192-
public class Main
193-
{
194-
public static void main(String[] args) {
195-
int num=15;
196-
String msg = num > 10
197-
? "Number is greater than 10"
198-
: "Number is less than or equal to 10";
199-
System.out.println(msg);
201+
int main() {
202+
int a=5, b=6;
203+
(a > b) ? cout<<"a is greater than b"<<endl : cout<<"a is less than b";
204+
return 0;
200205
}
201-
}
206+
```
207+
208+
- `cast`: it converts the value of the operand to the type of the right operand.
202209
210+
```cpp
211+
eg: int ch = 'a';
212+
int ch = (int)'a';
203213
```
204214

205-
- `typecasting`: it converts the value of the operand to the type of the right operand.
206-
eg:
207-
```java
208-
public class Main
209-
{
210-
public static void main(String[] args) {
211-
char ch = 'a';
212-
int typecasted_character = (int)'a';
213-
System.out.println(ch);
214-
System.out.println(typecasted_character);
215+
- `comma(,)`: causes a series of operations to occur in the order they are written.
216+
217+
```cpp
218+
int main() {
219+
int a=5, b=6;
220+
(a, b) = (b, a);
221+
return 0;
215222
}
216-
}
217223
```
224+
225+
- `Reference(&) operator`: it is used to get the address of the operand.
226+
227+
```cpp
228+
int main() {
229+
int a=5;
230+
cout<<"the address of a is "<<&a<<endl;
231+
return 0;
232+
}
233+
```
234+
235+
- `dereference(*) or pointer`: it is used to get the value of the operand. it is also known as \* pointer. Pointer is used to access the memory location of the variable.
236+
237+
```cpp
238+
int main() {
239+
int a=5;
240+
cout<<"the value of a is "<<*&a<<endl;
241+
return 0;
242+
}
243+
```
244+
218245
## **Operators Precedence**
219246
220247
Operators Precedence is the order in which the operators are evaluated. Below is the precedence of the operators.
221-

0 commit comments

Comments
 (0)