can somebody tell me the meaning of this "The function should use const reference parameter that allows read-only access to reference parameter without wasting space, speed."
Actually the question is;
Write a program that uses a structure named StudentData to store the following information about a student:
ID
name
major
year enrolled in school
GPA
The program should create two StudentData variables, store values in their members, and pass each one, in turn, to a function that displays the information about the student in a clearly formatted manner. The function should use const reference parameter that allows read-only access to reference parameter without wasting space, speed.
Although I have done the coding, i just want to know have i done it correct.
Here is the signature of a function accepting a parameter:
By value: int foo(SomeType);
By reference: int foo(SomeType&);
By constant reference: int foo(SomeType const&);
You're expected to use the third technique. You can do the same thing for whatever SomeType is (except if SomeType is a reference type, in which case the references collapse--but don't worry about that) and for all the combinations of const and volatile applied to SomeType.