Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should just pass pointers (since if you pass arrays to a function, what;'s really passed is a pointer anyway). Also, you can't return an array - again, just return a pointer:</p> <pre><code>int* _addInts(int *x, int *y); // equivalent to: int* _addInts(int x[], int y[]); </code></pre> <p>You'll also have to arrange for the number of elements to be passed in somehow. Something like the following might work for you:</p> <pre><code>int* _addInts(int *x, int *y, size_t count); </code></pre> <p>Also - do <em>not</em> fall into the trap of trying to use <code>sizeof</code> on array parameters, since they're really pointers in C:</p> <pre><code>int* _addInts(int x[], int y[]) { // the following will always print the size of a pointer (probably // 4 or 8): printf( "sizeof x: %u, sizeof y: %u\n", sizeof(x), sizeof(y)); } </code></pre> <p>That's one reason why I'd prefer having the parameters be declared as pointers rather than arrays - because they really will be pointers.</p> <p>See <a href="https://stackoverflow.com/questions/1598773/is-there-a-standard-function-in-c-that-would-return-the-length-of-an-array/1598827#1598827">Is there a standard function in C that would return the length of an array?</a> for a macro that will return the number of elements in an array for actual arrays and will cause a compiler error (on most compilers) much of the time when you try to use it on pointers.</p> <p>If your compiler is GCC, you can use Linux's trick: <a href="https://stackoverflow.com/questions/4415530/equivalents-to-msvcs-countof-in-other-compilers/4415628#4415628">Equivalents to MSVC&#39;s _countof in other compilers?</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload