Suppose we have two functions one takes a pointer to int as argument and the other takes pointer to char. We have two variables in main an int variable and a string. Like this:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void Change(char* a);
void ChangeInt(int* z);
int main()
{
char name[80] = "David";
printf("name = %s\n", name);
Change(name);
printf("name = %s\n", name);
int x = 7;
int *y = &x;
printf("x = %d\n", x);
ChangeInt(y);
printf("x = %d\n", x);
}
void Change(char *a)
{
a = "Chris";
printf("a = %s\n", a);
}
void ChangeInt(int *z)
{
*z = 1337;
printf("*z = %d\n", *z);
}
I'am aware that the string literal get's lost after Change stops but why does it work for an integer? What's the difference in memory?