G
grocery_stocker
If go like the following:
#include <stdlib.h>
void *test_me(int a) {
int *m;
m = &a;
}
main(void){
char *j;
j = test_me(1);
printf("The value of j is : %x", *j);
}
I get:
The value of j is : 1
However, when I add malloc()
#include <stdlib.h>
void *test_me(int a) {
int *m;
m = &a;
}
main(void){
char *p;
char *j;
p = malloc(10);
j = test_me(1);
printf("The value of p is : %x", *p);
printf("The value of j is : %x", *j);
free(p);
}
I get the following:
The value of p is : 0
The value of j is: ffffffc4
Why does p become zero?
#include <stdlib.h>
void *test_me(int a) {
int *m;
m = &a;
}
main(void){
char *j;
j = test_me(1);
printf("The value of j is : %x", *j);
}
I get:
The value of j is : 1
However, when I add malloc()
#include <stdlib.h>
void *test_me(int a) {
int *m;
m = &a;
}
main(void){
char *p;
char *j;
p = malloc(10);
j = test_me(1);
printf("The value of p is : %x", *p);
printf("The value of j is : %x", *j);
free(p);
}
I get the following:
The value of p is : 0
The value of j is: ffffffc4
Why does p become zero?