A newbie question, regarding gpu crashes while using CUDA through VC (Windows)

I just managed to setup CUDA and integrating it with VC, trying to get the hang of cudaMalloc and some basic functions, using that simple code:
void test2() {
int *a, *b;
//as far as I understood, cudaMalloc requires a pointer to the memory’s loc, hence the &a, &b
cudaMalloc(&a, sizeof(int));
cudaMalloc(&b, sizeof(int));
*a = 2;
*b = 3;

printf("%d\n%d\n", *a, *b);

While executing that, my system crashed (the infamous “sorry for the inconvenience” screen)
I’m currently working with i5 cpu and 970gtx gpu so I don’t think it’s a compatibility issue, my worst fear is that it is somehow damaging my hardware. I’d be glad to get some explanation.
I know I could’ve just written int *a = new int(2);, but I was just trying that option as well.
I took my chances and went for another go using the “just in time” debugger, and saw that the run-time error was writing access violation, and indeed the windows crash error was “irql less or equal”.
I guess that for some reason I don’t have permission to access the GPU’s buffers, any quick fix?

You’ll need to learn more about CUDA programming. A basic principle is that device pointers shouldn’t be dereferenced in host code.

This creates a device pointer:

cudaMalloc(&a, sizeof(int));

From that point forward, you should only dereference that pointer in device code.

This is host code trying to dereference that pointer:

*a = 2;

It’s not damaging your hardware, it’s just an illegal thing to do, and so windows terminates the process.