(CUDA C) Why is it not printing out the value copied from device memory?
<p>I'm learning CUDA right now through the training slides provided by NVIDIA. They have a sample program that shows how you could add two integers. The code is below:</p>

<pre><code>#include &lt;stdio.h&gt;

__global__ void add(int *a, int *b, int *c) {
    *c = *a+*b;
}

int main(void) {
    int a, b, c;        // Host copies of a, b, c
    int *d_a, *d_b, *d_c;   // Device copies of a, b, c
    size_t size = sizeof(int);

    //Allocate space for device copies of a, b, c
    cudaMalloc((void**)&amp;d_a, size);
    cudaMalloc((void**)&amp;d_b, size);
    cudaMalloc((void**)&amp;d_c, size);

    //Setup input values
    a = 2;
    b = 7;
    c = -3;

    //Copy inputs to device
    cudaMemcpy(d_a, &amp;a, size, cudaMemcpyHostToDevice);
    cudaMemcpy(d_b, &amp;b, size, cudaMemcpyHostToDevice);

    //Launch add() kernel on GPU
    add&lt;&lt;&lt;1,1&gt;&gt;&gt;(d_a, d_b, d_c);

    //Copy result back to host
    cudaMemcpy(&amp;c, d_c, size, cudaMemcpyDeviceToHost);

    //Cleanup
    cudaFree(d_a); cudaFree(d_b); cudaFree(d_c);

    printf("For a = %d, b = %d, we get a + b = %d\n", a, b, c);

    return 0;
}
</code></pre>

<p>But when I run the program, the output is:
"For a = 2, b = 7, we get a + b = -3"</p>

<p>meaning that the value of c was unchanged!</p>

<p>What am I doing wrong?</p>