So I'm trying to change the value at x[2] from 0 to 8 using a method, the way I have this isn't working. How can I do this? I tried searching around but came to no avail.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void changevar(int* x){
int* y;
y = &x[2];
y = 8;
}
int main(int argc, char** argv){
int* c;
c = (int*) malloc(sizeof(int));
printf("here %d\n", c[2]);
changevar(&c);
printf("here %d\n", c[2]);
free(c);
}
EDIT: I'm new to pointers