Posts

Relational Operators

  ๐Ÿ’ป Relational Operators in C (Easy + Clear Explanation) In C (developed by Dennis Ritchie ), relational operators are used to compare two values ๐Ÿ” ๐Ÿ‘‰ The result is always: 1 → True ✅ 0 → False ❌ ๐Ÿ”น What are Relational Operators? ๐Ÿค” They are used to check conditions like: Equal or not Greater or smaller ๐Ÿ‘‰ Mostly used in if conditions and loops ๐Ÿ”น Types of Relational Operators Operator Meaning Example Result == Equal to a == b True if equal != Not equal a != b True if not equal > Greater than a > b True if a is bigger < Less than a < b True if smaller >= Greater or equal a >= b True if ≥ <= Less or equal a <= b True if ≤ ๐Ÿ”น Examples of Each Operator #include <stdio.h> int main () { int a = 10 , b = 5 ; printf ( "%d\n" , a == b ); // 0 printf ( "%d\n" , a != b ); // 1 printf ( "%d\n" , a > b ); // 1 printf ( "%d\n" , a < b ); // 0 printf (...

Arithmetic Operators in C

  ๐Ÿ’ป Arithmetic Operators in C (Easy + Clear Explanation) In C (developed by Dennis Ritchie ), arithmetic operators are used to perform mathematical operations ➕➖✖️➗ ๐Ÿ”น What are Arithmetic Operators? ๐Ÿค” These operators are used to: ๐Ÿ‘‰ Add, subtract, multiply, divide numbers ๐Ÿ”น Types of Arithmetic Operators Operator Name Example Meaning + Addition a + b Add two values - Subtraction a - b Subtract * Multiplication a * b Multiply / Division a / b Divide % Modulus a % b Remainder ๐Ÿ”น Examples of Each Operator ๐Ÿ”ธ 1. Addition (+) int a = 10 , b = 5 ; printf ( "%d" , a + b ); ๐Ÿ‘‰ Output: 15 ๐Ÿ”ธ 2. Subtraction (-) printf ( "%d" , a - b ); ๐Ÿ‘‰ Output: 5 ๐Ÿ”ธ 3. Multiplication (*) printf ( "%d" , a * b ); ๐Ÿ‘‰ Output: 50 ๐Ÿ”ธ 4. Division (/) printf ( "%d" , a / b ); ๐Ÿ‘‰ Output: 2 ๐Ÿ‘‰ ⚠️ Important: If both are integers → result is integer Decimal part is removed ๐Ÿ”ธ 5. Modulus (%) printf ( "%d" , a % b ); ๐Ÿ‘‰...

Comments in C

  ๐Ÿ’ป Comments in C (Easy Explanation) In C (developed by Dennis Ritchie ), comments are used to write notes or explanations inside the program. ๐Ÿ‘‰ These are ignored by the compiler (they do not affect the output) ๐Ÿ”น What are Comments? ๐Ÿค” Comments are used to: Explain code ๐Ÿ“– Make program easy to understand Help other programmers ๐Ÿ”น Types of Comments in C ๐Ÿ”ธ 1. Single-Line Comment ( // ) ✏️ ๐Ÿ‘‰ Used for writing comment in one line ✅ Example: #include <stdio.h> int main () { // This is a single-line comment printf ( "Hello" ); return 0 ; } ๐Ÿ”ธ 2. Multi-Line Comment ( /* */ ) ๐Ÿงพ ๐Ÿ‘‰ Used for writing comments in multiple lines ✅ Example: #include <stdio.h> int main () { /* This is a multi-line comment */ printf ( "Hello" ); return 0 ; } ๐Ÿ”น Important Rules ⚠️ ✔ Comments are not executed ✔ Used only for understanding code ✔ Can be written anywhere in program ❗ Invalid Example /* This is wrong //...

Input & Output Functions in C

  ๐Ÿ’ป Input & Output Functions in C ( printf() and scanf() ) In C (developed by Dennis Ritchie ), input and output functions are used to: Take data from user ๐Ÿ“ฅ Display data on screen ๐Ÿ“ค ๐Ÿ”น 1. printf() Function (Output) ๐Ÿ“ค ๐Ÿ‘‰ printf() is used to display output on the screen ✅ Syntax printf ( "format specifier" , variables ); ✅ Example 1 #include <stdio.h> int main () { printf ( "Hello, World!" ); return 0 ; } ๐Ÿ‘‰ Output: Hello, World! ✅ Example 2 (with variables) int a = 10 ; printf ( "Value of a = %d" , a ); ๐Ÿ‘‰ Output: Value of a = 10 ๐Ÿ”น Multiple Values Example int a = 10 ; float b = 5.5 ; printf ( "a = %d, b = %f" , a , b ); ๐Ÿ‘‰ Output: a = 10, b = 5.500000 ๐Ÿ”น 2. scanf() Function (Input) ๐Ÿ“ฅ ๐Ÿ‘‰ scanf() is used to take input from user ✅ Syntax scanf ( "format specifier" , & variable ); ๐Ÿ‘‰ & = address of variable ✅ Example 1 #include <stdio.h> int main ...

Format Specifiers in C

  ๐Ÿ’ป Format Specifiers in C (With Easy Examples) In C (developed by Dennis Ritchie ), format specifiers are used in functions like printf() and scanf() to tell the compiler: ๐Ÿ‘‰ what type of data you are printing or reading ๐Ÿ”น What is a Format Specifier? ๐Ÿค” A format specifier starts with % and defines the data type of a variable ๐Ÿ‘‰ Example: printf ( "%d" , a ); Here %d means → print an integer ๐Ÿ”น Common Format Specifiers ๐Ÿ“Š Data Type Specifier Meaning int %d Integer float %f Decimal number double %lf Double precision char %c Single character string %s Text/string unsigned int %u Positive integer long int %ld Long integer long long int %lld Very large integer ๐Ÿ”น Examples of Each Specifier ๐Ÿ”ธ 1. Integer (%d) #include <stdio.h> int main () { int a = 10 ; printf ( "%d" , a ); return 0 ; } ๐Ÿ‘‰ Output: 10 ๐Ÿ”ธ 2. Float (%f) float b = 5.5 ; printf ( "%f" , b ); ๐Ÿ‘‰ Output: 5.500000 ๐Ÿ”ธ 3. Double (%lf) double pi =...

Type Modifiers in C

  ๐Ÿ’ป Type Modifiers in C (short, long, signed, unsigned) In C (developed by Dennis Ritchie ), type modifiers are used to modify the size or range of basic data types like int and char . ๐Ÿ‘‰ They help control: Memory usage ๐Ÿ“ฆ Range of values ๐Ÿ”ข ๐Ÿ”น What are Type Modifiers? ๐Ÿค” Type modifiers are keywords that change how a data type behaves ๐Ÿ‘‰ Main modifiers: short long signed unsigned ๐Ÿ”น 1. short ๐Ÿงฉ Used to reduce memory size of integer ✅ Example: short int a = 100 ; ๐Ÿ“Œ Size: 2 bytes ๐Ÿ“Œ Range: -32,768 to 32,767 ๐Ÿ‘‰ Same as: short a ; ๐Ÿ”น 2. long ๐Ÿ“ Used to increase size of integer or double ✅ Example: long int b = 100000 ; ๐Ÿ“Œ Size: 4 or 8 bytes (system dependent) ๐Ÿ‘‰ For large decimal numbers: long double pi = 3.141592653589793 ; ๐Ÿ“Œ Very high precision ๐ŸŽฏ ๐Ÿ”น 3. signed ➕➖ Used to store both positive and negative values ๐Ÿ‘‰ By default, int is signed ✅ Example: signed int x = - 50 ; ๐Ÿ“Œ Range: - to + ๐Ÿ”น 4. unsigned ➕ ...