Thread: function

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    21

    function

    Hi,

    i am just not sure whether the below way is valid and usable

    I have the following 2 functions :

    Code:
            int func1() 
            {
             }
    
    
           int func2()
           {
            }
    if i do the following , will it valid?

    Code:
            func1(func2());
    i know that this will work if scanf or printf is used. is it the same concepts?

    thks

  2. #2
    Registered User
    Join Date
    Jan 2006
    Posts
    63
    Code:
    #include <iostream>
    
    int function1(int func_return_value);
    int function2(int number);
    
    int main()
    {
    	
    	function1(function2(1));
    
    	return 0;
    }
    
    int function1(int func_return_value){
    
    	if(func_return_value == 0)
    		std::cout<< "Function 2's return value is 0" << std::endl;
    
    	if(func_return_value == 1)
    		std::cout<< "Function 2's return value is 1" << std::endl;
    
    	if(func_return_value > 1)
    		std::cout<< "Function 2's return value is 2" << std::endl;
    
    	return 0;
    }
    
    int function2(int number){
    
    	if(number == 0)
    		return 0;
    	if(number == 1)
    		return 1;
    
    	return 2;
    }
    There you go give that a shot.

  3. #3
    old man
    Join Date
    Dec 2005
    Posts
    90
    Quote Originally Posted by suzanne_lim
    if i do the following , will it valid?

    Code:
            func1(func2());
    All things being equal, func2() will execute and its return value will become the parameter for func1() ... this is very common.

    func2() must have a return value of the appropriate type, of course.

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    21
    Thanks guy...U saved me

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM