chinmay.sahoo
New member
As you have seen, functions that don’t return values are declared void. This prevents their use in an expression and helps head off accidental misuse. In the following example, the function print_vertical( ) prints its string argument vertically down the side of the screen. Since it returns no value, it is declared as void.
Since print_vertical( ) is declared as void, it cannot be used in an expression. For example, the following statement is wrong, and will not compile:
x = print_vertical("hello"); // Error
\#include <iostream>
using namespace std;
void print_vertical(char *str);
int main(int argc, char *argv[])
{
if(argc==2) print_vertical(argv[1]);
return 0;
}
void print_vertical(char *str)
{
while(*str)
cout << *str++ << '\n';
}
Since print_vertical( ) is declared as void, it cannot be used in an expression. For example, the following statement is wrong, and will not compile:
x = print_vertical("hello"); // Error