uwhpsc-2016 / homework2

Homework #2
0 stars 3 forks source link

Calling functions from other functions #24

Open gadamico opened 8 years ago

gadamico commented 8 years ago

In constructing jacobi.c and gauss_seidel.c it seems prudent to call functions constructed in earlier parts of the homework. In the functions that return only by reference we used a variable out to store the result. But when calling several such functions from, say, jacobi.c, I suppose we'd need to create and use several distinct "out" variables to keep them all straight?

quantheory commented 8 years ago

Yep. I would recommend giving them names that reflect what they are (e.g. lower or L for a lower triangular matrix).

cswiercz commented 8 years ago

Just because a function argument is given the name out doesn't mean that anything passed to it needs to be named out. A simple example is the following:

int square(int out)
{
  return out*out;
}

This can be called like so

int myvar = 2;
int another_var = square(myvar) // doesn't need to be called "out"
another_var = square(10); // literals don't even have a variable name