[Adult Learning Log] C Language – Week 4 Review

○ Key Learning Points from Week 4

Learned about the concepts and types of arithmetic operators, relational operators, logical operators, and conditional operators.
Studied increment/decrement operators, compound assignment operators, comma …


This content originally appeared on DEV Community and was authored by San Kang

○ Key Learning Points from Week 4

  • Learned about the concepts and types of arithmetic operators, relational operators, logical operators, and conditional operators.
  • Studied increment/decrement operators, compound assignment operators, comma operators, and bitwise operators.
  • Understood type conversion and operator precedence.

○ Expression (Formula)

An expression is a combination of constants, variables, and operators, divided into operators and operands.

○ Arithmetic Operators (Basic Arithmetic): +, -, *, /, %

  • Division between int types results in an int (decimal parts are truncated).
  • Division between float types yields float results.
  • % (Modulus Operator) returns the remainder of dividing the first operand by the second operand.

○ Increment/Decrement Operators

  • ++variable, variable++, --variable, variable--
  • The position of the increment/decrement operator affects when the value is updated.

○ Assignment Operators

Operators that assign the result of an expression to a variable.

  • The left side must be a variable, while the right side can be any expression.
100 = x + y; // Error
x = x + 1;   // Valid (Different from the math "="!)
y = x = 3;   // Valid (Assigns 3 to x, then assigns x's value to y)

○ Compound Assignment Operators

Combines = with arithmetic operators, e.g., x += y.

  • Allows shorthand for reassigning the result to the same variable.

○ Relational Operators: ==, !=, >, <, >=, <=

  • Compares two operands; returns TRUE (1) or FALSE (0).
  • Cannot chain comparisons as in math: 2 < x < 5 → This is invalid.
    • Correct way: (2 < x) && (x < 5)

○ Logical Operators: &&, ||, !

  • Used to combine multiple conditions.
  • Returns 1 (TRUE) if the condition is met, 0 (FALSE) otherwise.
  • In C, non-zero values are considered TRUE and 0 is FALSE.
  • Note: In this class, negative numbers were also treated as FALSE due to representing no electric signal.

○ Ternary Operator (Conditional Operator)

  • The only operator that takes three operands:
max_value = (x > y) ? a : b;  // Returns a if TRUE, b if FALSE

○ Comma Operator

  • Evaluates two expressions separated by , sequentially.

○ Bitwise Operators: &, |, ^, <<, >>, ~

  • << shifts bits to the left, effectively doubling the value per shift (due to binary nature).

○ Type Conversion & Operator Precedence

Type Conversion (Casting)

  • Changes the data type during program execution.
  • Be cautious—improper casting can lead to data loss.
  • When mixing different data types, C automatically promotes to the larger type.

Explicit Casting

  • Developer explicitly converts the type using parentheses before the variable:
(int)1.35  // Casts 1.35 to int

Operator Precedence

  • Determines the order of operations among multiple operators.
  • Refer to the textbook’s precedence chart for details.

○ Practice

Try writing and executing C code using the operators learned this week.

Image description

Image description

Image description


This content originally appeared on DEV Community and was authored by San Kang


Print Share Comment Cite Upload Translate Updates
APA

San Kang | Sciencx (2025-07-03T04:11:54+00:00) [Adult Learning Log] C Language – Week 4 Review. Retrieved from https://www.scien.cx/2025/07/03/adult-learning-log-c-language-week-4-review/

MLA
" » [Adult Learning Log] C Language – Week 4 Review." San Kang | Sciencx - Thursday July 3, 2025, https://www.scien.cx/2025/07/03/adult-learning-log-c-language-week-4-review/
HARVARD
San Kang | Sciencx Thursday July 3, 2025 » [Adult Learning Log] C Language – Week 4 Review., viewed ,<https://www.scien.cx/2025/07/03/adult-learning-log-c-language-week-4-review/>
VANCOUVER
San Kang | Sciencx - » [Adult Learning Log] C Language – Week 4 Review. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/07/03/adult-learning-log-c-language-week-4-review/
CHICAGO
" » [Adult Learning Log] C Language – Week 4 Review." San Kang | Sciencx - Accessed . https://www.scien.cx/2025/07/03/adult-learning-log-c-language-week-4-review/
IEEE
" » [Adult Learning Log] C Language – Week 4 Review." San Kang | Sciencx [Online]. Available: https://www.scien.cx/2025/07/03/adult-learning-log-c-language-week-4-review/. [Accessed: ]
rf:citation
» [Adult Learning Log] C Language – Week 4 Review | San Kang | Sciencx | https://www.scien.cx/2025/07/03/adult-learning-log-c-language-week-4-review/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.