Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

I AM NOT GOOD AT PROGRAM

Name: Anonymous 2009-10-31 17:31


#include <iostream>

int *modi (int *array)
{
    int *start = array;
   
    for (int x = 0; x < 10; x++)
    {
        array[x] = x;
    }
   
    return start;
}
   

int main ()
{
    int arr[10] = { 0 };
   
    for (int x = 0; x < 10; x++)
    {
        std::cout << arr[x];
    }
   
    modi (arr);
   
    for (int x = 0; x < 10; x++)
    {
        std::cout << arr[x];
    }
   
    std::cout << "niggers";
   
    return 0;
}


So I just wrote this. I know what it does, and I know that it works, but I don't know how it works.
int *start dereferences, but the value is undefined, and oh god how the fuck did I make this compile.
Please help.

Name: Anonymous 2009-10-31 21:26

>>1
I know what it does
I'm pretty sure you don't.

int *start dereferences
No, it doesn't. It declares start as a pointer to integer, with the same value as array itself. If you wanted to dereference anything, you should have written:


int start = *array;


Additionally, the first element of arr is in fact defined as you initialized arr with { 0 }; .

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List