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

Thread: void Functions

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

    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
    562

    Re: void Functions

    Great info thanks for sharing.

  3. #3
    Senior Member
    Join Date
    Jan 2016
    Location
    Mumbai
    Posts
    448

    Re: void Functions

    Very nice and good post 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, 06:49 AM
  2. Aggregate User Defined Functions
    By chinmay.sahoo in forum PHP
    Replies: 0
    Last Post: 05-23-2016, 07: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, 06: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, 07: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, 12: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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143