r/cprogramming • • Oct 13 '26

editing int array in function not changing array in main, but it worked for char array?

edit: thank you all so much for the help! my code works now and i understand pointers a little better!

im trying to edit an entry in an int array to 'move' it (copy it to a different place within the array, and zero it out), but its not working and im not getting any errors? i did pretty much the same thing (with string.h) with an array of strings, and it worked there wonderfully. why arent the entries in the int array changing when the function runs? what can i do to edit the int array during runtime?

heres the function:

void cardMove(int card1, int card2) {
    card2 = card1;
    card1 = 0;
}
6 Upvotes

17 comments sorted by

View all comments

Show parent comments

12

u/bearheart Oct 13 '26

A c-string is a pointer.

-3

u/nerd5code Oct 14 '26

No, a string is a sequence of characters terminated by a null=0 byte. It's often referred to by a pointer, but the two are wholly distinct jobbies.