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

C Question

Name: Anonymous 2011-07-19 2:02

Im going to be taking Intro to C in the fall so I have decided to read up on the textbook and learn how to program before the semester starts. I'm having a little problem, here's the trouble maker:
    potr1 = &goodarray[0];

    potr2 = &goodarray;

for some reason potr2 gets assigned the value of the &goodarray[0]instead of the &goodarray itself.. I have verified this by printfing both of them and they come up the same number. Im using DevC++ and Im pretty sure I just need to find a better compiler, but am I doing something wrong?

Name: Argus !!14eWW2o34yaxKWG 2011-07-23 9:00


int main(int argc, const char * argv[])
{
     char array[10] = "fuck you!"; //a simple character array
     char *p_one, *p_two;              //two character pointers
    
     p_one = &array;      //(array)
     p_two = &array[2];   //(array+2)

     printf("%s\n", array);  //not useful to the discussion
     return 0;               //slower than void return.
}


>>1
yep, arrays are fancy addressing systems, your mistake is that you believe that the array is a pointer itself, and has some location in memory.  The fact is, however, that an array IS simply an address. therefore the statement:
potr2 = &goodarray;
Is simply you trying to get the address of an address.  Your compiler gave you a break by not raping you in the eye and telling you to kill yourself; but you were still being retarded.  The part that gets me is that you were so blindly confident that an array was a pointer that you started this thread.

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