Getting Started with C

Loop
5 min readNov 20, 2023

--

C is a general-purpose programming language that was created by Dennis Ritchie. It is also a type of procedural programming language that follows the top-down approach. C does not support classes or objects, alternatively it organises code into procedures and/or functions that can be executed in a specific order. Here are a few advantages of C:

  1. It offers structured programming that allows breaking down problems into smaller modules that are easier to understand and modify.
  2. C is a portable language and can be executed on different machines
  3. C supports and offers a number of different built — in libraries for more efficient programming.
  4. It supports dynamic memory allocation
  5. As C is a compiler-based programming language the execution and compilation of code is comparatively faster.
  6. C enables the use of pointers.
  7. It also provides code re-usability for every function that is recursion as it allows the efficient way of code re-usability.

Applications of C include its use in Operating Systems.

  • It is also widely used in GUI (Graphical User Interface) and Embedded Systems.
  • It also commonly used for web browsers

Basic Operators in C:

Operators in C can be defined as symbols that can be used to perform specific mathematical, relational, bit-wise, conditional or logical computations of operands.

They are used extensively in C programs to perform various calculations, comparisons, and control flow operations.

Types of Operators:

  1. Arithmetic Operators:
  • “+” operator used to add two operands
  • “-” operator used to subtract two operands
  • “*” operator used to multiply two operands
  • “/” operator used to divide two operands
  • “%” operator used to return the value of remainder after division of the two given operands

2. Relational Operators:

  • “==” This operator allows us to check whether the two given operands are equal
  • “!=” This operator allows us to see whether the given operands are not equal
  • “<” This operator allows us to check if the left operand is less than the right operand
  • “>” This operator allows us to check if the left operand is greater than the right operand
  • “< =” This operator allows us to check if the left operand is less than or equal to the right operand
  • “> =” This operator allows us to check if the left operand is greater than or equal to the right operand

3. Logical Operators:

  • “&&” (Logical AND) returns true if both the operands are true
  • “||”(Logical OR) returns true if at least one of the operands is true
  • “!” (Logical NOT) returns the opposite of the operand’s truth value

4. Assignment Operators:

  • “=” assigns the value of the right operand to the left operand
  • “+=” This operator adds the value on the right-hand side to the variable on the left-hand side and then assigns the result to the variable on the left.
  • “-=” This operator subtracts the value on the right-hand side from the variable on the left-hand side and then assigns the result to the variable on the left.
  • “*=” This operator multiplies the variable on the left-hand side by the value on the right-hand side and assigns the result to the variable on the left.
  • “/=” This operator divides the variable on the left-hand side by the value on the right-hand side and assigns the result to the variable on the left.
  • “%=”· This operator calculates the modulus of the variable on the left-hand side with the value on the right-hand side and assigns the result to the variable on the left.

5. Bit-wise Operators:

  • Bit-wise AND (&): This operator firstly performs bit-wise AND operation on the bits of the given values of the operands. And if both bits are 1, only then the result bit is 1 otherwise result bit will be 0.
  • Bit-wise OR(|): This operator firstly performs bit-wise AND operation on the bits of the given values of the operands. If at least one of the bits is 1, then the result bit will be 1.
  • Bit-wise XOR(^): This operator firstly performs bit-wise AND operation on the bits of the given values of the operands. If the bits are different one of them is 0 and one of them is 1, then result bit is 1 but if they are the same, then result bit is 0.
  • Bit-wise NOT(~): This operator firstly performs bit-wise AND operation on the bits of the given values of the operands. It is simply a negation operation where all 1s become 0s, and all 0s become 1s.
  • Left Shift(<<):Shifts the bits of a number to the left by a specified number of positions. This is equivalent to multiplying the number by 2 raised to the power of the shift count.
  • Right Shift(>>): Shifts the bits of a number to the right by a specified number of positions. This is equivalent to dividing the number by 2 raised to the power of the shift count.

for detailed information and examples on bit-wise operators in C please refer:

6. Increment/Decrement Operators:

  • “++” (increment) This operator is commonly used to increase/increments the value of specific operand by 1.
  • “- -”(decrement) This operator does the exact opposite that is it decreases/decrements the value of specific operand by 1.

7. Ternary or Conditional Operators:

  • “?:” The ternary operator takes three operands and is used to return one of two values depending on the evaluation of a boolean condition

--

--

Loop
Loop

Written by Loop

Competitive coding club at Cummins College of Engineering, Pune

No responses yet