--- In [email protected], Christopher Coale <chris95...@...> wrote:
>
> double Sma(double *ds, int size)

A slight improvement is:

double Sma(const double *ds, int size)

The const tells the compiler and the reader that the function isn't supposed to 
modify the data at ds; it is 'constant'. For example if you made a mistake and 
wrote:

  (*ds)++ // modifies *ds - bug

instead of:

  *(ds++) // modifies ds

then in the first case the compiler would give you a 'writing to constant 
location' (or similar) warning/error.

If you look at the prototype for the printf function, you will see const used 
in that as well:

int printf(const char *format, ...);

So you know that whatever you use as the format string argument, the printf 
function isn't going to modify it.

Reply via email to