Thread: Question about function calling

  1. #1
    C/C++ homeyg's Avatar
    Join Date
    Nov 2004
    Location
    Louisiana, USA
    Posts
    209

    Question about function calling

    Lets say, you had a variable and you assigned a function to it, like so:

    Code:
    int variable = function(argument);
    If function(argument) returned a value (say int) and printed out a statement, would the statement be printed out if the function was assigned to a variable like the example?

    -Thanks for your time
    Last edited by homeyg; 12-17-2004 at 05:01 PM.

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Try it and see
    Code:
    #include <iostream>
    
    int function(int a)
    {
      
      std::cout<<a<<std::endl;
      return a + 3;
      
    }
    
    int main(void)
    {
      
      int mainA = function(10);
      std::cout<<mainA<<std::endl;
      std::cin.get();
      
      return 0;
      
    }
    Woop?

  3. #3
    C/C++ homeyg's Avatar
    Join Date
    Nov 2004
    Location
    Louisiana, USA
    Posts
    209
    Yes, I see now. Thanks.

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Its always good to try things out and tinker with them to see what happens. You learn alot that way . To explain what is happing you are still calling the function but the the varaible you create is only set to the return value of that function.
    Woop?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. function pointer question
    By andrea72 in forum C++ Programming
    Replies: 7
    Last Post: 12-11-2007, 06:25 AM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  5. I need help to compile this code...
    By wise_ron in forum C Programming
    Replies: 17
    Last Post: 05-07-2006, 12:22 PM