Posts

Showing posts from October, 2018

C: Pointers & Arrays

- Pointer Variables which store the addresses of other variables (including other pointers). Initialized by *(variable name). int x; int *aa; aa = &x; *aa is a pointer which stores the address of x. - Array Groups of variables stored with same variable names. Initialized by (variable name)[array size]. int aa[5]; aa is an array which can store up to five integer variables. - Two-Dimensional & Three-Dimensional Arrays Two-Dimensional Arrays can be initialized by (variable name)[length][width]. The amount of variables which can be stored is length*width. Three-Dimensional Arrays can be initialized by (variable name)[length][width][height]. The amount of variables which can be stored is length*width*height. - Accessing Arrays aa[(array size)]; Variables are stored in aa[0] to aa[(array size - 1)]. Any element of an array can be accessed through either *(aa+x) or aa[x], where x is (element number - 1). For example, to access the second element, ei...

C: Selection

Selection, in programming, is a method of specifying conditions in which statements are executed. - If Used as: if(boolean expression) { statement; } The statement will be run only if the boolean expression results in true. - If... else... Used as: if(boolean expression) { statement; } else { statement2; } The first statement will be run if its boolean expression results in true. If it results in false, statement2 will be run instead. - Nested if Used as: if(boolean expression) { if(boolean expression) { statement; } } The statement will be run only if every boolean expression leading to it results in true. - Switch case Used as: switch(expression) { case constant: statement; break; case constant2: statement2; break; default: statement3; } A statement will be run only if the expression is equal to the constant leading to it. If no constant matches the expression, the default statement will ...