From 164c13f813529c0462b07db4aab31c5d5d91dcd6 Mon Sep 17 00:00:00 2001 From: raulvillora Date: Wed, 14 Mar 2018 15:39:28 +0100 Subject: [PATCH 1/7] Create C.txt Brief summary of C --- languages/C.txt | 241 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 languages/C.txt diff --git a/languages/C.txt b/languages/C.txt new file mode 100644 index 0000000..5ed3de5 --- /dev/null +++ b/languages/C.txt @@ -0,0 +1,241 @@ + + +main() Function + +* The main() function is the starting point of the program: int main (int argc, char *argv[]) +* The return type of the main() function is an integer (type int) and it is known as the return value of the program. +* As a rule of thumb, value 0 means success while non-zero means an error conditions. + +Include Files + +* The purpose of these files is to tell the compiler about the existence of external functions which the source code will make use of. + +Preprocessor directives: + #include "mine.h" search current working directory first + #include search command line directory then system + #define TRUE 1 macro substitution, usually use capitals + #define min(a,b) (a selector, structure pointer + . select structure element + ! relational not, complement, ! a yields true or false + ~ bitwise not, ones complement, ~ a + ++ increment, pre or post to a variable + -- decrement, pre or post to a variable + - unary minus, - a + + unary plus, + a + * indirect, the value of a pointer, * p is value at pointer p address + & the memory address, & b is the memory address of variable b + sizeof size in bytes, sizeof a or sizeof (int) + (type) a cast, explicit type conversion, (float) i, (*fun)(a,b), (int*)x + * multiply, a * b + / divide, a / b + % modulo, a % b + + add, a + b + - subtract, a - b + << shift left, left operand is shifted left by right operand bits + >> shift right, left operand is shifted right by right operand bits + < less than, result is true or false, a %lt; b + <= less than or equal, result is true or false, a <= b + > greater than, result is true or false, a > b + >= greater than or equal, result is true or false, a >= b + == equal, result is true or false, a == b + != not equal, result is true or false, a != b + & bitwise and, a & b + ^ bitwise exclusive or, a ^ b + | bitwise or, a | b + && relational and, result is true or false, a < b && c >= d + || relational or, result is true or false, a < b || c >= d + ? exp1 ? exp2 : exp3 result is exp2 if exp1 != 0, else result is exp3 + = store + += add and store + -= subtract and store + *= multiply and store + /= divide and store + %= modulo and store + <<= shift left and store + >>= shift right and store + &= bitwise and and store + ^= bitwise exclusive or and store + |= bitwise or and store + , separator as in ( y=x,z=++x ) + + +Operator precedence + +More precedence + +LR ( ) [ ] -> . x++ x-- +RL ! ~ - + ++x --x * & sizeof (type) +LR * / % +LR + - +LR << >> +LR < <= > >= +LR == != +LR & +LR ^ +LR | +LR && +LR || +RL ? : +RL = += -= *= /= %= >>= <<= &= ^= |= +LR , + +Less precedence + +Conditional branching + + if ( condition ) statement ; + else statement_2 ; /* optional else clause */ + +Switch statement + +switch ( expression ) /* constants must be unique */ + { + case constant_1: /* do nothing for this case */ + break; + case constant_2: /* drop through and do same as constant_3*/ + case constant_3: + statement_sequence /* can have but does not need { } */ + break; + case constant_4: + statement_sequence /* does this and next */ + /* statement_sequence also*/ + case constant_5: + statement_sequence + break; + default: /* default executes if no constant equals*/ + statement_sequence /* the expression. This is optional */ + } + +Function definition + +type function_name(int a, float b, const char * ch,...) { function_body } + +/* only parameters passed by address can are modified*/ + +/* in the calling function, local copy can be modified*/ + +char * strcpy( char * s1, const char * s2 ) { statements } + +Declarations forms + +basic_type variable; + +type variable[val][val]...[val]={data,data,...}; /*multidimensional array*/ + +struct struct_name { /* struct_name is optional */ + type variable_1; /* any declaration */ + … /* all variable names must be unique*/ +} variable_1, ... ; /* variables are optional */ + +struct struct_name { /* struct_name is optional */ + type variable_1: length; /* any declaration : length in bits */ + ... /* type is int, unsigned or signed */ +} variable_1, ... ; /* variables are optional, they can also be arrays and pointers */ + + +union union_name { /* union_name is optional */ + type variable_1; /* variable_1 overlays variable_2 */ + type variable_2; + ... +} variable_a, ...; /* variables are optional */ + +enum enum_type /* enum_name is optional */ + { enumeration_name_1, /* establishes enumeration literals */ + enumeration_name_2=number,/* optional number, */ + ... /* default is 0, 1, 2, ... */ + } variable, ...; /* variables are optional */ + + /* use dot notation to select a component of a struct or union */ + From 5429e1d64afc50427074b3ed608216c2986d169c Mon Sep 17 00:00:00 2001 From: kobus Date: Fri, 20 Apr 2018 09:32:20 +0200 Subject: [PATCH 2/7] PHP Globals --- languages/php.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/languages/php.php b/languages/php.php index 4c8d311..a080fe0 100644 --- a/languages/php.php +++ b/languages/php.php @@ -1,5 +1,20 @@ Date: Fri, 20 Apr 2018 09:34:02 +0200 Subject: [PATCH 3/7] Add link --- languages/php.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/languages/php.php b/languages/php.php index a080fe0..61e7e00 100644 --- a/languages/php.php +++ b/languages/php.php @@ -1,7 +1,12 @@ Date: Fri, 20 Apr 2018 09:58:36 +0200 Subject: [PATCH 4/7] Ways of looping --- languages/php.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/languages/php.php b/languages/php.php index 61e7e00..8fd9ac3 100644 --- a/languages/php.php +++ b/languages/php.php @@ -3,6 +3,48 @@ /** * */ +/** + * Ways of looping + */ +continue; // Skip current iter +break; // Exit loop + +// Foreach +foreach($arr as $key => $value) { + $key = $key; + $value = $value; +} + +// For +for($i = 0; $i < count($arr) - 1; $i++) { + $key = $i; + $value = $arr[$i]; +} + +// While +$i = 0; +while($i < count($arr) - 1) { + $key = $i; + $value = $arr[$i]; +} + +// Do while +$i = 0; +do { + $key = $i; + $value = $arr[$i]; +} while($i < count($arr)); + +// Switch +switch($arr) { + case 1: + break; + case 2: + break; + case 3: + break; + default: +} /** * Global variable From 6482a577f5e0ed9f7204e5f238bdf4fca4d72369 Mon Sep 17 00:00:00 2001 From: kobus Date: Fri, 20 Apr 2018 09:58:57 +0200 Subject: [PATCH 5/7] Printing --- languages/php.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/languages/php.php b/languages/php.php index 8fd9ac3..bb6c6e7 100644 --- a/languages/php.php +++ b/languages/php.php @@ -1,8 +1,12 @@ Date: Fri, 20 Apr 2018 09:59:34 +0200 Subject: [PATCH 6/7] Die at start of file --- languages/php.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/languages/php.php b/languages/php.php index bb6c6e7..2b49f1a 100644 --- a/languages/php.php +++ b/languages/php.php @@ -1,5 +1,9 @@ Date: Fri, 20 Apr 2018 09:59:53 +0200 Subject: [PATCH 7/7] Spelling --- languages/php.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/languages/php.php b/languages/php.php index 2b49f1a..78a565f 100644 --- a/languages/php.php +++ b/languages/php.php @@ -55,14 +55,14 @@ switch($arr) { } /** - * Global variable + * Global variables * http://php.net/manual/en/language.variables.superglobals.php */ $_SERVER; // SERVER variables $_GET; // Query params $_POST; // Post fields $_REQUEST; // GET and POST together -$GLOBALS; // Collection of global variables +$GLOBALS; // Array of global variables $_SESSION; // Browser session $_FILES; // Array of files that are sent in request $_COOKIE; // Array of cookies sent in request