# Accessing matrix elements

**URL:** https://community.freefem.org/t/accessing-matrix-elements/981
**Category:** General Discussion
**Created:** [May 17, 2021, 11:52pm UTC](https://community.freefem.org/t/accessing-matrix-elements/981 "2021-05-17T23:52:02Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![amtravco](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@amtravco](https://community.freefem.org/u/amtravco)
#### Post date: [May 17, 2021, 11:52pm UTC](https://community.freefem.org/t/accessing-matrix-elements/981/1 "2021-05-17T23:52:02Z")

</div>

Two simple questions. Suppose I have a matrix created as

matrix C =  
[[1, 2, 3],  
[2, 4, 0],  
[8, 1, 9]];

How can I access individual elements of this matrix? I have tried the obvious C[1][2] = 5 but this syntax is not allowed.

Also, how would I create a matrix without needing to specify its initial elements, as was done for C above? Something like “real[int][int] D(20, 20)”, although again this is not correct.

---

<div class="post-metadata">

### Author: ![amtravco](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@amtravco](https://community.freefem.org/u/amtravco)
#### Post date: [May 18, 2021, 12:02am UTC](https://community.freefem.org/t/accessing-matrix-elements/981/2 "2021-05-18T00:02:58Z")

</div>

OK, I figured it out. The syntax is

```
   real[int, int] A(3, 3);

```

to create an array and

```
   A(1,2) = 7;

```

to access an element.
