1.

C++ lets you pass a structure by value and it lets you pass the address of a structure. If sample is a structure variable, how would you pass it by value? How would you pass its address? Which method do you think is better?

Answer»

If we assume structure variable name as sample and function name as sample_function() then:

Pass a structure by valuePass a structure by address 
struct SAMPLE sample; sample_function(sample);
void sample_function(struct SAMPLE sample
 
:
 :
}
struct SAMPLE sample;

sample_function(&sample);
void sample_function(struct SAMPLE *sample)
{
:
:
}

Both the method have their own importance, so as per the program requirement we can use any of them.



Discussion

No Comment Found

Related InterviewSolutions