Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. what is the difference between ..?

what is the difference between ..?

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    krish_kumar
    wrote on last edited by
    #1

    Hiiii to all I wanna know the difference between the return(0); return 0; return; from a function call...... return(0) and return 0 is same or not ?? Thanking you -------------- :rolleyes: :rolleyes: :rolleyes:

    C M 2 Replies Last reply
    0
    • K krish_kumar

      Hiiii to all I wanna know the difference between the return(0); return 0; return; from a function call...... return(0) and return 0 is same or not ?? Thanking you -------------- :rolleyes: :rolleyes: :rolleyes:

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      krish_kumar wrote:

      return(0) and return 0 is same or not ??

      Yes, it is the same. The parenthesis are here just useless. But, there's a difference between return; and return 0;: the first one is used in a function that returns nothing (void) and the second in a function that returns something (here, probably an integer).

      Cédric Moonen Software developer
      Charting control [v3.0] OpenGL game tutorial in C++

      1 Reply Last reply
      0
      • K krish_kumar

        Hiiii to all I wanna know the difference between the return(0); return 0; return; from a function call...... return(0) and return 0 is same or not ?? Thanking you -------------- :rolleyes: :rolleyes: :rolleyes:

        M Offline
        M Offline
        molesworth
        wrote on last edited by
        #3

        krish_kumar wrote:

        return(0) and return 0 is same or not

        Yes, exactly the same. The addition of brackets makes no difference.

        krish_kumar wrote:

        return;

        This however is totally different, and only valid in a "void" function - i.e. one which doesn't return a result. The difference between them can be illustrated as :-

        int DoSomething_1(int val)
        {
        // some processing
        // ...

        return (0);  // has to return a value as it's an "int" function
        

        }

        void DoSomething_2(int val)
        {
        // some processing
        // ...

        return;  // must not return a value as it's a "void" function
        

        }

        Days spent at sea are not deducted from one's alloted span - Phoenician proverb

        R 1 Reply Last reply
        0
        • M molesworth

          krish_kumar wrote:

          return(0) and return 0 is same or not

          Yes, exactly the same. The addition of brackets makes no difference.

          krish_kumar wrote:

          return;

          This however is totally different, and only valid in a "void" function - i.e. one which doesn't return a result. The difference between them can be illustrated as :-

          int DoSomething_1(int val)
          {
          // some processing
          // ...

          return (0);  // has to return a value as it's an "int" function
          

          }

          void DoSomething_2(int val)
          {
          // some processing
          // ...

          return;  // must not return a value as it's a "void" function
          

          }

          Days spent at sea are not deducted from one's alloted span - Phoenician proverb

          R Offline
          R Offline
          Rozis
          wrote on last edited by
          #4

          molesworth wrote:

          void DoSomething_2(int val){ // some processing // ... return; // must not return a value as it's a "void" function}

          isn't it:

          molesworth wrote:

          void DoSomething_2(){ // some processing // ... return; // must not return a value as it's a "void" function}

          [Edit] sorry for the layout...

          G 1 Reply Last reply
          0
          • R Rozis

            molesworth wrote:

            void DoSomething_2(int val){ // some processing // ... return; // must not return a value as it's a "void" function}

            isn't it:

            molesworth wrote:

            void DoSomething_2(){ // some processing // ... return; // must not return a value as it's a "void" function}

            [Edit] sorry for the layout...

            G Offline
            G Offline
            Graham Shanks
            wrote on last edited by
            #5

            Er, no. A "void" function describes what it returns, rather than the number of parameters it has.

            Graham Librarians rule, Ook!

            M 1 Reply Last reply
            0
            • G Graham Shanks

              Er, no. A "void" function describes what it returns, rather than the number of parameters it has.

              Graham Librarians rule, Ook!

              M Offline
              M Offline
              molesworth
              wrote on last edited by
              #6

              Thanks Graham, I was just about to say that... :)

              Days spent at sea are not deducted from one's alloted span - Phoenician proverb

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups