Purchase Solution

The Direction of Passing Parameters in C

Not what you're looking for?

Ask Custom Question

Let the function fun be defined as:

int fun(int *k) {
*k += 4;
return 3 * (*k) - 1;
}

Suppose fun is used in a program as follows:

void main() {
int I = 10, j = 10, sum1, sum2;
sum1 = (I / 2) + fun(&i);
sum2 - fun(&j) + (j / 2);
}

What are the values of sum1 and sum2?
a. If the operands in the expressions are evaluated left to right?
b. If the operands in the expressions are evaluated right to left?

Now the answers are: Let the function fun be defined as:

int fun(int *k) {
*k += 4;
return 3 * (*k) - 1;
}

Suppose fun is used in a program as follows:

void main() {
int I = 10, j = 10, sum1, sum2;
sum1 = (I / 2) + fun(&i);
sum2 - fun(&j) + (j / 2);
}

What are the values of sum1 and sum2?
a. If the operands in the expressions are evaluated left to right?
b. If the operands in the expressions are evaluated right to left? Let the function fun be defined as

int fun(int *k) {
*k += 4;
return 3 * (*k) - 1;
}

Suppose fun is used in a program as follows:

void main() {
int I = 10, j = 10, sum1, sum2;
sum1 = (I / 2) + fun(&i);
sum2 - fun(&j) + (j / 2);
}

What are the values of sum1 and sum2?
a. If the operands in the expressions are evaluated left to right? Sum1=46, Sum2=48
b. If the operands in the expressions are evaluated right to left? Sum1=48, Sum2=46

Purchase this Solution

Solution Summary

This solution provides a detailed, step by step response illustrating how a parameter will change in a C function by value or address, and direction as well.

Solution Preview

a. If the operands in the expressions are evaluated left to right?

sum1 = 46;
sum2 = 48;

Code:

int fun(int *k) {
*k += 4;
return 3 * (*k) - 1;
}

void main()
{
int i = 10, ...

Purchase this Solution


Free BrainMass Quizzes
Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.