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-11-01 15:02

Fixed OP's code.

#include <stdio.h>

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

int main()
{
    int arr[10] = { 0 };
    for (int i = 0; i < 10; ++i)
        printf("%d", arr[i]);

    modi(arr);
    for (int i = 0; i < 10; ++i)
        printf("%d", arr[i]);

    printf("people of African descent");
    return 0;
}

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