Reputation:
Is this function have any sense? if I didn't define the value of p_var1[] and p_size?
Just to know if it make sense, I have bigger code, but as a beginner, for me, if there is no values for these variables, that is weird.
First function:
int max1(int p_values[15][15])
{
int max_value;
for(int i=0; i < 15; i++)
{
int max_v = fnc(p_values[i], 15);
if( max_value < max_v)
{
max_value = max_v;
}
}
return max_value;
}
and second
//p_var1[] - is an array of values
//p_size - is the size of array
int fnc(int p_var1[], int p_size)
{
int max_value;
for (int i = 0; i < p_size; i++)
{
if (max_value > p_var1[i])
{
max_value = p_var[i];
}
}
return max_value;
}
Upvotes: 0
Views: 69
Reputation: 16853
I guess you wrote fnc(p_values[i], 15)
without knowing what it means? Not the best approach, but asking about it shows promise. When this expression is reached, the fnc
identifier says that we're going to pause the execution of the current function (max1
) and jump to execute the function fnc
. Once that function finishes, the returned value will be the value of the expression and execution of max1
can resume. The stuff in the parentheses says that as we jump to fnc
, assign p_var1 = p_values[i]
and p_size = 15
(the first parameter is assigned the first argument, and the second parameter is assigned the second argument). If you're confused by the terms "parameter" and "argument", see What's the difference between an argument and a parameter?
So when you call fnc
you do define the value of p_var1
and p_size
(for that function call). (Wikipedia has an article with an example that covers this also, and you might find some useful information in the rest of that article.)
Upvotes: 0
Reputation: 1035
This code isn't a full program, it's just a function definition. Here, a function called fnc
is declared that can be called with parameters. Here's an example of a full program using it:
//p_var1[] - is an array of values
//p_size - is the size of array
int fnc(int p_var1[], int p_size)
{
int max_value;
for (int i = 0; i < p_size; i++)
{
if (max_value > p_var1[i])
{
max_value = p_var[i];
}
}
return max_value;
}
int main() {
int lst[5] = {10, 2, 6, 4, 8};
int max = fnc(lst, 5); // max = 10
return 0;
}
Upvotes: 2