Last active
December 20, 2022 08:54
-
-
Save amani27/8d9c74af7dc09d882236f390e7cf1dc3 to your computer and use it in GitHub Desktop.
Demonstrating Dart arithmetic operators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void main() { | |
| int a = 16; | |
| int b = 5; | |
| var c = a / b; // Division operator | |
| print('c = $c'); // Returns division result - double values | |
| var i = a ~/ b; // Tilde slash operator | |
| print('i = $i'); // Returns integer part of division result | |
| var r = a % b; // Modulus operator | |
| print('r = $r'); // Returns remainder of division | |
| ++a; | |
| print('a = $a'); | |
| a++; | |
| print('a = $a'); | |
| int a1, a2; | |
| a1 = a++; // first assigns value and only then increments | |
| print('a1 = $a1'); | |
| a2 = ++a; // vice-versa to a++ | |
| // first increments and then assigns value | |
| print('a2 = $a2'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment