---
title: QkQuantumRegister (v2.1)
description: API reference for QkQuantumRegister in qiskit-c v2.1
source: https://eu-de.quantum.cloud.ibm.com/docs/en/api/qiskit-c/2.1/qk-quantum-register
---

# QkQuantumRegister

```c
typedef struct QkQuantumRegister QkQuantumRegister
```

A common way to instantiate several bits at once is to create a register. A register is a named collection of bits. Creating a register enables giving a collection of bits a name which can be use as metadata around specific bits in a circuit. This name will also typically be preseserved when exporting the circuit to interchange languages.

You can create a register by calling `qk_quantum_register_new()`, for example:

```c
#include <qiskit.h>

QkQuantumRegister *qreg = qk_quantum_register_new(5, "my_qreg");
```

Which creates a new 5 qubit register named `"my_qreg"`.

Then to add the register to a circuit you use the `qk_circuit_add_quantum_register()` function:

```c
QkCircuit *qc = qk_circuit_new(0, 0);
qk_circuit_add_quantum_register(qc, qreg);
uint32_t num_qubits = qk_circuit_num_qubits(qc); // 5
```

While circuits track registers, the registers themselves impart almost no behavioral differences on circuits.

## Functions

### qk\_quantum\_register\_new

`QkQuantumRegister *qk_quantum_register_new(uint32_t num_qubits, const char *name)`

Construct a new owning quantum register with a given number of qubits and name

#### Example

```c
QkQuantumRegister *qr = qk_quantum_register_new(5, "five_qubits");
```

#### Safety

The `name` parameter must be a pointer to memory that contains a valid nul terminator at the end of the string. It also must be valid for reads of bytes up to and including the nul terminator.

**Parameters**

- **num\_qubits** – The number of qubits to create the register for
- **name** – The name string for the created register. The name must be comprised of valid UTF-8 characters.

**Returns**

A pointer to the created register

### qk\_quantum\_register\_free

`void qk_quantum_register_free(QkQuantumRegister *reg)`

Free a quantum register.

#### Example

```c
QkQuantumRegister *qr = qk_quantum_register_new(1024, "qreg");
qk_quantum_register_free(qr);
```

#### Safety

Behavior is undefined if `reg` is not either null or a valid pointer to a `QkQuantumRegister`.

**Parameters**

**reg** – A pointer to the register to free.
