Call by Value and Call by Reference in C

Discuss how to use and promote Web standards with the Mozilla Gecko engine.
Locked
Bidisha20
New Member
Posts: 1
Joined: June 20th, 2022, 5:42 am

Call by Value and Call by Reference in C

Post by Bidisha20 »

I'm trying to understand the conceptual difference between call by reference, value, and name.

So I have the following pseudocode:

Code: Select all

foo(a, b, c)
{
   b =b++;
   a = a++;
   c = a + b*10
}

X=1;
Y=2;
Z=3;
foo(X, Y+2, Z);
What's X, Y, and Z after the foo call if a, b, and c are all call by reference? if a, b, and c are call-by-value/result? if a, b, and c are call-by-name?

Another scenario:

Code: Select all

X=1;
Y=2;
Z=3;
foo(X, Y+2, X);
I'm trying to get a head start on studying for an upcoming final and this seemed like a good review problem to go over. Pass-by-name is definitely the most foreign to me.
User avatar
jscher2000
Posts: 11762
Joined: December 19th, 2004, 12:26 am
Location: Silicon Valley, CA USA
Contact:

Re: Call by Value and Call by Reference in C

Post by jscher2000 »

This probably is not a good forum for C questions.
Locked