Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Operators and Expressions in C Language

Operators and Expressions in C Language

To master the C programming language, you need to get a grip on operators and expressions. C uses symbols called operators to perform operations on variables and constants. These operators come in handy when you want to manipulate data and create expressions. An expression is a mix of operators, constants, and variables that boils down to a single value.
Key Operators in C Language:

Arithmetic Operators:
The C language uses arithmetic operators to do basic math. These include adding (+) taking away (-), times (*), divide (/), and finding remainders (%).
Relational Operators:
When you want to compare two things in C, you use relational operators. They give you a yes or no answer. Are these two identical?" (==), "Is this different from that?" (!=), "Is this bigger than that?" (>), and "Is this smaller than that?" (<).
Logical Operators:
Logical operators in C help you link different conditions. They figure out how these conditions fit together. You can use "and" (&&) to check if two things are true, "or" (||) to see if at least one thing is true, and "not" (!) to flip a condition.
Bitwise Operators:
Bitwise operators work on the bits of whole number operands. The operations that fall under this category are bitwise AND (&), bitwise OR (|), bitwise XOR (^), bitwise NOT (~), left shift (<<), and right shift (>>).
Assignment Operators:
Assignment operators give values to variables. The basic assignment operator is (=). Compound assignment operators like (+=, -=, *= /=) do the operation and give the result in one step.
Other Operators

himaja

July 30, 2024
Tweet

More Decks by himaja

Other Decks in Programming

Transcript

  1. THE C PROGRAMMING LANGUAGE, YOU NEED TO GET A GRIP

    ON OPERATORS AND EXPRESSIONS. C USES SYMBOLS CALLED OPERATORS TO PERFORM OPERATIONS ON VARIABLES AND CONSTANTS. THESE OPERATORS COME IN HANDY WHEN YOU WANT TO MANIPULATE DATA AND CREATE EXPRESSIONS. AN EXPRESSION IS A MIX OF OPERATORS, CONSTANTS, AND VARIABLES THAT BOILS DOWN TO A SINGLE VALUE. INTRODUCTION https://nareshit.com/courses/c-language-online-training
  2. 01 02 03 04 05 06 07 ARITHMETIC OPERATORS RELATIONAL

    OPERATORS LOGICAL OPERATORS BITWISE OPERATORS ASSIGNMENT OPERATORS OTHER OPERATORS OPERATOR PRECEDENCE AND ASSOCIATIVITY IN C KEY OPERATORS IN C LANGUAGE https://nareshit.com/courses/c-language-online-training
  3. ARITHMETIC OPERATORS: THE C LANGUAGE USES ARITHMETIC OPERATORS TO DO

    BASIC MATH. THESE INCLUDE ADDING (+) TAKING AWAY (-), TIMES (*), DIVIDE (/), AND FINDING REMAINDERS (%). RELATIONAL OPERATORS: WHEN YOU WANT TO COMPARE TWO THINGS IN C, YOU USE RELATIONAL OPERATORS. THEY GIVE YOU A YES OR NO ANSWER. ARE THESE TWO IDENTICAL?" (==), "IS THIS DIFFERENT FROM THAT?" (!=), "IS THIS BIGGER THAN THAT?" (>), AND "IS THIS SMALLER THAN THAT?" (<). https://nareshit.com/courses/c-language-online-training
  4. LOGICAL OPERATORS: LOGICAL OPERATORS IN C HELP YOU LINK DIFFERENT

    CONDITIONS. THEY FIGURE OUT HOW THESE CONDITIONS FIT TOGETHER. YOU CAN USE "AND" (&&) TO CHECK IF TWO THINGS ARE TRUE, "OR" (||) TO SEE IF AT LEAST ONE THING IS TRUE, AND "NOT" (!) TO FLIP A CONDITION. BITWISE OPERATORS: BITWISE OPERATORS WORK ON THE BITS OF WHOLE NUMBER OPERANDS. THE OPERATIONS THAT FALL UNDER THIS CATEGORY ARE BITWISE AND (&), BITWISE OR (|), BITWISE XOR (^), BITWISE NOT (~), LEFT SHIFT (<<), AND RIGHT SHIFT (>>). https://nareshit.com/courses/c-language-online-training
  5. ASSIGNMENT OPERATORS: ASSIGNMENT OPERATORS GIVE VALUES TO VARIABLES. THE BASIC

    ASSIGNMENT OPERATOR IS (=). COMPOUND ASSIGNMENT OPERATORS LIKE (+=, -=, *= /=) DO THE OPERATION AND GIVE THE RESULT IN ONE STEP. https://nareshit.com/courses/c-language-online-training
  6. SIZEOF OPERATOR: FIGURES OUT THE SIZE OF ITS OPERAND. COMMA

    OPERATOR ( , ): THIS CHECKS THE FIRST PART, THROWS IT AWAY, AND GIVES BACK THE RESULT OF THE SECOND PART. CONDITIONAL OPERATOR ( ? : ): THIS IS A THREE-PART TOOL TO MAKE DECISIONS IN CODE. DOT (.) AND ARROW (->) OPERATORS: THESE HELP YOU GET TO PARTS OF CLASSES, STRUCTURES, AND UNIONS. OTHER OPERATORS: BESIDES THESE, C HAS SOME OTHER OPERATORS FOR SPECIFIC JOBS: https://nareshit.com/courses/c-language-online-training
  7. CAST OPERATOR: THIS CHANGES ONE TYPE OF DATA TO ANOTHER

    USING (TYPE) EXPRESSION. ADDRESSOF (&) AND DEREFERENCE (*) OPERATORS: THESE WORK WITH POINTERS TO FIND WHERE A VARIABLE LIVES AND TO SEE WHAT'S INSIDE A POINTER, IN THAT ORDER. https://nareshit.com/courses/c-language-online-training
  8. UNARY, BINARY AND TERNARY OPERATORS IN C: C GROUPS OPERATORS

    INTO THREE CATEGORIES BASED ON HOW MANY OPERANDS THEY USE: UNARY OPERATORS: THESE WORK ON ONE OPERAND. BINARY OPERATORS: THESE WORK ON TWO OPERANDS. TERNARY OPERATOR: C HAS ONE TERNARY OPERATOR, WHICH IS THE CONDITIONAL OPERATOR ( ?). https://nareshit.com/courses/c-language-online-training
  9. OPERATOR PRECEDENCE AND ASSOCIATIVITY IN C: WHEN C EXPRESSIONS HAVE

    MULTIPLE OPERATORS, EACH OPERATOR HAS ITS OWN PRECEDENCE AND ASSOCIATIVITY: PRECEDENCE: DECIDES THE SEQUENCE OF EVALUATION IN EXPRESSIONS. THE SYSTEM EVALUATES OPERATORS WITH HIGHER PRECEDENCE FIRST. ASSOCIATIVITY: POINTS OUT THE DIRECTION FOR EVALUATING OPERATORS WITH THE SAME PRECEDENCE LEVEL (LEFT TO RIGHT OR RIGHT TO LEFT). TO WRITE BUG-FREE AND SOUND CODE IN C, YOU NEED TO UNDERSTAND OPERATOR PRECEDENCE AND ASSOCIATIVITY. https://nareshit.com/courses/c-language-online-training
  10. CONCLUSION: OPERATORS AND EXPRESSIONS ARE AT THE HEART OF C

    PROGRAMMING. THEY LET DEVELOPERS HANDLE DATA WELL AND WRITE SHORT CODE. IF YOU WANT TO GET GOOD AT C PROGRAMMING, YOU MUST MASTER THESE IDEAS. https://nareshit.com/courses/c-language-online-training