---
title: QkObsTerm (latest version)
description: API reference for QkObsTerm in the latest version of qiskit-c
source: https://quantum.cloud.ibm.com/docs/en/api/qiskit-c/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.

#### size\_t len

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

#### QkBitTerm \*bit\_terms

An aligned pointer to `len` elements of type `QkBitTerm`. This can be `NULL` if and only if `len` is 0.

#### uint32\_t \*indices

An aligned pointer to `len` elements of type `uint32_t`. This can be `NULL` if and only if `len` is 0.

#### 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);
qk_obs_free(obs);
```

#### 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**

A pointer to a nul-terminated char array of the string representation for `term`
