Operator | Description | Associativity |
|---|---|---|
| () [] . -> ++ -- | Parentheses (function call) Brackets (array subscript) Member selection via object name Member selection via pointer Postfix increment/decrement | left-to-right |
| ++ -- + - ! ~ (type) * & sizeof | Prefix increment/decrement Unary plus/minus Logical negation/bitwise complement Cast (change type) Dereference Address Determine size in bytes | right-to-left |
| * / % | Multiplication/division/modulus | left-to-right |
| + - | Addition/subtraction | left-to-right |
| << >> | Bitwise shift left, Bitwise shift right | left-to-right |
| < <= > >= | Relational less than/less than or equal to Relational greater than/greater than or equal to | left-to-right |
| == != | Relational is equal to/is not equal to | left-to-right |
| & | Bitwise AND | left-to-right |
| ^ | Bitwise exclusive OR | left-to-right |
| | | Bitwise inclusive OR | left-to-right |
| && | Logical AND | left-to-right |
| || | Logical OR | left-to-right |
| ?: | Ternary conditional | right-to-left |
| = += -= *= /= %= &= ^= |= <<= >>= | Assignment Addition/subtraction assignment Multiplication/division assignment Modulus/bitwise AND assignment Bitwise exclusive/inclusive OR assignment Bitwise shift left/right assignment | right-to-left |
, | Comma (separate expressions) | left-to-right |
Thursday, February 10, 2011
C Operator Precedence and Associativity
Saturday, February 5, 2011
Program to print a semicolon without using semicolon in the code.
Program to print a semicolon without using semicolon in the code.
#include <stdio.h>
void main() {
//prints the character with ascii value 59, i.e., semicolon
if (printf("%c\n", 59)) {
//prints semicolon
}
}
Output:
;
Explanation:
If statement checks whether return value of printf function is greater than zero or not. The return value of function
call printf("%c",59) is 1. As printf returns the length of the string printed. printf("%c",59) prints ascii value that
corresponds to 59, that is semicolon(;).
#include <stdio.h>
void main() {
//prints the character with ascii value 59, i.e., semicolon
if (printf("%c\n", 59)) {
//prints semicolon
}
}
Output:
;
Explanation:
If statement checks whether return value of printf function is greater than zero or not. The return value of function
call printf("%c",59) is 1. As printf returns the length of the string printed. printf("%c",59) prints ascii value that
corresponds to 59, that is semicolon(;).
Subscribe to:
Posts (Atom)