Pointer to local variable

Posted by Radek Šimko on Stack Overflow See other posts from Stack Overflow or by Radek Šimko
Published on 2010-12-31T13:27:55Z Indexed on 2010/12/31 13:54 UTC
Read the original article Hit count: 256

Filed under:
|
|
|

May I have any acces to local variable in different function? If may, how?

void replaceNumberAndPrint(int array[3]) {
    printf("%i\n", array[1]);
    printf("%i\n", array[1]);
}

int * getArray() {
    int myArray[3] = {4, 65, 23};
    return myArray;
}

int main() {
    replaceNumberAndPrint(getArray());
}

The output of the piece of code above:

65
4202656

What am i doing wrong? What the "4202656" means??

Do I have to copy the whole array in the replaceNumberAndPrint() function to be able to access to it more than first times?

© Stack Overflow or respective owner

Related posts about c++

Related posts about c