Show Menu

Dart vs C++ Cheat Sheet (DRAFT) by

a comparison between c++ and dart syntax

This is a draft cheat sheet. It is a work in progress and is not finished yet.

C++ helloworld

int main() {
   cout << "Hello World"; // prints Hello World
   return 0;

C++ data types

c++ is statically typed
'type variab­le_­list;'

c++ variables

type variable_name = value;
int    i, j, k;
char   c, ch;
float  f, salary;
double d;
lvalue − Expres­sions that refer to a memory location is called "­lva­lue­" expres­sion.
rvalue − The term rvalue refers to a data value that is stored at some address in memory.

C++ operators


Storage Classes in C++

default storage class for all local variables
used to define local variables that should be stored in a register instead of RAM.
keep a local variable in existence during the life-time of the program instead of creating and destroying it each time
is used to give a reference of a global variable that is visible to ALL the program files.
It allows a member of an object to override const member functi­on(­applies only to class objects)

Dart helloworld

 main() or (void main())
   print("Hello World!"); 

dart data types

lists are equivalent of arrays­(or­dered lists)
Maps represent a collection of objects, Map data type represents a set of values as key-value pairs.
Dart is an optionally typed language. If the type of a variable is not explicitly specified, the variable’s type is dynamic. The dynamic keyword can also be used as a type annotation explic­itly.

Dart variables

String name = 'Smith';
dynamic x = "tom";
final variable_name;
const variable_name;
-All uninit­ialized variables have an initial value of null. This is because Dart considers all values as objects.
-Variables declared without a static type are implicitly declared as dynamic. Variables can be also declared using the dynamic keyword in place of the var keyword.
-The final and const keyword are used to declare constants, These keywords can be used together with the variable’s data type or instead of the var keyword.
-The const keyword is a compile time const.

Dart operators

in addition to c style operators
Unary minus, also known as negation (reverse the sign of the expres­sion)
Divide, returning an integer result
it is
it is not
Assign the value only if the variable is null

Dart for in loop

for (variablename in object){  
   statement or block to execute  
void main() { 
   var obj = [12,13,14]; 
   for (var prop in obj) {