Consider the following C program:
int sub(int *sum)
{ *sum =*sum +*sum;
return 10; }
void main() {
int num= 3;
num = sub(&num)+ num;
}
What is the value of num after the assignment statement in main, assuming
operands are evaluated left to right.
operands are evaluated right to left.
by function definition :
int sub(int *sum)
{ *sum =*sum +*sum;
return 10; }
we see that whatever value we pass to this function, it will return 10 irrespective of the value of sum.
main function:
void main() {
int num= 3;
num = sub(&num) + num;
}
value of num
will be value returned by sub function + num
num is initialised by 3
so as we have seen sub function will return 10 and value of num is 3
so statement is
10 + 3
operands are evaluated left to right.
operands are evaluated right to left.
these will not make any difference as there is only one operator and value calculated from left to right or right to left will be same.
so answer for given problem for both the cases will be : 13.
Hope this helps!
Kindly appreciate the help by upvoting the answer. Thank you!
Consider the following C program: int sub(int *sum) { *sum =*sum +*sum; return 10; } void...
4. Consider the following C program: (2 points) int fun( int *j){ + 11; return 9; } void main(){ int k 2; k + fun( &k); k What is the value of k after the assignment statement in main, assuming operands are evaluated left to right. operands are evaluated right to left. Please, also explain how you got the values in detail.
Consider the following program: # include <iostream> int x = 3, y = 5; void foo(void) { x = x + 2; y = y + 4; } void bar(void) { int x = 10; y = y + 3; foo( ); cout << x << endl; cout << y << endl; } void baz(void) { int y = 7; bar( ); cout << y << endl; } void main( ) { baz( ); } What output does this program...
Consider the following C++ program: #include <iostream> using namespace std; void f1(int); void f2(int); void f3(int); int main() { f1(10); return 0; } void f1(int n) { f2(n + 5); } void f2(int n) { f3(n - 2); } void f3(int n) { cout << n << endl; // LINE 1 } Just before the program statement marked with the comment "LINE 1" is executed, how many stack frames will be on the program call stack?
Consider the following program: # include <iostream> using namesapce std; void Func(int a, int bl double number-25.0: int main) f int x-18, y-20; cout<c"Before: x- kex<" and y-eyecendl; Fundxy 1// end of main void Funcfint a, int b) int sum a+b; a-200; b-300; numberanumber+1.0 Which of the statements below are correct? (Select only the correct answers. There may be more than one) D A The statement double number-25.0; declares a global variable number B. The variables x and y are...
2. Write a MIPS program that translates the following C code int a 1234; b 5678 int sum void main () atb sum = cout <<sum; } 2. Write a MIPS program that translates the following C code int a 1234; b 5678 int sum void main () atb sum = cout
#include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void displayArrayContent(int[]); void displayLargestValue(int[]); void displaySmallestValue(int[]); int main(){ int number; int numbers[SIZE] = {9,1,90,98,53,22,76,29,37,65}; cout <<"Enter a number: "; cin >> number; cout << endl; displayGreaterThan(numbers,number); cout << endl; displaySmallerThan(numbers,number); cout << endl; displayArrayContent(numbers); cout << endl; displayLargestValue(numbers); cout << endl; displaySmallestValue(numbers); cout << endl; return 0; } void displayGreaterThan(int value[],int num){ cout << " All larger value(s)than" <<...
XCORE Question 1 Consider the following program void Elint x, int y Y = y + 1 cout<<x<<"*«y << endl; void nain) 1 int i, a13): all) = 15; a 2) - 203 a13) = 25; cout <i«"" <all) <<"" << a12) << ""« a[3] << endl; cout <i<** <all) << "" << a12) <<""« a[3] << endl; What values of the variable and array A are printed with the following rules. a parameters are passed by value bi parameters...
6) What is the final value of variable num after executing the following statements? void Exam(int & N) A)13 ( T++ ¢ut << < 1 ) B)12 void main() (int num-10; C) 11 for (int i - 0; i < 3; i.) Exam (num). D) 10
QUESTION 62 Consider the following code: void Pancake(int x, int& y, int z); void Waffle(int& x, int& y); int Doughnut(int y, int z); int main( ) { int a = 1; int b = 2; int c = 3; int d = 4; Pancake(a, b, c); Waffle(b, c); Pancake(d, c, b); d = Doughnut(b, a); return 0; } void Pancake(int x, int& y, int z) { y += 3; ...
(10pts). Consider the following: void fun1(void); void fun2(void); void fun3(void); void main() { Int a,b,c; … } void fun1(void){ Int b,c,d; … } void fun2(void){ Int c,d,e; … } void fun3(void){ Int d,e,f; … } Given the following calling sequences and assuming that dynamic scoping is used. What variables are visible during execution of the last function called? Include with each visible variable the name of the function in which it was...