I am learning about the usage of stack and I notice that they are used differently, or apparently so, in C and Java. For example, the code below written in C will not work because it will clobber "name"

```
char* getName(){
char name[32];
scanf( "%s",name);
return name;
}

int main (int argc, char *argv[]){
char *myName = getName();

printf("%s", myName);
}    

```

However, if I write something similar in Java, it works just fine:

```
public static String getName(){
String name = "A name";
return name ; 

}

static void main(String[] args){
String name = getName();
System.out.print(name);
}

```

I want to know why. Why does the stack not clobber in Java but does so in C ?