From a8801255c048132d2ca8accec2d6afa950a1de18 Mon Sep 17 00:00:00 2001 From: athreya2013 <40118072+athreya2013@users.noreply.github.com> Date: Sat, 5 Jan 2019 22:14:52 +0530 Subject: [PATCH] Information regarding pointers in array (#30573) * Information regarding pointers in array Added more Information in 2D arrays that we can declare the array without no_of_rows and usage of pointers in array element accessing * fix: formatting/spelling * fix: formatting, matched variable name to other examples --- guide/english/c/arrays/index.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/guide/english/c/arrays/index.md b/guide/english/c/arrays/index.md index 4f3cbc9fea..91c8d5a3b0 100644 --- a/guide/english/c/arrays/index.md +++ b/guide/english/c/arrays/index.md @@ -66,6 +66,7 @@ If you want to create an array with all the elements as `0`. ```C int var = arr[0]; ``` + Here an int is created called `var`, and it is initialized to the 0th element of arr. **Very importart to note** that in C, indexes start at zero as opposed to 1. This means that to access the first element, the index (between the brackets) is 0, to access the second element, the index is 1 etc. In this example `var` is going to store the value `1`. @@ -105,6 +106,12 @@ Two-dimensional arrays are common and can be initialized using the following syn int arr[2][5] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; ``` +We can also declare the two-dimensional array without giving the number of rows, but number of columns is a must. + +example: `int arr[][5]` - here the number of rows are variable + +To access the element `arr[i][j]` we can also denote it by `*(arr+i*n+j)`,where `n` is the number of columns + It can be difficult to visualize a 2-dimensional array using the above syntax so developers often use optional, nested brackets to clarify the structure of the array. This is also a valid way to initialize a 2-dimensional array. ```C int arr[2][5] = {