From 8e3299d2dffc43a05abb032f192f9a5679e050e0 Mon Sep 17 00:00:00 2001 From: Ajay T Shaju Date: Mon, 18 Sep 2023 22:30:58 +0530 Subject: [PATCH] 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 67ab08c..5290f99 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 8f75176..8462faf 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