Operators
An operator is a symbol that is used to perform operations. There can be many types of operations like arithmetic, logical, bitwise etc. There are following types of operators to perform different types of operations in C language.
Precedence of Operators in C
The precedence of operator species that which operator will be evaluated first and next. The associativity specifies the operators direction to be evaluated, it may be left to right or right to left.
Let's understand the precedence by the example given below:
int value=20+30*10;
The value variable will contain 320 because * (multiplicative operator) is evaluated before + (additive operator).
The precedence and associativity of C operators is given below:
Category | Operator | Associativity |
---|---|---|
Postfix | () [] -> . ++ - - | Left to right |
Unary | + - ! ~ ++ - - (type)* & sizeof | Right to left |
Multiplicative | * / % | Left to right |
Additive | + - | Left to right |
Shift | << >> | Left to right |
Relational | < <= > >= | Left to right |
Equality | == != | Left to right |
Bitwise AND | & | Left to right |
Bitwise XOR | ^ | Left to right |
Bitwise OR | | | Left to right |
Logical AND | && | Left to right |
Logical OR | || | Left to right |
Conditional | ?: | Right to left |
Assignment | = += -= *= /= %=>>= <<= &= ^= |= | Right to left |
Comma | , | Left to right |
Keyword in C
A keyword is a reserved word. You cannot use it as a variable name, constant name etc. There are only 32 reserved words (keywords) in C language.
A list of 32 keywords in c language is given below:
auto | break | case | char | const | continue | default | do |
double | else | enum | extern | float | for | goto | if |
int | long | register | return | short | signed | sizeof | static |
struct | switch | typedef | union | unsigned | void | volatile | while |
Comments in C
Comments in C language are used to provide information about lines of code. It is widely used for documenting code. There are 2 types of comments in C language.Single Line Comments
Single line comments are represented by double slash \\. Let's see an example of single line comment in C.#include <stdio.h> void main( ) { //printing information printf("Hello Catchmecoder"); } Output: Hello Catchmecoder
printf("Hello Catchmecoder"); //printing information
Mult Line Comments
Multi line comments are represented by slash asterisk \* ... *\. It can occupy many lines of code but it can't be nested. Syntax:/* code to be commented */
#include <stdio.h> void main( ) { /*printing information*/ printf("Hello Catchmecoder"); } Output: Hello Catchmecoder