Evaluate the following C expression, assuming: 4 * 4 + 8 - 4 / 2 the precedence of operators is +,
Posted: Sun May 15, 2022 8:03 am
Evaluate the following C expression, assuming:
4 * 4
+ 8 -
4 / 2
the precedence of operators is +, -, /, *:
____________
the precedence of operators is /, -, *, +:
____________
all operators are at the same precedence, and
associate left to right: ____________
all operators are at the same precedence, and
associate right to left: ____________
How many times does the following C code iterate:
int a = 1;
int b = 5;
while( a++ && b-- && a
<= b )
cout <<
'*';
assuming that changes in the values of
variables do not affect subsequent occurrences of those variables
in the same expression (e.g., C)? ____________
assuming that changes in the values of
variables do affect subsequent occurrences of those variables in
the same expression? ____________
How many times does the following C code iterate:
int a = 3;
int b = 3;
while( --a > 0 || --b > 0 ) //Note:
--a returns value AFTER decrementing
cout <<
'*';
with short-circuit evaluation?
____________
without short-circuit evaluation?
____________
Given the following C/C++ code:
int global = 3, val = 2;
int SideEffect( int & par ) // Note: Parameter
passed by REFERENCE
{
int temp = global;
global = par;
par = temp;
return global;
}
Evaluate the expression: SideEffect ( val ) * val
assuming Left -> Right evaluation of
operands ____________
assuming Right -> Left evaluation of
operands ____________
4 * 4
+ 8 -
4 / 2
the precedence of operators is +, -, /, *:
____________
the precedence of operators is /, -, *, +:
____________
all operators are at the same precedence, and
associate left to right: ____________
all operators are at the same precedence, and
associate right to left: ____________
How many times does the following C code iterate:
int a = 1;
int b = 5;
while( a++ && b-- && a
<= b )
cout <<
'*';
assuming that changes in the values of
variables do not affect subsequent occurrences of those variables
in the same expression (e.g., C)? ____________
assuming that changes in the values of
variables do affect subsequent occurrences of those variables in
the same expression? ____________
How many times does the following C code iterate:
int a = 3;
int b = 3;
while( --a > 0 || --b > 0 ) //Note:
--a returns value AFTER decrementing
cout <<
'*';
with short-circuit evaluation?
____________
without short-circuit evaluation?
____________
Given the following C/C++ code:
int global = 3, val = 2;
int SideEffect( int & par ) // Note: Parameter
passed by REFERENCE
{
int temp = global;
global = par;
par = temp;
return global;
}
Evaluate the expression: SideEffect ( val ) * val
assuming Left -> Right evaluation of
operands ____________
assuming Right -> Left evaluation of
operands ____________