+ 3

Please explain what is a void? And how to use it? Please

28th Jul 2017, 10:13 AM
Yasir Faiz Ahmed
Yasir Faiz Ahmed - avatar
2 Answers
+ 9
"Void is nothingness. The truth of life, the external materialisation of the heart." --- Yes, void is indeed nothingness. In C++, void functions are functions which do not return anything back to the caller. (functions which have no return value) This may seem to be redundant at first, but void functions have a lot of usages. E.g. void hello() { std::cout << "Hello!"; } This is a void function which sole purpose is to print a string literal. No return value is required. Variables can also be passed to the void function via reference to be manipulated. E.g. void swap(int& a, int& b) { a = a + b; b = a - b; a = a - b; // variables manipulated // no return value required }
28th Jul 2017, 10:37 AM
Hatsy Rei
Hatsy Rei - avatar
+ 7
then there is void pointers int value = 1; string another = "boo"; void* ptr; ptr = &value; ptr = &another; http://www.learncpp.com/cpp-tutorial/613-void-pointers/
28th Jul 2017, 11:17 AM
jay
jay - avatar