Thread: indirection of int in a function call

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    62

    indirection of int in a function call

    Hi all,

    I utilized all of the function help I got before and I am close on this one:

    Code:
    #include <stdio.h>
    #include <math.h>
    #define NumElements 5
    
    int Square(int j)
    {
        j = j * j;
        return (j);
    }
    
    int SquareArray( int num, int value)
    {
        value = Square(value);
        return (value);
    }
    int SquareAgain (int num, int array[])
    {
        int i;
        for(i = 0; i < num; i++)
        {
            array[i] = Square(array[i]);
        }
        return (array);
    }
    
    int main(int argc, char** argv)
    {
        int array[NumElements] = { 1, 2, 3, 4, 5 };
        int i;
        int num;
        int value;
    
        printf( "array = ");
        for (i = 0; i < NumElements; i++)
        {
            printf( " &#37;d", array[i]);
        }
        printf( "  before squaring\n");
    
        num = i;
    
        printf( "array = ");
        for (i = 0; i < NumElements; i++)
        {        
            value = array[i];
            printf( " %d", SquareArray(num, value));
        }
        printf( "  after squaring\n");
    
        SquareAgain(num, array);
    
        printf( "array = ");
        for (i = 0; i < NumElements; i++)    {        
            
            printf( " %d", array[i]);
        }
        printf( "  after squaring\n");
    
        return ( 0 );
    }
    Compiles and runs with desired output but I get this warning:
    Warning 1 warning C4047: 'return' : 'int' differs in levels of indirection from 'int *' 24
    That's a new one on me.

    line 24 = return (array);
    Last edited by tikelele; 11-29-2007 at 12:18 PM.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    array is int[], while you return int.
    Return the same type.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    62
    thanks Elysia for the reply.

    so: return ( int array[] )

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    62
    er
    return (array[])

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No,
    Code:
    int[] SquareAgain (int num, int array[])
    The rest should be left as is.

  6. #6
    Registered User
    Join Date
    Oct 2007
    Posts
    62
    what a knucklehead I am!!

    Thanks.

  7. #7
    Registered User
    Join Date
    Oct 2007
    Posts
    62
    actually that did not solve it at all. It made it worse.

    I compiled it as is with VC++ and that is where I got the warning.

    I compiled same code with gcc and no warnings at all.

    Must be MS.

    Thanks E

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Well, I would use pointers, though, so I'm to an expert on [].

  9. #9
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Don't return anything at all. The array is being changed in place so what's the point?

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. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  3. Replies: 26
    Last Post: 11-30-2007, 03:51 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 06:05 PM