21
loading...
This website collects cookies to deliver better user experience
// addition
print(1 + 2); // will return 3
// subtraction
print(2 - 1); // will return 1
// multiplication
print(2 * 2); // will return 4
// double division
print(5 / 2); // will return 2.5;
// integer division
print(5 ~/ 2); // will return 2;
// modulus
print(5 %2 ); // will return 1;
void main() {
var a = 0;
// what do you think the output will be?
print(increaseNum(a));
}
int increaseNum(int num) {
return num++;
}
void main() {
var a = 0;
// will print 1
print(increaseNum(a));
}
int increaseNum(int num) {
return ++num;
}
void main() {
var a = 0;
print(increaseNum(a));
}
int increaseNum(int num) {
return num += 1;
}
// basic assignment operator
var a = 1;
// will print 2
var a = 1;
print(a += 1);
// will print 0
var a = 1;
print(a -= 1);
// will print 1
var a = 1;
print(a *= 1);
// this actually won't compile because we can't assign a double to an int
var a = 1;
print(a /= 1);
// will print 1
var a = 1;
print(a ~/= 1);
// true
print(0 < 1);
// false
print(0 > 1);
// true
print(0 <= 1);
// false
print(0 >= 1);
// true
print(1 == 1);
// true
print(0 != 1);
There's 3 logical operators:
There are "truth tables" you can look up to get a better understanding of these logical operators. Here's an example of one: