Why & is used before parameter?

0 Jessie York · April 10, 2015
Hello,

In C++ video 48, there is an & before the object variable name.

https://github.com/buckyroberts/Source-Code-from-Tutorials/blob/master/C%2B%2B/48_cppBeginners.cpp

void stinkysFriend(StankFist &sfo)


I do not understand why & is needed before the object name. Should not it be simply without an & as:


void stinkysFriend(StankFist sfo)

or more preferably with an asterisks before the object name as if we are passing a pointer:

void stinkysFriend(StankFist *sfo)

Could you clear it for me please?

Cheers

Post a Reply

Replies

Oldest  Newest  Rating
0 Jessie York · April 11, 2015
OK Thanks Gesu for your help. Much appreciated.
0 Jessie York · April 11, 2015
Thanks Gesu for your explanation.

One more thing. Why & is used rather than *? Should not it be as

void stinkysFriend(StankFist *sfo)


if we need to pass the pointer?
  • 1

C++

107,107 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator