action-adventure games android टाइम बाजार पेनल srm students portal pubg lite official santa tracker google psammoma bodies mnemonic ऑनलाइन क्रिकेट गेम pragmatic play xamarin ios फुल्का 150 ladli behna yojna.mp.gov.in who is telugu bigg boss 7 winner top fantasy apps rummy gold 51 bonus टाइम बाजार टाइम बाजार टाइम बाजार 777 charlie dog death time zone games sattamayka jhilmil colony lottoland winners india liobet bhoomi survey documents rush ludo controller hack unova stone ajker football khela milan night milan night milan night milan night ट्रिक-टेकिंग गेम 20000 hindi mein इंडिया कल्याण चार्ट games apk ward population bet 213 migration ka hindi arth indian bike driving quotes bedroom size in meters torrent tamil movie download satka tv telugu bigg boss 7 winner name महिला सुरक्षा natraj matka oceanofgamess भारत सबसे अच्छा नाम sport baji old paytm download carrom club paytm cash apk download bed last date of admission 2023 संगम लॉटरी का रिजल्ट mohini matka aam ka para pdf is stock market gambling Multidimensional array | Tech Blog https://www.technhit.in Technology for Mankind Thu, 01 Dec 2016 11:23:14 +0000 en-US hourly 1 https://wordpress.org/?v=5.5.3 https://i1.wp.com/www.technhit.in/wp-content/uploads/2020/10/cropped-LOGO-update2.png?fit=32%2C32&ssl=1 Multidimensional array | Tech Blog https://www.technhit.in 32 32 109949773 Using Arrays C Language with Example https://www.technhit.in/using-arrays-c-language-example/ https://www.technhit.in/using-arrays-c-language-example/#comments Sun, 21 Aug 2016 10:27:20 +0000 http://technhit.in/?p=324 In a single sentence, an Array is a container of the homogeneous data type. that can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same […]

The post Using Arrays C Language with Example appeared first on Tech Blog.

]]>
In a single sentence, an Array is a container of the homogeneous data type. that can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.

Instead of declaring individual variables, such as num0, num1, …, and num99, you declare one array variable such as numbers and use num[0], num[1], and …, num[99] to represent individual variables. A specific element in an array is accessed by an index.

All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.

Declaring Array:

 

array declearation

Subscripts and pointer arithmetic:

array[subscript] equivalent to *(array + (subscript))

Strange but true. Given earlier declaration of m, the expression 2[m] is legal!. Not only that it’s equivalent to :

*(2+m)

*(m+2)

m[2]

Initializing arrays:

By default, regular arrays of local scope (for example, those declared within a function) are left uninitialized. This means that none of its elements are set to any particular value; their contents are undetermined at the point the array is declared. A user can put element and execute during program execution.

But the elements in an array can be explicitly initialized to specific values when it is declared, by enclosing those initial values in braces {}. For example:

 int num[5]={10,5,17,4,8};

array exam5

Array Pocket index starts with 0 and last pocket index is array element -1. Assume that array element is n then  last pocket index is n-1.

The number of values between braces {} should not greater than the number of elements in the array. If its happens then value overrides from the first element of this array.  Assume that you have an array num[5]  with 5 elements. After that, you initialized  it with 7 values. num[5]={10,5,17,4,8,15,12}

 int num[5]={10,5,17,4,8,15,12};

First of all its grab array pockets as chronological order.

array exam6

But you still have two more values remain to be placed. The remain two values override the first and second pocket of the array. Finally its looks like bellow:

array exam7

If you initialized less element than declared size of the array. It’s ok the remaining pocket has 0 value by default.

 int num[5]={10,5,17};

array exam8

The initializer can even have no values, just the braces:

 int num [5] = { };

array exam9

When an initialization of values is provided for an array, C/C++ allows the possibility of leaving the square brackets empty[]. In this case, the compiler will assume automatically a size for the array that matches the number of values included between the braces {}:

 int num[]={10,5,17,4,8};

array exam13

Accessing the values of an array:

The values of any of the elements in an array can be accessed just like the value of a regular variable of the same type. The syntax is:

name[index]
Following the previous examples in which num had 5 elements and each of those elements was of type int, the name which can be used to refer to each element is the following:

array exam10

For example considering the following code segment. You are able to access its values from this array as follows:

  int num[5]={10,5,17,4,8};

array exam11

x=num[2];      // The value of x  is equal to 17

x=num[4];      // The value of x is equal to 8
 scanf("%d",&num[2]);
/* statement to insert value in the third element of array num[]. */

scanf("%d",&num[i]);
/* you can use a variable instead of number to insert value, in this case (i+1)th element of array num[]. Because array use zero(0) based index, the first element of array is num[0], second is num[1], ith is num[i-1] and (i+1)th is num[i]. */

printf("%d",num[0]);
/* statement to print first element of an array. */

printf("%d",num[i]);
/* statement to print (i+1)th element of an array. */

 

Array names and pointer variables, playing together:

arrays array exam2 array exam3 array exam4

 

Multidimensional arrays:

Multidimensional arrays can be described as “arrays of arrays”. It can be two dimensional, three dimensional and even more in deep. However, arrays more than three levels deep are hard to manage for most people. Generally, two-dimensional array we can imagine as a two-dimensional table and three-dimensional array can imagine as a cube of a two-dimensional table.

Declaring multidimensional array :

 int num[5][5];

array exam12

 int num[3][5][4];

 

 

image002

See:

In next tutorial, we learn execution of array its applications. it is very grateful to me if this tutorial is helpful for you. Thank you.

The post Using Arrays C Language with Example appeared first on Tech Blog.

]]>
https://www.technhit.in/using-arrays-c-language-example/feed/ 6 324