filmov
tv
C Operator Precedence & Associativity - C Programming Tutorial 41
Показать описание
C Operator Precedence & Associativity - C Programming Tutorial 41
Precedence:
While evaluating a given expression; which operator should be evaluated first before the other?
I.e. which operator needs to be given higher precedence than the other?
Associativity:
If same operator appears two or more times in an expression, in which direction the specific operator(s) needs to be evaluated
a = 3 * 5 + 10 / 2 + 3 + 20 -10
Precedence and associativity of C operators table: P UMASRE BLCAC
P. Level | Operators
1 | P: Parenthesis
2 | U: Unary
3 | M: Multiplicative
4 | A: Additive
5 | S: Shift
6 | R: Relational
7 | E: Equality
8 | B: Bitwise
9 | L: Logical
10 | C: Conditional
11 | A: Assignment
12 | C: Comma
Note:
- Only Unary and Assign operators have Right to Left Associativity.
Example code:
#include <stdio.h>
int main()
{
printf("%d\n", 2 + 2 + 2); // 6
printf("%d\n", 2 + 3 * 5); // 17 not 20
printf("%d\n", 3 * 5 + 4 / 2 + 3); // 20
printf("%f\n", 3 * 9 / 2 + 3); // 0.000000
printf("%d\n", 3 * 9 / 2 + 3); // 16
printf("%.1f\n", 3 * 9 / (float)2 + 3); // 16.5
return 0;
}
Note:
- replace < with less-than symbol.
- replace > with greater-than symbol.
=========================================
Follow the link for next video:
Follow the link for previous video:
=========================================
C Programming Tutorials Playlist:
=========================================
Watch My Other Useful Tutorials:-
Computer Programming Fundamentals Playlist:-
C Practical LAB Exercises Playlist:-
C++ Tutorials Playlist:
=========================================
► Subscribe to our YouTube channel:
► Visit our Website:
=========================================
Hash Tags:-
#ChidresTechTutorials #CProgramming #CProgrammingTutorial
Precedence:
While evaluating a given expression; which operator should be evaluated first before the other?
I.e. which operator needs to be given higher precedence than the other?
Associativity:
If same operator appears two or more times in an expression, in which direction the specific operator(s) needs to be evaluated
a = 3 * 5 + 10 / 2 + 3 + 20 -10
Precedence and associativity of C operators table: P UMASRE BLCAC
P. Level | Operators
1 | P: Parenthesis
2 | U: Unary
3 | M: Multiplicative
4 | A: Additive
5 | S: Shift
6 | R: Relational
7 | E: Equality
8 | B: Bitwise
9 | L: Logical
10 | C: Conditional
11 | A: Assignment
12 | C: Comma
Note:
- Only Unary and Assign operators have Right to Left Associativity.
Example code:
#include <stdio.h>
int main()
{
printf("%d\n", 2 + 2 + 2); // 6
printf("%d\n", 2 + 3 * 5); // 17 not 20
printf("%d\n", 3 * 5 + 4 / 2 + 3); // 20
printf("%f\n", 3 * 9 / 2 + 3); // 0.000000
printf("%d\n", 3 * 9 / 2 + 3); // 16
printf("%.1f\n", 3 * 9 / (float)2 + 3); // 16.5
return 0;
}
Note:
- replace < with less-than symbol.
- replace > with greater-than symbol.
=========================================
Follow the link for next video:
Follow the link for previous video:
=========================================
C Programming Tutorials Playlist:
=========================================
Watch My Other Useful Tutorials:-
Computer Programming Fundamentals Playlist:-
C Practical LAB Exercises Playlist:-
C++ Tutorials Playlist:
=========================================
► Subscribe to our YouTube channel:
► Visit our Website:
=========================================
Hash Tags:-
#ChidresTechTutorials #CProgramming #CProgrammingTutorial
Комментарии