-2

I want create a function and return two integers: i and c. How can i do this? Thanks in advance

a++ ;
 if(i == 288){
 a = 0 ;
 i-- ;
 b++ ;
 c++ ;
 } 
 if(c == 5000) {

 i = 0 ;
 c = 0 ;

 }
  if(a == 1 ){
   P2OUT = 0xFF ;
  a = 0 ;
  }
 if (b == 1){
 P2OUT= 0x00 ;
 b = 0 ; 

 }
5
  • Pack those integers into a struct and return it from the function. Otherwise you could pass those int variables by reference to the function Commented Mar 25, 2019 at 19:27
  • @ShadowRanger: Makes me wonder if that question should reopened. There are some good answers there. Commented Mar 25, 2019 at 19:29
  • 1
    The code you've posted isn't a function... Nor is it clear what you'd want to return. Commented Mar 25, 2019 at 19:29
  • 2
    @FredLarson: Weather Vane's duplicate is still open, and more specific (I agree the one I found is a little broad, since it's unclear if they want to return a variable number of homogeneous things or a fixed number of potentially heterogeneous things). Commented Mar 25, 2019 at 19:31
  • Example: div() returns 2 ints. Commented Mar 26, 2019 at 2:07

1 Answer 1

2
struct s1
{
    int a;
    int b;
    /* more */
}

struct s1 foo(/* ... */)
{
    struct s1 s;

    s.a = /* something */;
    s.b = /* something */;
    /* more */
    return s;
}

int foo1(int *a, int *b /*, .... */ )
{
    *a = /* something */;
    *b = /* something */;
    return /* something */;
}
Sign up to request clarification or add additional context in comments.

4 Comments

I'm confused as to how this was posted at all, given the question was closed as a duplicate two minutes beforehand... I thought SO rejected new answers as soon as the question was closed.
@ShadowRanger magic
@shadowranger I think P__J__ was writing an answer from a mobile phone.
@machine_1 wrong

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.