Thread: Quick question

  1. #1
    Unregistered
    Guest

    Quick question

    Is it legal to pass an assignment statement to a function?
    Ex:

    void f(int a, int b);

    int main (void)
    {
    int c = 2, d = 3;
    f(c=d*2, d = 3);
    }

    void f(int a, int b)
    {
    return a*b;
    }

    My compiler is all messed up so I can't test it right now.

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    223
    Even if you can I would not recommended unless you are trying to compete in the obsfucated code constest.
    zMan

  3. #3
    Unregistered
    Guest

    Re: Quick question

    Originally posted by Unregistered
    Is it legal to pass an assignment statement to a function?
    Ex:
    Code:
    void f(int a, int b);
    
    int main (void)
    {
    	int c = 2, d = 3;
    	f(c=d*2, d = 3);
    }
    
    void f(int a, int b)
    {
    	return a*b;
    }
    My compiler is all messed up so I can't test it right now.
    Here's what I found out. I would do it like this...
    f( d*2, 3 )

    But, if you insist on doing that, the first paramter a would receive (c = d * 2) which would be 12. Also, it would take d = 3 as the second, which would be 3. So I don't think you would get your desired results that way.
    it would be the same thing and would definitely work.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM