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

# QkObsTerm

This is a group of functions for interacting with an opaque (Rust-space) SparseTerm instance.

## Data types

### QkObsTerm

`struct QkObsTerm`

A term in a `QkObs`.

This contains the coefficient (`coeff`), the number of qubits of the observable (`num_qubits`) and pointers to the `bit_terms` and `indices` arrays, which have length `len`. It’s the responsibility of the user that the data is coherent, see also the below section on safety.

#### Safety

- `bit_terms` must be a non-null, aligned pointer to `len` elements of type `QkBitTerm`.
- `indices` must be a non-null, aligned pointer to `len` elements of type `uint32_t`.

#### QkComplex64 coeff

The coefficient of the observable term.

#### uintptr\_t len

Length of the `bit_terms` and `indices` arrays.

#### QkBitTerm \*bit\_terms

A non-null, aligned pointer to `len` elements of type `QkBitTerm`.

#### uint32\_t \*indices

A non-null, aligned pointer to `len` elements of type `uint32_t`.

#### uint32\_t num\_qubits

The number of qubits the observable term is defined on.

## Functions

### qk\_obsterm\_str

`char *qk_obsterm_str(const QkObsTerm *term)`

Return a string representation of the sparse term.

#### Example

```c
QkObs *obs = qk_obs_identity(100);
QkObsTerm term;
qk_obs_term(obs, 0, &term);
char *string = qk_obsterm_str(&term);
qk_str_free(string);
```

#### Safety

Behavior is undefined `term` is not a valid, non-null pointer to a `QkObsTerm`.

The string must not be freed with the normal C free, you must use `qk_str_free` to free the memory consumed by the String. Not calling `qk_str_free` will lead to a memory leak.

Do not change the length of the string after it’s returned, although values can be mutated.

**Parameters**

**term** – A pointer to the term.

**Returns**

The function exit code. This is `>0` if reading the term failed.
