From 245fb449b920c2a791581cfeadc61fd9413a9191 Mon Sep 17 00:00:00 2001 From: srdusr Date: Wed, 26 Apr 2023 23:56:02 +0200 Subject: Add notes on C --- languages/c.md | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/languages/c.md b/languages/c.md index e69de29..513ec0c 100644 --- a/languages/c.md +++ b/languages/c.md @@ -0,0 +1,114 @@ + ### C Programming + +##### Basic Syntax +- Comments + // This is a single-line comment + + /* This is a + multi-line comment */ +- Variables + + // Declaration and initialization + int x = 10; + + // Declaration without initialization + float y; +- Data Types +|Data Type| Description| +| --- | --- | --- | + |int| Integer + |float| Floating point number + |double| Double precision floating point number + |char| Character + |bool| Boolean + |Operators| + |Operator| Description + |=| Assignment| + |+| Addition| + |-| Subtraction| + |*| Multiplication| + |/| Division| + |%| Modulus| (remainder after division) + |==| Equality| + |!=| Inequality| + |<| Less than| + |>| Greater than| + |<=| Less than or equal to| + |>=| Greater than or equal to| + |&&| Logical AND| + |` + |!| Logical NOT| + Control Structures + Conditional Statements + c + Copy code + if (condition) { + // code block to execute if condition is true + } else if (anotherCondition) { + // code block to execute if anotherCondition is true + } else { + // code block to execute if neither condition is true + } + Loops + For Loop + c + Copy code + for (initialization; condition; update) { + // code block to execute repeatedly while condition is true + } + While Loop + c + Copy code + while (condition) { + // code block to execute repeatedly while condition is true + } + Do-While Loop + c + Copy code + do { + // code block to execute at least once + } while (condition); + Switch Statements + c + Copy code + switch (expression) { + case value1: + // code block to execute if expression equals value1 + break; + case value2: + // code block to execute if expression equals value2 + break; + default: + // code block to execute if expression does not equal any specified value + break; + } + Functions + c + Copy code + // Function prototype + returnType functionName(argumentType argumentName); + + // Function definition + returnType functionName(argumentType argumentName) { + // code block to execute + return returnValue; + } + Arrays + c + Copy code + // Declaration and initialization + int arrayName[size] = {value1, value2, value3}; + + // Accessing elements + int element = arrayName[index]; + Pointers + c + Copy code + // Declaration and initialization + int *pointerName = &variableName; + + // Accessing value through pointer + int value = *pointerName;` + + + -- cgit v1.2.3