G
gwowen
Is the following function well defined?
int f(int a, int b int c){
return a * b / c;
}
If so, what is f(5,1,3) ?
int f(int a, int b int c){
return a * b / c;
}
If so, what is f(5,1,3) ?
5 * 1 / 3 is equivalent to (5 * 1) / 3, which is equal to 5/3 = 1,
because multiplication and division (which have the same precedence)
associate left-to-right.
Is the following function well defined?
int f(int a, int b int c){
return a * b / c;
}
If so, what is f(5,1,3) ?
In
In general, yes, but not if overflow occurs (undefined) or c is 0
(undefined) or if either operand is negative
(implementation-defined).
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.