# Z gate (CUDA-Q) [[z-gate|Z gate]] implementation using CUDA-Q. The Z gate applied to $\lvert 0\rangle$ is invisible at measurement (it leaves $\lvert 0\rangle$ unchanged), so this example prepares $\lvert +\rangle$ first, applies Z, then rotates back to the computational basis to confirm the phase flip. ```cpp // Compile: nvq++ main.cpp -o main // Run: ./main #include struct kernel { __qpu__ void operator()() { cudaq::qubit q; h(q); // |0> -> |+> z(q); // |+> -> |-> h(q); // rotate back to computational basis: |-> -> |1> mz(q); } }; int main() { auto counts = cudaq::sample(kernel{}); counts.dump(); // 100% |1>, confirming the phase flip } ```