PLEASE NOTE: the upgrades to this server,, have not yet been completed.
Hopefully the changes will be completed on THURSDAY 8th December.
Web-based programs, such as csmarks, cssubmit, and the help fora, will be unavailable at some time on Thursday 8th.
  It's UWAweek 49


This forum is provided to promote discussion amongst students enrolled in CITS2002 Systems Programming.
Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.

Displaying selected article
Showing 1 of 919 articles.
Currently 5 other people reading this forum.

 UWA week 37 (2nd semester, week 7) ↓
SVG not supported

Login to reply

5:54am Fri 16th Sep, Christopher M.

"Thomas Morton" <23*6*4*[email protected]*u*e*t*u*a*e*u*a*> wrote:
> I would imaging that pass-by-value, would require a lot of memory for making copies, especially when dealing with large arrays or structs. On the other hand, I would expect pass-by-reference to require a small, fixed amount of memory no matter what, since the size of an address is fixed.
Hi Thomas, You are correct that pass-by-value will always be more expensive, both in terms of required space on the runtime stack and in the time required to copy the data before calling the function. On contemporary CPUs, all pointers are the same size, so pass-by-reference can also make the compilers' life easier. But pass-by-value is the default mechanism in most programming languages, to prevent the function from accidently modifying the caller's original values. We also know in C that the name of an array is is equivalent to the address of the array's first element, so passing an array (name) to a function is akin to passing the array by reference. But sometimes you don't want this, we don't want the function to be able to modify the original data. So a neat trick is to wrap an array inside a structure, as structures are always passed-by-value:
typedef struct {
    int   array[N];

void function(MYTYPE parameter)
    parameter.array[0] = .... ;

    MYTYPE localstruct;


The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  1:17AM Sep 14 2022
Privacy policy