"num" should not be a pointer. I changed your code to the one below, works for me (note it requires SM 2.0 or newer for printf):
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include "stdio.h"
#include "stdlib.h"
__constant__ int num;
__global__ void kernel() {
printf("\n num=%d\n", num);
if (num == 5)
printf("\n num is equal 5");
else
printf("\n num is not equal 5");
}
int main() {
cudaError_t err;
int x;
printf("\n\nPlease enter x:");
scanf("%d", &x);
err = cudaMemcpyToSymbol(num, &x, sizeof(int) * 1);
if (err != cudaSuccess) {
printf("Error: %d\n", err);
return 1;
}
kernel<<<1, 1>>>();
err = cudaDeviceSynchronize();
if (err != cudaSuccess) {
printf("Error: %d\n", err);
return 1;
}
return 0;
}