| | |
New To C++, Need Some Help On The Follwing Program(call By Vallue And Reference?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2007
Posts: 5
Reputation:
Solved Threads: 0
New To C++, Need Some Help On The Follwing Program(call By Vallue And Reference?
0
#1 Jan 24th, 2008
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.
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.
Re: New To C++, Need Some Help On The Follwing Program(call By Vallue And Reference?
0
#2 Jan 24th, 2008
•
•
•
•
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.
C++ Syntax (Toggle Plain Text)
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!!!
![]() |
Other Threads in the C++ Forum
- Previous Thread: Deleting In Linked List..
- Next Thread: Problem in stripping a particular substring from a string
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





