Welcome to the Webmaster Forum.
Results 1 to 2 of 2

Thread: void Functions

  1. #1
    Senior Member
    Join Date
    Jan 2014
    Location
    Banglore
    Posts
    249

    void Functions

    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.

    #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

  2. #2
    Senior Member
    Join Date
    Jan 2016
    Location
    Mumbai
    Posts
    476

    Re: void Functions

    Great info thanks for sharing.

 

 

Similar Threads

  1. What is the difference between the functions UNLINK and UNSET?
    By david ho in forum Coding & Programming
    Replies: 6
    Last Post: 07-01-2016, 07:49 AM
  2. Aggregate User Defined Functions
    By chinmay.sahoo in forum PHP
    Replies: 0
    Last Post: 05-23-2016, 08:39 AM
  3. What are Spiders, Robots and Crawlers and what are their functions?
    By Keerti in forum Search Engine Optimization (SEO)
    Replies: 4
    Last Post: 04-15-2016, 07:57 AM
  4. How would you use the functions sin(), pow(), sqrt()?
    By chinmay.sahoo in forum Coding & Programming
    Replies: 2
    Last Post: 04-11-2016, 08:39 AM
  5. What are Spiders, Robots and Crawlers and what are their functions?
    By deepsharma01 in forum Search Engine Optimization (SEO)
    Replies: 3
    Last Post: 10-01-2015, 01:46 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Back to top

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73