Hey i was watching some stanford lectures on youtube and i like the bit about working with memory. So i figured i would try and do something like passing the address of an array to a function and manually going through the memory and overiding whats in the memory at a certain point to change the array, but im getting confused
i just wrote this quickly and isnt exactly the same code, but it was the same method i was using, i just want to understand how to pass an address then in a seperate function assign a new value to that address.Code:#include <stdio.h> int changearray(int *arr){ //pass the reference to the first element of array //*arr should now point to the first elemet of the array? //the above doesnt seem to be true but i thought thats what would happen? //move two elements down the array int *finaladdress = arr + sizeof(int)*4; //above im trying to assign finaladdress to point to the 4th element of the passed array //again this doesnt seem to be working i must be confused. //now i want to change the 4th element of the array finaladdress = 1; return 0; } int main(){ int arr[10]; changearray(&arr); return 0; }