Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / need help with "void"

Author
Message
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 4th Jul 2010 21:38
I use voids in my programes.. like this:

void something () {content}

but when i see it in other people's code i see:

void something (int x, int y,...) {}

What does that do? and why is there "()" at the end of some commands in the first place?

I just love the smell of code in the morning...
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 4th Jul 2010 21:58
"()" denotes a function call. Inside the parenthesis can lie parameters with which you pass variables/values to the function that you are calling.



http://cplusplus.com/doc/tutorial/functions/
http://cplusplus.com/doc/tutorial/functions2/

“C++ : Where friends have access to your private members.”
-Gavin Russell Baker
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 4th Jul 2010 22:14
Thank you

I just love the smell of code in the morning...
Kryogenik
15
Years of Service
User Offline
Joined: 22nd Sep 2009
Location: Heidelberg, Germany
Posted: 4th Jul 2010 22:35
Do you mean void or the parentheses? If you mean the parentheses, then its a function call, or you can use it to separate expressions so order of operations doesn't change the way you want it to evaluate. I.E. if you had the expression 5 + 6 * 2 + 4, order of operations would make it 5 + 12 + 4 and mess it up (unless you want it do it like that). Using parentheses would make them separate: (5 + 6) * (2 + 4) and it would come out as 66, the way you would expect. If you mean void, that's the type of variable the function returns. Void denotes no value is returned. If you wanted an int to be returned from the function, you'd use int, and if you wanted a double, you'd put double before the function etc. In case you don't know, you'd use the return command and put the number (or expression) you want to return. You can also use this command with no value to break from the function (don't take that as gospel, but I'm pretty sure).

cout<<"I'm learning C++, and this is all I know \n"

Login to post a reply

Server time is: 2024-11-19 20:24:33
Your offset time is: 2024-11-19 20:24:33