Monday, May 24, 2010

C++ QUESTIONS consider the function prototype?

consider the function prototype below





bool max_of_List(float List[],int size_of_List,int *where);





Judge each of these arguments whether it is passing-by-value,passing-by-address,or passing-by-reference? Why?

C++ QUESTIONS consider the function prototype?
that sounds like a exam question...uhmm I'll get you started.





List = reference, is an array, ALL arrays in C++ are passed as reference


size = value, is the size of the array, not meant to be modified and there is no %26amp; next to it, so it's value...





where = ..... I'll tell you, it's a pointer to an int...what do you think it is ?





there you go...
Reply:1st parameter pass by reference


2nd pass byvalue


3rd pass by reference
Reply:First of all u have no pass by refernce type arg in this prototype





As far as i infer i think that this function should get a list of float values as first arg, the size of this list as second arg and the third arg is used to send the position of max number to the calling function





1. the first arg is pass by address since arrays implicitly pass addresses


2.The second one is obviously normal pass by value


3.The third one is also pass by address as u recieve it using a pointer the calling function should definetly pass address


by passing the variable with '%26amp;' qualifier.





Ha-p Coding..


No comments:

Post a Comment