I am just trying to use malloc and the code runs fine but visual studios gives me issues with it. Is this how you're supposed to do these things or am I doing something wrong?
The warning shows up right on the line:
chadley->name = "chadley"
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int age;
char *name;
} Person;
int main()
{
Person bradley;
bradley.name = "bradley";
bradley.age = 2334444;
Person *chadley = malloc(sizeof(Person));
chadley->name = "chadley";
chadley->age = 234;
printf("Person object %s of age %d", chadley->name, chadley->age);
}
Error Code: Dereferencing NULL pointer 'chadley'