From 82a8d0e5b4807dfb264951b20444b1d14bf2c95c Mon Sep 17 00:00:00 2001 From: Ajay T Shaju Date: Mon, 18 Sep 2023 21:05:16 +0530 Subject: [PATCH 1/6] first --- languages/C.md | 1 + languages/C.txt | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) create mode 100644 languages/C.md diff --git a/languages/C.md b/languages/C.md new file mode 100644 index 00000000..a435ccb8 --- /dev/null +++ b/languages/C.md @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/languages/C.txt b/languages/C.txt index ca721f53..b33c3a54 100644 --- a/languages/C.txt +++ b/languages/C.txt @@ -1,5 +1,3 @@ - - main() Function * The main() function is the starting point of the program: int main (int argc, char *argv[]) From ca5e153c6d8d09302efb6c393c12edc095e0d7e5 Mon Sep 17 00:00:00 2001 From: Ajay T Shaju Date: Mon, 18 Sep 2023 21:10:32 +0530 Subject: [PATCH 2/6] initial --- README.md | 2 +- languages/C.md | 8 +++++++- languages/C.txt | 5 ----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 984ca006..5191b897 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Feel free to take a look. You might learn new things. They have been designed to #### Imperative -- [C](languages/C.txt) +- [C](languages/C.md) - [C#](languages/C%23.txt) - [Go](languages/golang.md) - [Java](languages/java.md) diff --git a/languages/C.md b/languages/C.md index a435ccb8..5b04aa2a 100644 --- a/languages/C.md +++ b/languages/C.md @@ -1 +1,7 @@ - \ No newline at end of file + + +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.``` diff --git a/languages/C.txt b/languages/C.txt index b33c3a54..8ff450d0 100644 --- a/languages/C.txt +++ b/languages/C.txt @@ -1,8 +1,3 @@ -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 From d7fdfb674586a1bb1f6955a0c54d7378150570b2 Mon Sep 17 00:00:00 2001 From: Ajay T Shaju Date: Mon, 18 Sep 2023 22:03:19 +0530 Subject: [PATCH 3/6] new chnage --- languages/C.md | 43 ++++++++++++++++++++++++++++++++++++++++++- languages/C.txt | 30 ------------------------------ 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/languages/C.md b/languages/C.md index 5b04aa2a..79c93c66 100644 --- a/languages/C.md +++ b/languages/C.md @@ -1,7 +1,48 @@ -main() Function +```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: + +| Directive | Description | +|-----------------------------|----------------------------------------------------| +| `#include "mine.h"` | Search current working directory first. | +| `#include ` | Search command line directory, then the system. | +| `#define TRUE 1` | Macro substitution, usually use capitals. | +| `#define min(a,b)` | Macro substitution with parameters. | +| `#define abs(a)` | Macro substitution. | +| `#define note /* comment */` | This comment gets inserted every time `note` appears. | +| `backslash \ at end of a line` | Means continue the line. | +| `#undef TRUE` | Undefines a previously defined macro name. | +| `#error` | Stop compiling at this point. | +| `#if expression` | Conditional compilation, starts an `if` structure. | +| `#elif expression` | Else if expression != 0, compile the following code. | +| `#else` | Else, compile the following code. | +| `#endif` | End of conditional compiling. | +| `#ifdef macroname` | Like `#if`, compiles if `macroname` is defined. | +| `#ifndef macroname` | Like `#if`, compiles if `macroname` is undefined. | +| `#line number [filename]` | Set the origin for `__LINE__` and `__FILE__`. | +| `#pragma` | Gives the compiler commands. | + +--- + +## Create and execute a program + +In Linux systems: + 1. Open up a terminal (Ctrl + Alt + T) + 2. Create the program: nano nameProgram.c + 3. Write the program and save it + 4. gcc -o nameExecutable nameProgram.c (eg: gcc -o nameProgram_output nameProgram.c +) \ No newline at end of file diff --git a/languages/C.txt b/languages/C.txt index 8ff450d0..8f751763 100644 --- a/languages/C.txt +++ b/languages/C.txt @@ -1,34 +1,4 @@ -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 Date: Mon, 18 Sep 2023 22:04:53 +0530 Subject: [PATCH 4/6] commit --- languages/C.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/languages/C.md b/languages/C.md index 79c93c66..67ab08c9 100644 --- a/languages/C.md +++ b/languages/C.md @@ -1,16 +1,14 @@ - +### main() Function -```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.``` +* 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. +* The purpose of these files is to tell the compiler about the existence of external functions which the source code will make use of. --- @@ -41,8 +39,11 @@ ## Create and execute a program In Linux systems: + 1. Open up a terminal (Ctrl + Alt + T) + 2. Create the program: nano nameProgram.c + 3. Write the program and save it - 4. gcc -o nameExecutable nameProgram.c (eg: gcc -o nameProgram_output nameProgram.c -) \ No newline at end of file + + 4. gcc -o nameExecutable nameProgram.c (eg: gcc -o nameProgram_output nameProgram.c) \ No newline at end of file From 8e3299d2dffc43a05abb032f192f9a5679e050e0 Mon Sep 17 00:00:00 2001 From: Ajay T Shaju Date: Mon, 18 Sep 2023 22:30:58 +0530 Subject: [PATCH 5/6] test --- languages/C.md | 197 ++++++++++++++++++++++++++++++++++++++++++++++-- languages/C.txt | 139 ---------------------------------- 2 files changed, 191 insertions(+), 145 deletions(-) diff --git a/languages/C.md b/languages/C.md index 67ab08c9..5290f99b 100644 --- a/languages/C.md +++ b/languages/C.md @@ -1,4 +1,4 @@ -### main() Function +#### 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. @@ -6,13 +6,13 @@ --- -## Include Files +### 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. +* 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: +### Preprocessor directives: | Directive | Description | |-----------------------------|----------------------------------------------------| @@ -36,7 +36,7 @@ --- -## Create and execute a program +### Create and execute a program In Linux systems: @@ -46,4 +46,189 @@ In Linux systems: 3. Write the program and save it - 4. gcc -o nameExecutable nameProgram.c (eg: gcc -o nameProgram_output nameProgram.c) \ No newline at end of file + 4. gcc -o nameExecutable nameProgram.c (eg: gcc -o nameProgram_output nameProgram.c) + +--- + +### Reserved words (32) + +| Term | Description | +|------------|------------------------------------------------------------| +| `auto` | Optional local declaration | +| `break` | Used to exit a loop and used to exit a `switch` statement | +| `case` | Choice in a `switch` statement | +| `char` | Basic declaration of a type character | +| `const` | Prefix declaration meaning the variable cannot be changed | +| `continue` | Go to the bottom of a loop in `for`, `while`, and `do` loops | +| `default` | Optional last case of a `switch` statement | +| `do` | Executable statement, `do-while` loop | +| `double` | Basic declaration of double precision floating point | +| `else` | Executable statement, part of an "if" structure | +| `enum` | Basic declaration of enumeration type | +| `extern` | Prefix declaration meaning the variable is defined externally | +| `float` | Basic declaration of floating point | +| `for` | Executable statement, `for` loop | +| `goto` | Jump within a function to a label | +| `if` | Executable statement | +| `int` | Basic declaration of an integer | +| `long` | Prefix declaration applying to many types | +| `register` | Prefix declaration meaning to keep a variable in a register | +| `return` | Executable statement with or without a value | +| `short` | Prefix declaration applying to many types | +| `signed` | Prefix declaration applying to some types | +| `sizeof` | Operator applying to variables and types, gives size in bytes | +| `static` | Prefix declaration to make a local variable static | +| `struct` | Declaration of a structure, like a record | +| `switch` | Executable statement for cases | +| `typedef` | Creates a new type name for an existing type | +| `union` | Declaration of variables that share the same memory locations | +| `unsigned` | Prefix declaration applying to some types | +| `void` | Declaration of a typeless variable | +| `volatile` | Prefix declaration meaning the variable can be changed at any time | +| `while` | Executable statement, `while` loop or `do-while` loop | + +--- + +### Basic types + +| Type | Description | +|---------|--------------------------------------------------------| +| `char` | Character type, usually one byte (a string is an array of `char`) | +| `int` | Integer type, usually 2 or 4 bytes (default) | +| `float` | Floating-point type, usually 4 bytes | +| `double`| Floating-point type, usually 8 bytes | +| `void` | No type, typeless | +| `enum` | Enumeration type (user defines the type name) | + +--- + +### Type modifiers, prefix for basic types + +| Modifier | Description | +|------------|--------------------------------------------------------| +| `signed` | Has a sign (default) | +| `unsigned` | No sign bit in the variable | +| `long` | Longer version of a type (e.g., `long int`) | +| `short` | Shorter version of a type (e.g., `short int`) | +| `const` | Variable cannot be modified or stored into | + +--- + +### Storage Types + +| Prefix | Description | +|-----------|-------------------------------------------------------| +| `auto` | Local variable (default) | +| `static` | Permanent, exists beyond function scope (not `auto`) | +| `volatile`| Can change from external influences | +| `extern` | Variables are defined elsewhere, externally | +| `register`| Suggests that the variable should be stored in a register if possible | + +--- +### Operators + +| Operator | Description | +|----------|----------------------------------------------------| +| `( )` | Grouping parenthesis, function call | +| `[ ]` | Array indexing, also `[ ][ ]` etc. | +| `->` | 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 the 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)` | 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 < 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` | +| `?` | Ternary conditional, `exp1 ? exp2 : exp3`, result is `exp2` if `exp1` is not 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 + +| Associativity | Operators | +|---------------|---------------------------------------------------| +| 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 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 */ + } + +--- + +--- \ No newline at end of file diff --git a/languages/C.txt b/languages/C.txt index 8f751763..8462fafe 100644 --- a/languages/C.txt +++ b/languages/C.txt @@ -1,119 +1,4 @@ - -32 Reserved words - -Term Description -auto optional local declaration -break used to exit loop and used to exit switch -case choice in a switch -char basic declaration of a type character -const prefix declaration meaning variable can not be changed -continue go to bottom of loop in for, while and do loops -default optional last case of a switch -do executable statement, do-while loop -double basic declaration double precision floating point -else executable statement, part of "if" structure -enum basic declaration of enumeration type -extern prefix declaration meaning variable is defined externally -float basic declaration of floating point -for executable statement, for loop -goto jump within function to a label -if executable statement -int basic declaration of integer -long prefix declaration applying to many types -register prefix declaration meaning keep variable in register -return executable statement with or without a value -short prefix declaration applying to many types -signed prefix declaration applying to some types -sizeof operator applying to variables and types, gives size in bytes -static prefix declaration to make local variable static -struct declaration of a structure, like a record -switch executable statement for cases -typedef creates a new type name for an existing type -union declaration of variables that are in the same memory locations -unsigned prefix declaration applying to some types -void declaration of a typeless variable -volatile prefix declaration meaning the variable can be changed at any time -while executable statement, while loop or do-while loop - -Basic types - -Type Description -char character type, usually one byte ( a string is array of char ) -int integer type, usually 2 or 4 bytes ( default ) -float floating point type, usually 4 bytes -double floating point type, usually 8 bytes -void no type, typeless -enum enumeration type ( user defines the type name ) - -Type modifiers, prefix for basic types - -Modifiers Description -signed has a sign ( default ) -unsigned no sign bit in variable -long longer version of type (short or long alone means short int or -short shorter version of type long int because int is the default) -const variable can not be stored into - - -Storage Types - -Prefix Description -auto local variable ( default ) -static permanent when function exits, not auto -volatile can change from outside influence -extern variables are defined elsewhere, externally -register assign variable to register - -Operators - - ( ) grouping parenthesis, function call - [ ] array indexing, also [ ][ ] etc. - -> 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 @@ -136,30 +21,6 @@ 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 From 984b1b0282ca482b9f0b992a862795771f44f805 Mon Sep 17 00:00:00 2001 From: Ajay T Shaju Date: Mon, 18 Sep 2023 22:36:03 +0530 Subject: [PATCH 6/6] Final for C --- languages/C.md | 12 ++++----- languages/C.txt | 65 ------------------------------------------------- 2 files changed, 5 insertions(+), 72 deletions(-) delete mode 100644 languages/C.txt diff --git a/languages/C.md b/languages/C.md index 5290f99b..1968c803 100644 --- a/languages/C.md +++ b/languages/C.md @@ -158,9 +158,9 @@ In Linux systems: | `!=` | Not equal, result is true or false, `a != b` | | `&` | Bitwise and, `a & b` | | `^` | Bitwise exclusive or, `a ^ b` | -| | | Bitwise 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` | +| | | | Relational or, result is true or false, `a < b` | | `c >= d` | | `?` | Ternary conditional, `exp1 ? exp2 : exp3`, result is `exp2` if `exp1` is not 0, else result is `exp3` | | `=` | Store | | `+=` | Add and store | @@ -191,11 +191,11 @@ In Linux systems: | LR | `==`, `!=` | | LR | `&` | | LR | `^` | -| LR | `|` | +| LR | | | | LR | `&&` | -| LR | `||` | +| LR | | | | | RL | `? :` | -| RL | `=`, `+=`, `-=` ,`*=`, `/=`, `%=`, `>>=`, `<<=`, `&=`, `^=`, `|=` | +| RL | `=`, `+=`, `-=` ,`*=`, `/=`, `%=`, `>>=`, `<<=`, `&=`, `^=`, |= | | LR | `,` | @@ -229,6 +229,4 @@ In Linux systems: statement_sequence /* the expression. This is optional */ } ---- - --- \ No newline at end of file diff --git a/languages/C.txt b/languages/C.txt deleted file mode 100644 index 8462fafe..00000000 --- a/languages/C.txt +++ /dev/null @@ -1,65 +0,0 @@ - -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 - - -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 */ -