Headlines
Loading...

 

Operators and Expressions in C

Arithmetic Operators

Arithmetic operators are used to perform mathematical operations. They include:

  • + (Addition)
  • - (Subtraction)
  • * (Multiplication)
  • / (Division)
  • % (Modulus)

Example:

int a = 10, b = 5;
int sum = a + b;        // sum is 15
int difference = a - b; // difference is 5
int product = a * b;    // product is 50
int quotient = a / b;   // quotient is 2
int remainder = a % b;  // remainder is 0
  

Relational Operators

Relational operators are used to compare two values. They include:

  • > (Greater than)
  • < (Less than)
  • >= (Greater than or equal to)
  • <= (Less than or equal to)
  • == (Equal to)
  • != (Not equal to)

Example:

int a = 10, b = 5;
bool isGreater = (a > b);  // isGreater is true
bool isEqual = (a == b);   // isEqual is false
  

Logical Operators

Logical operators are used to combine multiple conditions. They include:

  • && (Logical AND)
  • || (Logical OR)
  • ! (Logical NOT)

Example:

int a = 10, b = 5, c = 15;
bool result = (a > b) && (c > a); // result is true
bool resultOr = (a > b) || (a > c); // resultOr is true
bool notResult = !(a > b); // notResult is false
  

Bitwise Operators

Bitwise operators are used to perform operations on individual bits of a number. They include:

  • & (Bitwise AND)
  • | (Bitwise OR)
  • ^ (Bitwise XOR)
  • << (Left shift)
  • >> (Right shift)

Example:

int a = 5, b = 3; // a = 0101, b = 0011
int andResult = a & b;  // andResult is 1 (0001)
int orResult = a | b;   // orResult is 7 (0111)
int xorResult = a ^ b;  // xorResult is 6 (0110)
int leftShift = a << 1; // leftShift is 10 (1010)
int rightShift = a >> 1; // rightShift is 2 (0010)
  

Assignment Operators

Assignment operators are used to assign values to variables. They include:

  • = (Assignment)
  • += (Add and assign)
  • -= (Subtract and assign)
  • *= (Multiply and assign)
  • /= (Divide and assign)

Example:

int a = 10;
a += 5;  // a is now 15
a -= 3;  // a is now 12
a *= 2;  // a is now 24
a /= 4;  // a is now 6
  

Hello, This is Multi Dude [MD] I am a website designer and can create very beautiful, responsive and friendly websites for you. I will do my best and will serve you whenever you need .Don`t Worry about Difference of Time zone! I have gone through your requirement and highly interested. I will deliver the project with 100% satisfaction and under deadline. I will do this job as per your expectation. Please come over chat, let's discuss more on the project. I will start work immediately and provide you daily updates.Please share reference for your website or any documents related to the project if you have, Website will be responsive, User friendly and SEO friendly.  Contact: killerbeast003@gmail. com

0 Comments: