title: assigning values to variables in GPU memory in CUDA
body: <p>My question is can I explicitly assign values to variables that are sitting in GPU memory or do I always have to use cudaMemcpy?</p>
  
  <p>for example can i do this:</p>
  
  <pre><code>int * a;
  cudaMalloc((void**)&amp;a, sizeof(int));
  *a = 5;
  </code></pre>
  
  <p>or can i only do:</p>
  
  <pre><code>int * dev_a;
  int a = 5;
  cudaMalloc((void**)&amp;dev_a, sizeof(int));
  cudaMemcpy(dev_a, &amp;a, sizeof(int) , cudaMemcpyHostToDevice);
  </code></pre>