HI,

I am still new in this language. i would like some help. i need to write a program that finds an avarage marks of "y" students by rerunning and terminating the program. i need this in a 2 dimensional array to store a roll number and marks of the "y" number of the students. it should include array of pointers, call by value and call by reference.

my main problem is to combine all these in one program.
give me the codes and an explanation on calling by value and reference.

your help will mean alot to me. thank you.

HI,

I am still new in this language. i would like some help. i need to write a program that finds an avarage marks of "y" students by rerunning and terminating the program. i need this in a 2 dimensional array to store a roll number and marks of the "y" number of the students. it should include array of pointers, call by value and call by reference.

my main problem is to combine all these in one program.
give me the codes and an explanation on calling by value and reference.

your help will mean alot to me. thank you.

As far as writing the code is concerned i'm sure you can do that on your own i can try and make you understand the concept of pass by value and reference in as simple terms as possible..

pass by value occurs when you pass the copy of entire object as a function argument. thus you will be creating an entirely new object and whatever changes you make to this new copy in your function will not affect the original object.

pass by reference occurs when you dont pass the actual object but only address of the object. Thus whatever chages you make to the object will change the actual object.

void
Base::MyFunc(int& val)    //pass by reference
{
	val = 10;
}

void
Base::MyFunc2(int val)    //pass by value
{
	val = 10;
}

int main()
{
   int val = 5;
   Base().MyFunc(val);
   cout << val << endl;  // val is passed by ref and hence the value gets changed

   int val2 = 5;
   Base().MyFunc2(val2);
   cout << val2 << endl; //val is passed by value hence remains unchanged
}

output
10
5

here the first function MyFunc takes parameter val by reference, hence cout will give output as 10, the original object got changed, howver the second method takes parameter as value and hence the second cout will still print 5!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.