Thread: function returns int *

  1. #1
    Registered User
    Join Date
    Sep 2001

    Question function returns int *

    I have problems with a function like this:


    int * where (void)
    int pos[2]={0,0};
    int i, j;
    for (i=0;i<12;i++)
    if (t[i][j]=='K')
    return pos;
    return pos;

    Borland c 3,1 compiler returns with the message :'warning:Function should return a value".
    What is the problem with this function ?

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    pos is local to your function but you are returning a pointer to it, so the pointer will point to a variable that is no longer in scope. You should either make the variable global, pass the variable into the function or allocate memory on the heap to store it from within the function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Working with random like dice
    By SebastionV3 in forum C++ Programming
    Replies: 10
    Last Post: 05-26-2006, 09:16 PM
  5. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 06:05 PM