I am really struggling to see why the following code will not work and causes a segfault.
Car *newCar;
Car *oldCar;
newCar->engineSize = 1500;
memcpy(newCar, oldCar, sizeof(Car));
I am obviously missing something very fundamental here but don’t know what it is. Any help would be greatly appreciated.
Thanks
You need to allocate memory for it.
If you don’t need to use the pointer elsewhere, you could use stack-allocation.