Question

1. f(m, n) w = w+1; n = 3; m = n * 10; main W = 0; int z[] = {10, 20, 30}; f(z[w], z[0]); print (z[w], z[0]); Given the code

0 0
Add a comment Improve this question Transcribed image text
Answer #1

a) In the above code, we can see that the function f is not returning any value (we can say that it is a void function), so the output of the following code will be the values written in the print statement that is z[w] and z[0], it has already assigned the value of w=0, so z[w] = z[0] that is 10 in the given array.

output:- 10 10

b) if the value-result and address of z[w] are computed at the time of the call, it will not show any effect on the output.

output:- 10 10

yes, you can print the address of the z[w], the address will be printed.

c) If we pass reference instead of value then the values of the variables will be changed

f(&m,&n) --> m=30 n=3

and it will update the value of z[0] and z[w] and it will not update the value of w because the reference of w is not passed the only reference of z[w] and z[0] is passed.

output:- 30 3

d) If we pass the name instead of value the values will be updated locally for that function only, and it will not update anything in the main function

so the output will be-

output:- 10 10

I hope you get the answer, so please upvote my rating if u have any queries then ask me in the comment section.
Thanks!!

Add a comment
Know the answer?
Add Answer to:
1. f(m, n) w = w+1; n = 3; m = n * 10; main W...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. f (m, n) m- n* 10; main int z[] 10, 20, 30; print(z [w], z[0]);...

    1. f (m, n) m- n* 10; main int z[] 10, 20, 30; print(z [w], z[0]); Given the code above, what is the output of the program if the values are passed by: a) Value. b) Value-result and address of z[ c) Reference. d) Name is computed at the time of the cal Note: The order of evaluating the parameters of a subprogram are from left to right.)

  • Consider the following code C++ like program: int i, j, arr[5]; //arr is an array starting...

    Consider the following code C++ like program: int i, j, arr[5]; //arr is an array starting at index 0 void exchange(int x, int y) { int temp:= x; x:= y; y:= temp; } main(){ for (j = 0; j < 5; j++) arr[j]:= j; i:= 1; exchange(i, arr[i+1]); output(i, arr[2]); //print i and arr[2] } What is the output of the code if both parameters in function swapping are passed by: a- value? b- reference? c- value-result?

  • 1-Is it possible to run a program without a main() function? Yes No 2- How many...

    1-Is it possible to run a program without a main() function? Yes No 2- How many main() functions can one have in a program? 2 This depends on what compiler you use. As many as you like 1 3- What does the following code fragment leave in x? char a = 'A'; int x = sizeof (a); 1 Depends on what compiler you use. 4 2 4- True or false: In a C program I can have two functions with...

  • Given the following program in a C-like syntax, what does F1(m) return assuming static scoping and...

    Given the following program in a C-like syntax, what does F1(m) return assuming static scoping and dynamic scoping? You can assume that expressions are evaluated from left to right. int m = 3; int F1(int i) { return (i + F2(m) + m); } int F2(int j) { j++; return (j * m); } int main() { int m = 5; F1(m); } Explain in details how you got the answers to earn full credit. Don't just write the answer....

  • Using C programming language Question 1 a) through m) Exercise #1: Write a C program that...

    Using C programming language Question 1 a) through m) Exercise #1: Write a C program that contains the following steps (make sure all variables are int). Read carefully each step as they are not only programming steps but also learning topics that explain how functions in C really work. a. Ask the user for a number between 10 and 99. Write an input validation loop to make sure it is within the prescribed range and ask again if not. b....

  • answer in c++ Using the table below, complete the C++ code to write the function prototype...

    answer in c++ Using the table below, complete the C++ code to write the function prototype statement, and the void function header. The void function should receive three double variables: the first two by value and the last one by reference. Name the formal parameters num1, num2 and answer. The function should divide the num1 variable by the num2 variable and then store the result in the answer variable. Name the function calcQuotient. Also write an appropriate function prototype for...

  • #include<stdio.h> #include<stdio.h> int main(){ int i; //initialize array char array[10] = {“Smith”, “Owen”, “Kowalczyk”, “Glass”, “Bierling”,...

    #include<stdio.h> #include<stdio.h> int main(){ int i; //initialize array char array[10] = {“Smith”, “Owen”, “Kowalczyk”, “Glass”, “Bierling”, “Hanenburg”, “Rhoderick”, “Pearce”, “Raymond”, “Kamphuis”}; for(int i=0; i<8;i++){ for(int j=0; j<9; j++){ if(strcmp(array[j],array[j+1])>0){ char temp[20]; strcpy(temp,array[j]); strcpy(array[j],array[j+1]); strcpy(array[j+1],temp); } } } printf(“---------File Names---------\n”); for(inti=0; i<9; i++){ printf(“\t%s\n”,array[i]); } printf(-------5 Largest Files according to sorting----\n”); for(int i=0;i>=5;i--) { printf(“\t%s\n”,array[i]); } return0; } Consider the "sort" program (using with void* parameters in the bubblesort function) from the week 10 "sort void" lecture. Modify it as follows...

  • (17) (1 mark) What is the static parent of a subprogram? (18) (1 mark) What is...

    (17) (1 mark) What is the static parent of a subprogram? (18) (1 mark) What is a formal parameter? (19) (3 marks) Consider the following program, written in a C-like lan- guage int x void f(int a) {а- а+2; х %3D х+1;} void main x 1 f(x); printf("x= d\n",x); What value ot xwill be printed by the main program under each of the tollowing conditions? Imagine that tformal parameter a of function fis being passed: i by value ii. by...

  • XCORE Question 1 Consider the following program void Elint x, int y Y = y +...

    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...

  • 1 Rewrite the following program so that it will use function. include <stdio.h> Int main) printf...

    1 Rewrite the following program so that it will use function. include <stdio.h> Int main) printf ("Hello!") return 0 2 Assume a program has the following declarations: short s- 4 int i--5; long m-3 float f-19.3f; double d-3.6; What are the following values? (a) s+m (b) (float) d (c) d s (e) (int) f 3 What will be the output of the following program: int x = 3 float a 2.76; y-2* x; print f("X-2d, y*ta, z»%d", x, y, z);...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT