0
Simple C++ Expression
// I know that this one is simple, but Iâm only about 25% into the C++ course. Can someone explain the answer, please? Thank you. âWhat is the result of the following expression?â cout << 1000/100%7*2; // My logic: Using PEMDAS (Iâm not sure when to execute modulus), 7*2 = 14 1000/100 = 10 10%14 = 10 output = 10 // Alt logic: 100%7 = 2 2*2 = 4 1000/4 = 250 Output = 250
3 RĂ©ponses
+ 3
https://en.cppreference.com/w/cpp/language/operator_precedence
Says it executes left to right for operators /, *, % .
So most probably it's executing that way only like "/" first , then "%" and after we have "*".
+ 3
C++ logic: from left to right
1000/100=10
10%7=3
3*2=6
There are no brackets in your expression. Division, multiplication, and modulus have equal status. It means that your expression is executed from left to right.
+ 1
Abhay and Katty Leony ,
Thank you. Iâll review that link.