Parameter???

I'm finding arguments and parameters difficult to distinguish, can someone help? Is this parameter? If not how do I turn it into one??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

#include <iostream>
using namespace std;

int* arrayExpander(int[], int);

int main()
{
	int array[] = { 0,1,4,8,9,10,12,54 };
	int size = 8;
	
	int *arrPtr = arrayExpander(array, size); //I think this is where I made a mistake? Argument?
	for (int i = 0; i < size * 2; i++)
	{
		cout << arrPtr[i] << endl;
	}

	return 0;
}
int* arrayExpander(int array[], int size)
{
	int* ExpandArray = new int[size * 2];
	for (int i = 0; i < size * 2; i++)
	{
		if (i < size)
		{
			ExpandArray[i] = array[i];
		}
		else
		{
			ExpandArray[i] = 0;
		}
		
	}

	return ExpandArray;
}
First in this content argument and parameter are referring to the same thing. In your function arrayExpander both array[] and size are arguments (or parameters) of that function.

The arguments are the values that you pass to the function.

1
2
// array and size are passed as argument to the arrayExpander function.
int *arrPtr = arrayExpander(array, size);

The parameters are the variables inside the function that will get the values from the arguments being passed to the function.

1
2
// The arrayExpander function has two parameters array and size.
int* arrayExpander(int array[], int size)
Parameters and arguments are the same thing.When a value is passed to the function it is known as argument but when received by the function it is known as parameter for instance,

void func( int i ) ///i is a parameter
{
///code here
}

int main( )
{
int i=90 ;
func( i ) ; /// i is an argument

cin.get() ;
return 0 ;
}

'i' is argument in the passing side but parameter in the receiving side.

Edited:
Last edited on
@Corecplusplus

I mentioned this at length in another post, but I will mention here again for the sake of others.

Your meanings of argument and parameter are incorrect, Peter87 is correct.

Also for the sake of others, regard the tutorial in the link with caution.
Topic archived. No new replies allowed.