Thread: c program-Return of two values from a global function.

  1. #1
    Registered User
    Join Date
    Mar 2013
    Location
    south africa
    Posts
    7

    c program-Return of two values from a global function.

    Please tell me if this is possible.

    Code:
    return (numberOfKegs && numberOfCases);

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Either
    - create a structure with 2 members, and return that struct.

    - pass pointers to where you want numberOfKegs and numberOfCases stored.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Is it possible?
    Yes.

    Does it do what you want?
    No.

    This will return 0 or 1, depending on the logical operation inside the parenthesis. Remember, that everything except zero is true!

    What you need is to pass these two variables as arguments by reference in your function. (other solutions too, but this is what you should do in my opinion).

    //Since parenthesis is a Greek word, I am little confused here. How do you write parenthesis in plural? Or this is plural? :P
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by std10093
    //Since parenthesis is a Greek word, I am little confused here. How do you write parenthesis in plural? Or this is plural? :P
    In this context, "parenthesis" is an English word of Greek origin. Its plural is "parentheses".
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Thank you Laserlight
    Well the Greek word is παρένθεση, that's why I said Greek word, but you are right
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to return 2 values upon calling a function
    By David_Baratheon in forum C Programming
    Replies: 1
    Last Post: 05-10-2012, 10:05 AM
  2. Having a function return three values
    By alanb in forum C++ Programming
    Replies: 12
    Last Post: 09-02-2009, 08:51 AM
  3. function return values
    By ashok449 in forum C Programming
    Replies: 10
    Last Post: 12-21-2007, 02:57 AM
  4. can a function return 2 values?
    By panfilero in forum C Programming
    Replies: 2
    Last Post: 09-27-2005, 02:35 AM
  5. Can objects contain/return values like a function?
    By Panopticon in forum C++ Programming
    Replies: 3
    Last Post: 01-22-2003, 07:44 PM