Hello,

I've read this textbook like a-kezillion times, and i still can't understand why we use the '&' in void function.

can somebody please explain.
thanks.

ps : please don't give that lmgtfy.com thingy. it's annoying.

Recommended Answers

All 3 Replies

Please explain yourself better. Maybe post an example. To my knowledge & can be used as the address opereator, when declaring a reference variable and as a bit operator. I suspect you are trying to ask why are parameters sometimes passed to functions as references, but who knows.

if you are talking about this line

pv = &i

then this is used to assign to the pointer pv the address of the variable i. thus making the void pointer an int basically

if you are talking about

void Foo(int & bar) {}

then you are passing the variable by reference so that whatever happens to the variable inside the function it will be that when you get back to the calling function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.