Can someone explain the void function in c++?
Basically it means "nothing" or "no type" There are 3 basic ways that void is used: Function argument: int myFunc(void) -- the function takes nothing. Function return value: void myFunc(int) -- the function returns nothing Generic data pointer: void* data -- 'data' is a pointer to data of unknown type, and cannot be dereferenced. As simple as that.
Generally you do not use `type function_name(void);` in c++, but that is popular in c. The main thing void is used rfor in c++ is the second thing siddhantk3m8 noted, making a function that returns nothing. Note: This just means trurn via the return statment. Pass by reference can still be used. The biggest mistake with void is using it on the main function. All of this has to do with standards. http://www.parashift.com/c%2B%2B-faq-lite/newbie.html#faq-29.3
Join our real-time social learning platform and learn together with your friends!