šŸ•·ļø Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 103 (from laksa106)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ā„¹ļø Skipped - page is already crawled

šŸ“„
INDEXABLE
āœ…
CRAWLED
2 days ago
šŸ¤–
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.1 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://www.geeksforgeeks.org/c/operators-in-c/
Last Crawled2026-04-13 00:07:51 (2 days ago)
First Indexed2025-06-14 07:56:55 (10 months ago)
HTTP Status Code200
Meta TitleOperators in C - GeeksforGeeks
Meta DescriptionYour All-in-One Learning Portal: GeeksforGeeks is a comprehensive educational platform that empowers learners across domains-spanning computer science and programming, school education, upskilling, commerce, software tools, competitive exams, and more., Your All-in-One Learning Portal. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
Meta Canonicalnull
Boilerpipe Text
Operators are the basic components of C programming. They are symbols that represent some kind of operation, such as mathematical, relational, bitwise, conditional, or logical computations, which are to be performed on values or variables. The values and variables used with operators are called operands . Output 30 Unary, Binary and Ternary Operators On the basis of the number of operands they work on, operators can be classified into three types : Unary Operators: Operators that work on single operand. Example: Increment( ++ ) , Decrement( -- ) Binary Operators: Operators that work on two operands. Example: Addition ( + ), Subtraction( - ) , Multiplication ( * ) Ternary Operators: Operators that work on three operands. Example : Conditional Operator( ? : ) Types of Operators in C C language provides a wide range of built in operators that can be classified into 6 types based on their functionality: Arithmetic Operators The arithmetic operators are used to perform arithmetic/mathematical operations on operands. There are 9 arithmetic operators in C language : Output a + b = 30 a - b = 20 a * b = 125 a / b = 5 a % b = 0 +a = 25 -a = -25 a++ = 25 a-- = 26 Relational Operators The relational operators in C are used for the comparison of the two operands. All these operators are binary operators that return true or false values as the result of comparison. Output a < b : 0 a > b : 1 a <= b: 0 a >= b: 1 a == b: 0 a != b : 1 Here, 0 means false and 1 means true. Logical Operator Logical Operators are used to combine two or more conditions/constraints or to complement the evaluation of the original condition in consideration. The result of the operation of a logical operator is a Boolean value either true or false . Symbol Operator Description Syntax && Logical AND Returns true if both the operands are true. a && b || Logical OR Returns true if both or any of the operand is true. a || b ! Logical NOT Returns true if the operand is false. !a Output a && b : 1 a || b : 1 !a: 0 Bitwise Operators The Bitwise operators are used to perform bit-level operations on the operands. The operators are first converted to bit-level and then the calculation is performed on the operands. Note: Mathematical operations such as addition, subtraction, multiplication, etc. can be performed at the bit level for faster processing. Symbol Operator Description Syntax & Bitwise AND Performs bit-by-bit AND operation and returns the result. a & b | Bitwise OR Performs bit-by-bit OR operation and returns the result. a | b ^ Bitwise XOR Performs bit-by-bit XOR operation and returns the result. a ^ b ~ Bitwise First Complement Flips all the set and unset bits on the number. ~a << Bitwise Leftshift Shifts bits to the left by a given number of positions; multiplies the number by 2 for each shift. a << b >> Bitwise Rightshift Shifts bits to the right by a given number of positions; divides the number by 2 for each shift. a >> b Output a & b: 1 a | b: 29 a ^ b: 28 ~a: -26 a >> b: 0 a << b: 800 Assignment Operators Assignment operators are used to assign value to a variable. The left side operand of the assignment operator is a variable and the right side operand of the assignment operator is a value. The value on the right side must be of the same data type as the variable on the left side otherwise the compiler will raise an error. The assignment operators can be combined with some other operators in C to provide multiple operations using single operator. These operators are called compound operators. Symbol Operator Description Syntax = Simple Assignment Assign the value of the right operand to the left operand. a = b += Plus and assign Add the right operand and left operand and assign this value to the left operand. a += b -= Minus and assign Subtract the right operand and left operand and assign this value to the left operand. a -= b *= Multiply and assign Multiply the right operand and left operand and assign this value to the left operand. a *= b /= Divide and assign Divide the left operand with the right operand and assign this value to the left operand. a /= b %= Modulus and assign Assign the remainder in the division of left operand with the right operand to the left operand. a %= b &= AND and assign Performs bitwise AND and assigns this value to the left operand. a &= b |= OR and assign Performs bitwise OR and assigns this value to the left operand. a |= b ^= XOR and assign Performs bitwise XOR and assigns this value to the left operand. a ^= b >>= Rightshift and assign Performs bitwise Rightshift and assign this value to the left operand. a >>= b <<= Leftshift and assign Performs bitwise Leftshift and assign this value to the left operand. a <<= b Output a = b: 5 a += b: 10 a -= b: 5 a *= b: 25 a /= b: 5 a %= b: 0 a &= b: 0 a |= b: 5 a ^= b: 0 a >>= b: 0 a <<= b: 0 Other Operators Apart from the above operators, there are some other operators available in C used to perform some specific tasks. Some of them are discussed here:Ā  sizeof Operator sizeof is much used in the C programming language. It is a compile-time unary operator which can be used to compute the size of its operand. The result of sizeof is of the unsigned integral type which is usually denoted by size_t. Basically, the sizeof the operator is used to compute the size of the variable or datatype. Syntax sizeof ( operand ) Comma Operator ( , ) The comma operator (represented by the token) is a binary operator that evaluates its first operand and discards the result, it then evaluates the second operand and returns this value (and type). The comma operator has the lowest precedence of any C operator. It can act as both operator and separator.Ā  Syntax operand1 , operand2 Conditional Operator ( ? : ) The conditional operator is the only ternary operator in C. It is a conditional operator that we can use in place of if..else statements. Syntax expression1 ? Expression2 : Expression3 ; Here, Expression1 is the condition to be evaluated. If the condition( Expression1 ) is True then we will execute and return the result of Expression2 otherwise if the condition( Expression1 ) is false then we will execute and return the result of Expression3 . dot (.) and arrow (->) Operators Member operators are used to reference individual members of classes, structures, and unions. The dot operator is applied to the actual object.Ā  The arrow operator is used with a pointer to an object. Syntax structure_variable . member ; structure_pointer -> member ; Cast Operators Casting operators convert one data type to another. For example, int(2.2000) would return 2. A cast is a special operator that forces one data type to be converted into another.Ā  Syntax ( new_type ) operand ; addressof (&) and Dereference (*) Operators Addressof operator & returns the address of a variable and the dereference operator * is used to access the value stored at that address. Example of Other C Operators Output sizeof(num) = 4 bytes &num = 0x7ffdb58c037c *add_of_num = 10 (10 < 5) ? 10 : 20 = 20 (float)num = 10.000000 It is strongly recommended to learn Operator Precedence and Associativity after reading about operators.
Markdown
[![geeksforgeeks](https://media.geeksforgeeks.org/gfg-gg-logo.svg)](https://www.geeksforgeeks.org/) ![search icon](https://media.geeksforgeeks.org/auth-dashboard-uploads/Property=Light---Default.svg) - Sign In - [Courses]() - [Tutorials]() - [Interview Prep]() - [C Tutorial](https://www.geeksforgeeks.org/c/c-programming-language/) - [Interview Questions](https://www.geeksforgeeks.org/c/c-coding-interview-questions/) - [Examples](https://www.geeksforgeeks.org/c/c-programming-examples/) - [Quizzes](https://www.geeksforgeeks.org/c/c-multiple-choice-questions/) - [Projects](https://www.geeksforgeeks.org/c/c-projects/) - [Cheatsheet](https://www.geeksforgeeks.org/c/c-cheatsheet/) - [File Handling](https://www.geeksforgeeks.org/c/basics-file-handling-c/) - [Multithreading](https://www.geeksforgeeks.org/c/multithreading-in-c/) - [Memory Layout](https://www.geeksforgeeks.org/c/memory-layout-of-c-program/) - [DSA in C](https://www.geeksforgeeks.org/c/learn-dsa-in-c/) # Operators in C Last Updated : 3 Apr, 2026 Operators are the basic components of C programming. They are symbols that represent some kind of operation, such as mathematical, relational, bitwise, conditional, or logical computations, which are to be performed on values or variables. The values and variables used with operators are called ****operands****. C `` ``` #include <stdio.h> ``` ``` int main() { ``` ``` ``` ``` // Expression for getting sum ``` ``` int sum = 10 + 20; ``` ``` ``` ``` printf("%d", sum); ``` ``` return 0; ``` ``` } ``` **Output** ``` 30 ``` ## Unary, Binary and Ternary Operators On the basis of the number of operands they work on, operators can be classified into three types : 1. ****Unary Operators:**** Operators that work on single operand. Example: Increment( ++ ) , Decrement( -- ) 2. ****Binary Operators:**** Operators that work on two operands. Example: Addition ( + ), Subtraction( - ) , Multiplication ( \* ) 3. ****Ternary Operators:**** Operators that work on three operands. Example****:**** Conditional Operator( ? : ) ## Types of Operators in C C language provides a wide range of built in operators that can be classified into 6 types based on their functionality: ## ****Arithmetic Operators**** The [arithmetic operators](https://www.geeksforgeeks.org/c/arithmetic-operators-in-c/) are used to perform arithmetic/mathematical operations on operands. There are ****9 arithmetic**** operators in C language****:**** C `` ``` #include <stdio.h> ``` ``` ​ ``` ``` int main() { ``` ``` ​ ``` ``` int a = 25, b = 5; ``` ``` ​ ``` ``` // using operators and printing results ``` ``` printf("a + b = %d\n", a + b); ``` ``` printf("a - b = %d\n", a - b); ``` ``` printf("a * b = %d\n", a * b); ``` ``` printf("a / b = %d\n", a / b); ``` ``` printf("a %% b = %d\n", a % b); ``` ``` printf("+a = %d\n", +a); ``` ``` printf("-a = %d\n", -a); ``` ``` printf("a++ = %d\n", a++); ``` ``` printf("a-- = %d\n", a--); ``` ``` ​ ``` ``` return 0; ``` ``` } ``` **Output** ``` a + b = 30 a - b = 20 a * b = 125 a / b = 5 a % b = 0 +a = 25 -a = -25 a++ = 25 a-- = 26 ``` ## ****Relational Operators**** The [relational operators](https://www.geeksforgeeks.org/c/relational-operators-in-c/) in C are used for the comparison of the two operands. All these operators are binary operators that return true or false values as the result of comparison. C `` ``` #include <stdio.h> ``` ``` ​ ``` ``` int main() { ``` ``` int a = 25, b = 5; ``` ``` ​ ``` ``` // using operators and printing results ``` ``` printf("a < b : %d\n", a < b); ``` ``` printf("a > b : %d\n", a > b); ``` ``` printf("a <= b: %d\n", a <= b); ``` ``` printf("a >= b: %d\n", a >= b); ``` ``` printf("a == b: %d\n", a == b); ``` ``` printf("a != b : %d\n", a != b); ``` ``` ​ ``` ``` return 0; ``` ``` } ``` **Output** ``` a < b : 0 a > b : 1 a <= b: 0 a >= b: 1 a == b: 0 a != b : 1 ``` Here, 0 means false and 1 means true. ## ****Logical Operator**** [Logical Operators](https://www.geeksforgeeks.org/c/logical-operators-in-c/) are used to combine two or more conditions/constraints or to complement the evaluation of the original condition in consideration. The result of the operation of a logical operator is a Boolean value either ****true**** or ****false****. | Symbol | ****Operator**** | Description | Syntax | |---|---|---|---| | ****&&**** | ****Logical AND**** | Returns true if both the operands are true. | ****a && b**** | | ****\|\|**** | ****Logical OR**** | Returns true if both or any of the operand is true. | ****a \|\| b**** | | ****\!**** | ****Logical NOT**** | Returns true if the operand is false. | ****!a**** | C `` ``` #include <stdio.h> ``` ``` ​ ``` ``` int main() { ``` ``` int a = 25, b = 5; ``` ``` ​ ``` ``` // using operators and printing results ``` ``` printf("a && b : %d\n", a && b); ``` ``` printf("a || b : %d\n", a || b); ``` ``` printf("!a: %d\n", !a); ``` ``` ​ ``` ``` return 0; ``` ``` } ``` **Output** ``` a && b : 1 a || b : 1 !a: 0 ``` ## ****Bitwise Operators**** The [Bitwise operators](https://www.geeksforgeeks.org/c/bitwise-operators-in-c-cpp/) are used to perform bit-level operations on the operands. The operators are first converted to bit-level and then the calculation is performed on the operands. ****Note:**** Mathematical operations such as addition, subtraction, multiplication, etc. can be performed at the bit level for faster processing. | Symbol | ****Operator**** | Description | Syntax | |---|---|---|---| | ****&**** | ****Bitwise AND**** | Performs bit-by-bit AND operation and returns the result. | ****a & b**** | | ****\|**** | ****Bitwise OR**** | Performs bit-by-bit OR operation and returns the result. | ****a \| b**** | | ****^**** | ****Bitwise XOR**** | Performs bit-by-bit XOR operation and returns the result. | ****a ^ b**** | | ****~**** | ****Bitwise First Complement**** | Flips all the set and unset bits on the number. | ****~a**** | | ****\<\<**** | ****Bitwise Leftshift**** | Shifts bits to the left by a given number of positions; multiplies the number by 2 for each shift. | ****a \<\< b**** | | ****\>\>**** | ****Bitwise Rightshift**** | Shifts bits to the right by a given number of positions; divides the number by 2 for each shift. | ****a \>\> b**** | C `` ``` #include <stdio.h> ``` ``` ​ ``` ``` int main() { ``` ``` int a = 25, b = 5; ``` ``` ​ ``` ``` // using operators and printing results ``` ``` printf("a & b: %d\n", a & b); ``` ``` printf("a | b: %d\n", a | b); ``` ``` printf("a ^ b: %d\n", a ^ b); ``` ``` printf("~a: %d\n", ~a); ``` ``` printf("a >> b: %d\n", a >> b); ``` ``` printf("a << b: %d\n", a << b); ``` ``` ​ ``` ``` return 0; ``` ``` } ``` **Output** ``` a & b: 1 a | b: 29 a ^ b: 28 ~a: -26 a >> b: 0 a << b: 800 ``` ## ****Assignment Operators**** [Assignment operators](https://www.geeksforgeeks.org/c/assignment-operators-in-c-c/) are used to assign value to a variable. The left side operand of the assignment operator is a variable and the right side operand of the assignment operator is a value. The value on the right side must be of the same data type as the variable on the left side otherwise the compiler will raise an error. The assignment operators can be combined with some other operators in C to provide multiple operations using single operator. These operators are called compound operators. | Symbol | ****Operator**** | Description | Syntax | |---|---|---|---| | ****\=**** | ****Simple Assignment**** | Assign the value of the right operand to the left operand. | ****a = b**** | | ****\+=**** | ****Plus and assign**** | Add the right operand and left operand and assign this value to the left operand. | ****a += b**** | | ****\-=**** | ****Minus and assign**** | Subtract the right operand and left operand and assign this value to the left operand. | ****a -= b**** | | ****\*=**** | ****Multiply and assign**** | Multiply the right operand and left operand and assign this value to the left operand. | ****a \*= b**** | | ****/=**** | ****Divide and assign**** | Divide the left operand with the right operand and assign this value to the left operand. | ****a /= b**** | | ****%=**** | ****Modulus and assign**** | Assign the remainder in the division of left operand with the right operand to the left operand. | ****a %= b**** | | ****&=**** | ****AND and assign**** | Performs bitwise AND and assigns this value to the left operand. | ****a &= b**** | | ****\|=**** | ****OR and assign**** | Performs bitwise OR and assigns this value to the left operand. | ****a \|= b**** | | ****^=**** | ****XOR and assign**** | Performs bitwise XOR and assigns this value to the left operand. | ****a ^= b**** | | ****\>\>=**** | ****Rightshift and assign**** | Performs bitwise Rightshift and assign this value to the left operand. | ****a \>\>= b**** | | ****\<\<=**** | ****Leftshift and assign**** | Performs bitwise Leftshift and assign this value to the left operand. | ****a \<\<= b**** | C `` ``` #include <stdio.h> ``` ``` ​ ``` ``` int main() { ``` ``` int a = 25, b = 5; ``` ``` ​ ``` ``` // using operators and printing results ``` ``` printf("a = b: %d\n", a = b); ``` ``` printf("a += b: %d\n", a += b); ``` ``` printf("a -= b: %d\n", a -= b); ``` ``` printf("a *= b: %d\n", a *= b); ``` ``` printf("a /= b: %d\n", a /= b); ``` ``` printf("a %%= b: %d\n", a %= b); ``` ``` printf("a &= b: %d\n", a &= b); ``` ``` printf("a |= b: %d\n", a |= b); ``` ``` printf("a ^= b: %d\n", a ^= b); ``` ``` printf("a >>= b: %d\n", a >>= b); ``` ``` printf("a <<= b: %d\n", a <<= b); ``` ``` ​ ``` ``` return 0; ``` ``` } ``` **Output** ``` a = b: 5 a += b: 10 a -= b: 5 a *= b: 25 a /= b: 5 a %= b: 0 a &= b: 0 a |= b: 5 a ^= b: 0 a >>= b: 0 a <<= b: 0 ``` ## ****Other Operators**** Apart from the above operators, there are some other operators available in C used to perform some specific tasks. Some of them are discussed here: ### ****sizeof Operator**** - [sizeof](https://www.geeksforgeeks.org/c/sizeof-operator-c/) is much used in the C programming language. - It is a compile-time unary operator which can be used to compute the size of its operand. - The result of sizeof is of the unsigned integral type which is usually denoted by size\_t. - Basically, the sizeof the operator is used to compute the size of the variable or datatype. ****Syntax**** C `` ### Comma Operator ( , ) The [comma operator](https://www.geeksforgeeks.org/c/comma-in-c/) (represented by the token) is a binary operator that evaluates its first operand and discards the result, it then evaluates the second operand and returns this value (and type). The comma operator has the lowest precedence of any C operator. It can act as both operator and separator. ****Syntax**** C `` ### Conditional Operator ( ? : ) The [****conditional operator****](https://www.geeksforgeeks.org/c/conditional-or-ternary-operator-in-c/) is the only ternary operator in C. It is a conditional operator that we can use in place of if..else statements. ****Syntax**** C `` Here, ****Expression1**** is the condition to be evaluated. If the condition(****Expression1****) is *****True*****then we will execute and return the result of ****Expression2**** otherwise if the condition(****Expression1****) is *****false*****then we will execute and return the result of ****Expression3****. ### ****dot (.) and arrow (-\>) Operators**** Member operators are used to reference individual members of classes, structures, and unions. - The [****dot operator****](https://www.geeksforgeeks.org/c/dot-operator-in-c/) is applied to the actual object. - The [****arrow operator****](https://www.geeksforgeeks.org/c/arrow-operator-in-c-c-with-examples/) is used with a pointer to an object. ****Syntax**** C `` ### ****Cast Operators**** [****Casting operators****](https://www.geeksforgeeks.org/cpp/casting-operators-in-cpp/) convert one data type to another. For example, int(2.2000) would return 2. - A cast is a special operator that forces one data type to be converted into another. ****Syntax**** C `` ### ****addressof (&) and Dereference (\*) Operators**** [Addressof operator &](https://www.geeksforgeeks.org/cpp/address-operator-in-c/) returns the address of a variable and the [dereference operator \*](https://www.geeksforgeeks.org/cpp/dereference-pointer-in-c/) is used to access the value stored at that address. ### Example of Other C Operators C `` ``` // C Program to demonstrate the use of Misc operators ``` ``` #include <stdio.h> ``` ``` ​ ``` ``` int main() ``` ``` { ``` ``` // integer variable ``` ``` int num = 10; ``` ``` int* add_of_num = &num; ``` ``` ​ ``` ``` printf("sizeof(num) = %d bytes\n", sizeof(num)); ``` ``` printf("&num = %p\n", &num); ``` ``` printf("*add_of_num = %d\n", *add_of_num); ``` ``` printf("(10 < 5) ? 10 : 20 = %d\n", (10 < 5) ? 10 : 20); ``` ``` printf("(float)num = %f\n", (float)num); ``` ``` ​ ``` ``` return 0; ``` ``` } ``` **Output** ``` sizeof(num) = 4 bytes &num = 0x7ffdb58c037c *add_of_num = 10 (10 < 5) ? 10 : 20 = 20 (float)num = 10.000000 ``` It is strongly recommended to learn [Operator Precedence and Associativity](https://www.geeksforgeeks.org/c/operator-precedence-and-associativity-in-c/) after reading about operators. Comparison Operators in C [Visit Course![course link icon](https://media.geeksforgeeks.org/auth-dashboard-uploads/Vector11.svg)](https://www.geeksforgeeks.org/courses/c-Programming-basic-to-advanced) Suggested Quiz ![reset](https://media.geeksforgeeks.org/auth-dashboard-uploads/Reset-icon---Light.svg) 5 Questions Which of the following is an arithmetic operator in C? - A && - B \|\| - C \+ - D \== What is the result of the expression 5 % 2 in C? - A 2 - B 1\.5 - C 1 - D 0 Which of the following is a relational operator in C? - A \= - B != - C & - D \+= What is the precedence of the multiplication \* operator compared to addition + in C? - A Lower - B Higher - C Same - D Undefined Which operator is used to access the value at an address in C? - A & - B \* - C \-\> - D . ![success](https://media.geeksforgeeks.org/auth-dashboard-uploads/sucess-img.png) Quiz Completed Successfully Your Score :0/5 Accuracy :0% Login to View Explanation **1**/5 \< Previous Next \> Comment [K](https://www.geeksforgeeks.org/user/kartik/) [kartik](https://www.geeksforgeeks.org/user/kartik/) 489 Article Tags: Article Tags: [C Language](https://www.geeksforgeeks.org/category/programming-language/c/) [C Basics](https://www.geeksforgeeks.org/tag/c-basics/) [C-Operators](https://www.geeksforgeeks.org/tag/c-operators/) ### Explore [![GeeksforGeeks](https://media.geeksforgeeks.org/auth-dashboard-uploads/gfgFooterLogo.png)](https://www.geeksforgeeks.org/) ![location](https://media.geeksforgeeks.org/img-practice/Location-1685004904.svg) Corporate & Communications Address: A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305) ![location](https://media.geeksforgeeks.org/img-practice/Location-1685004904.svg) Registered Address: K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305 [![GFG App on Play Store](https://media.geeksforgeeks.org/auth-dashboard-uploads/googleplay-%281%29.png)](https://geeksforgeeksapp.page.link/gfg-app)[![GFG App on App Store](https://media.geeksforgeeks.org/auth-dashboard-uploads/appstore-%281%29.png)](https://geeksforgeeksapp.page.link/gfg-app) - Company - [About Us](https://www.geeksforgeeks.org/about/) - [Legal](https://www.geeksforgeeks.org/legal/) - [Privacy Policy](https://www.geeksforgeeks.org/legal/privacy-policy/) - [Contact Us](https://www.geeksforgeeks.org/about/contact-us/) - [Advertise with us](https://www.geeksforgeeks.org/advertise-with-us/) - [GFG Corporate Solution](https://www.geeksforgeeks.org/gfg-corporate-solution/) - [Campus Training Program](https://www.geeksforgeeks.org/campus-training-program/) - Explore - [POTD](https://www.geeksforgeeks.org/problem-of-the-day) - [Job-A-Thon](https://practice.geeksforgeeks.org/events/rec/job-a-thon/) - [Blogs](https://www.geeksforgeeks.org/category/blogs/?type=recent) - [Nation Skill Up](https://www.geeksforgeeks.org/nation-skill-up/) - Tutorials - [Programming Languages](https://www.geeksforgeeks.org/computer-science-fundamentals/programming-language-tutorials/) - [DSA](https://www.geeksforgeeks.org/dsa/dsa-tutorial-learn-data-structures-and-algorithms/) - [Web Technology](https://www.geeksforgeeks.org/web-tech/web-technology/) - [AI, ML & Data Science](https://www.geeksforgeeks.org/machine-learning/ai-ml-and-data-science-tutorial-learn-ai-ml-and-data-science/) - [DevOps](https://www.geeksforgeeks.org/devops/devops-tutorial/) - [CS Core Subjects](https://www.geeksforgeeks.org/gate/gate-exam-tutorial/) - [Interview Preparation](https://www.geeksforgeeks.org/aptitude/interview-corner/) - [Software and Tools](https://www.geeksforgeeks.org/websites-apps/software-and-tools-a-to-z-list/) - Courses - [ML and Data Science](https://www.geeksforgeeks.org/courses/category/machine-learning-data-science) - [DSA and Placements](https://www.geeksforgeeks.org/courses/category/dsa-placements) - [Web Development](https://www.geeksforgeeks.org/courses/category/development-testing) - [Programming Languages](https://www.geeksforgeeks.org/courses/category/programming-languages) - [DevOps & Cloud](https://www.geeksforgeeks.org/courses/category/cloud-devops) - [GATE](https://www.geeksforgeeks.org/courses/category/gate) - [Trending Technologies](https://www.geeksforgeeks.org/courses/category/trending-technologies/) - Videos - [DSA](https://www.geeksforgeeks.org/videos/category/sde-sheet/) - [Python](https://www.geeksforgeeks.org/videos/category/python/) - [Java](https://www.geeksforgeeks.org/videos/category/java-w6y5f4/) - [C++](https://www.geeksforgeeks.org/videos/category/c/) - [Web Development](https://www.geeksforgeeks.org/videos/category/web-development/) - [Data Science](https://www.geeksforgeeks.org/videos/category/data-science/) - [CS Subjects](https://www.geeksforgeeks.org/videos/category/cs-subjects/) - Preparation Corner - [Interview Corner](https://www.geeksforgeeks.org/interview-prep/interview-corner/) - [Aptitude](https://www.geeksforgeeks.org/aptitude/aptitude-questions-and-answers/) - [Puzzles](https://www.geeksforgeeks.org/aptitude/puzzles/) - [GfG 160](https://www.geeksforgeeks.org/courses/gfg-160-series) - [System Design](https://www.geeksforgeeks.org/system-design/system-design-tutorial/) [@GeeksforGeeks, Sanchhaya Education Private Limited](https://www.geeksforgeeks.org/), [All rights reserved](https://www.geeksforgeeks.org/copyright-information/) ![]()
Readable Markdown
Operators are the basic components of C programming. They are symbols that represent some kind of operation, such as mathematical, relational, bitwise, conditional, or logical computations, which are to be performed on values or variables. The values and variables used with operators are called ****operands****. **Output** ``` 30 ``` ## Unary, Binary and Ternary Operators On the basis of the number of operands they work on, operators can be classified into three types : 1. ****Unary Operators:**** Operators that work on single operand. Example: Increment( ++ ) , Decrement( -- ) 2. ****Binary Operators:**** Operators that work on two operands. Example: Addition ( + ), Subtraction( - ) , Multiplication ( \* ) 3. ****Ternary Operators:**** Operators that work on three operands. Example****:**** Conditional Operator( ? : ) ## Types of Operators in C C language provides a wide range of built in operators that can be classified into 6 types based on their functionality: ## ****Arithmetic Operators**** The [arithmetic operators](https://www.geeksforgeeks.org/c/arithmetic-operators-in-c/) are used to perform arithmetic/mathematical operations on operands. There are ****9 arithmetic**** operators in C language****:**** **Output** ``` a + b = 30 a - b = 20 a * b = 125 a / b = 5 a % b = 0 +a = 25 -a = -25 a++ = 25 a-- = 26 ``` ## ****Relational Operators**** The [relational operators](https://www.geeksforgeeks.org/c/relational-operators-in-c/) in C are used for the comparison of the two operands. All these operators are binary operators that return true or false values as the result of comparison. **Output** ``` a < b : 0 a > b : 1 a <= b: 0 a >= b: 1 a == b: 0 a != b : 1 ``` Here, 0 means false and 1 means true. ## ****Logical Operator**** [Logical Operators](https://www.geeksforgeeks.org/c/logical-operators-in-c/) are used to combine two or more conditions/constraints or to complement the evaluation of the original condition in consideration. The result of the operation of a logical operator is a Boolean value either ****true**** or ****false****. | Symbol | ****Operator**** | Description | Syntax | |---|---|---|---| | ****&&**** | ****Logical AND**** | Returns true if both the operands are true. | ****a && b**** | | ****\|\|**** | ****Logical OR**** | Returns true if both or any of the operand is true. | ****a \|\| b**** | | ****\!**** | ****Logical NOT**** | Returns true if the operand is false. | ****!a**** | **Output** ``` a && b : 1 a || b : 1 !a: 0 ``` ## ****Bitwise Operators**** The [Bitwise operators](https://www.geeksforgeeks.org/c/bitwise-operators-in-c-cpp/) are used to perform bit-level operations on the operands. The operators are first converted to bit-level and then the calculation is performed on the operands. ****Note:**** Mathematical operations such as addition, subtraction, multiplication, etc. can be performed at the bit level for faster processing. | Symbol | ****Operator**** | Description | Syntax | |---|---|---|---| | ****&**** | ****Bitwise AND**** | Performs bit-by-bit AND operation and returns the result. | ****a & b**** | | ****\|**** | ****Bitwise OR**** | Performs bit-by-bit OR operation and returns the result. | ****a \| b**** | | ****^**** | ****Bitwise XOR**** | Performs bit-by-bit XOR operation and returns the result. | ****a ^ b**** | | ****~**** | ****Bitwise First Complement**** | Flips all the set and unset bits on the number. | ****~a**** | | ****\<\<**** | ****Bitwise Leftshift**** | Shifts bits to the left by a given number of positions; multiplies the number by 2 for each shift. | ****a \<\< b**** | | ****\>\>**** | ****Bitwise Rightshift**** | Shifts bits to the right by a given number of positions; divides the number by 2 for each shift. | ****a \>\> b**** | **Output** ``` a & b: 1 a | b: 29 a ^ b: 28 ~a: -26 a >> b: 0 a << b: 800 ``` ## ****Assignment Operators**** [Assignment operators](https://www.geeksforgeeks.org/c/assignment-operators-in-c-c/) are used to assign value to a variable. The left side operand of the assignment operator is a variable and the right side operand of the assignment operator is a value. The value on the right side must be of the same data type as the variable on the left side otherwise the compiler will raise an error. The assignment operators can be combined with some other operators in C to provide multiple operations using single operator. These operators are called compound operators. | Symbol | ****Operator**** | Description | Syntax | |---|---|---|---| | ****\=**** | ****Simple Assignment**** | Assign the value of the right operand to the left operand. | ****a = b**** | | ****\+=**** | ****Plus and assign**** | Add the right operand and left operand and assign this value to the left operand. | ****a += b**** | | ****\-=**** | ****Minus and assign**** | Subtract the right operand and left operand and assign this value to the left operand. | ****a -= b**** | | ****\*=**** | ****Multiply and assign**** | Multiply the right operand and left operand and assign this value to the left operand. | ****a \*= b**** | | ****/=**** | ****Divide and assign**** | Divide the left operand with the right operand and assign this value to the left operand. | ****a /= b**** | | ****%=**** | ****Modulus and assign**** | Assign the remainder in the division of left operand with the right operand to the left operand. | ****a %= b**** | | ****&=**** | ****AND and assign**** | Performs bitwise AND and assigns this value to the left operand. | ****a &= b**** | | ****\|=**** | ****OR and assign**** | Performs bitwise OR and assigns this value to the left operand. | ****a \|= b**** | | ****^=**** | ****XOR and assign**** | Performs bitwise XOR and assigns this value to the left operand. | ****a ^= b**** | | ****\>\>=**** | ****Rightshift and assign**** | Performs bitwise Rightshift and assign this value to the left operand. | ****a \>\>= b**** | | ****\<\<=**** | ****Leftshift and assign**** | Performs bitwise Leftshift and assign this value to the left operand. | ****a \<\<= b**** | **Output** ``` a = b: 5 a += b: 10 a -= b: 5 a *= b: 25 a /= b: 5 a %= b: 0 a &= b: 0 a |= b: 5 a ^= b: 0 a >>= b: 0 a <<= b: 0 ``` ## ****Other Operators**** Apart from the above operators, there are some other operators available in C used to perform some specific tasks. Some of them are discussed here: ### ****sizeof Operator**** - [sizeof](https://www.geeksforgeeks.org/c/sizeof-operator-c/) is much used in the C programming language. - It is a compile-time unary operator which can be used to compute the size of its operand. - The result of sizeof is of the unsigned integral type which is usually denoted by size\_t. - Basically, the sizeof the operator is used to compute the size of the variable or datatype. ****Syntax**** `` ### Comma Operator ( , ) The [comma operator](https://www.geeksforgeeks.org/c/comma-in-c/) (represented by the token) is a binary operator that evaluates its first operand and discards the result, it then evaluates the second operand and returns this value (and type). The comma operator has the lowest precedence of any C operator. It can act as both operator and separator. ****Syntax**** `` ### Conditional Operator ( ? : ) The [****conditional operator****](https://www.geeksforgeeks.org/c/conditional-or-ternary-operator-in-c/) is the only ternary operator in C. It is a conditional operator that we can use in place of if..else statements. ****Syntax**** `` Here, ****Expression1**** is the condition to be evaluated. If the condition(****Expression1****) is *****True*****then we will execute and return the result of ****Expression2**** otherwise if the condition(****Expression1****) is *****false*****then we will execute and return the result of ****Expression3****. ### ****dot (.) and arrow (-\>) Operators**** Member operators are used to reference individual members of classes, structures, and unions. - The [****dot operator****](https://www.geeksforgeeks.org/c/dot-operator-in-c/) is applied to the actual object. - The [****arrow operator****](https://www.geeksforgeeks.org/c/arrow-operator-in-c-c-with-examples/) is used with a pointer to an object. ****Syntax**** `` ### ****Cast Operators**** [****Casting operators****](https://www.geeksforgeeks.org/cpp/casting-operators-in-cpp/) convert one data type to another. For example, int(2.2000) would return 2. - A cast is a special operator that forces one data type to be converted into another. ****Syntax**** `` ### ****addressof (&) and Dereference (\*) Operators**** [Addressof operator &](https://www.geeksforgeeks.org/cpp/address-operator-in-c/) returns the address of a variable and the [dereference operator \*](https://www.geeksforgeeks.org/cpp/dereference-pointer-in-c/) is used to access the value stored at that address. ### Example of Other C Operators **Output** ``` sizeof(num) = 4 bytes &num = 0x7ffdb58c037c *add_of_num = 10 (10 < 5) ? 10 : 20 = 20 (float)num = 10.000000 ``` It is strongly recommended to learn [Operator Precedence and Associativity](https://www.geeksforgeeks.org/c/operator-precedence-and-associativity-in-c/) after reading about operators.
Shard103 (laksa)
Root Hash12046344915360636903
Unparsed URLorg,geeksforgeeks!www,/c/operators-in-c/ s443