{"id":959,"date":"2023-12-07T17:54:53","date_gmt":"2023-12-07T17:54:53","guid":{"rendered":"https:\/\/thelearnify.in\/?p=959"},"modified":"2023-12-07T17:54:53","modified_gmt":"2023-12-07T17:54:53","slug":"introduction-to-arrays","status":"publish","type":"post","link":"https:\/\/thelearnify.in\/introduction-to-arrays\/","title":{"rendered":"Introduction to Arrays"},"content":{"rendered":"

Introduction of Arrays<\/h3>\n

C Programming<\/a> \u092e\u0947\u0902 Arrays<\/a>, Element \u0915\u093e \u090f\u0915 Collection \u0939\u094b\u0924\u093e \u0939\u0948| \u091c\u093f\u0938\u092e\u0947 Same Data Type \u0915\u0947 Element \u090f\u0915 Variable Name \u092e\u0947\u0902 Grouped \u0939\u094b\u0924\u0947 \u0939\u0948\u0964 \u0907\u0928 Element \u0915\u094b Contiguous Memory Location \u092e\u0947\u0902 Store \u0915\u093f\u092f\u093e \u091c\u093e\u0924\u093e \u0939\u0948, \u091c\u093f\u0938\u0938\u0947 \u0907\u0928\u094d\u0939\u0947\u0902 Access \u0914\u0930 Manipulate \u0915\u0930\u0928\u093e Efficient \u0939\u094b \u091c\u093e\u0924\u093e \u0939\u0948\u0964<\/p>\n

Array \u090f\u0915 \u0939\u0940 Type \u0915\u0947 Data \u0915\u0947 \u092c\u0921\u093c\u0947 Set, \u091c\u0948\u0938\u0947 – Integers, Floating-Point Number \u092f\u093e Character \u0915\u0947 \u0938\u093e\u0925 \u0915\u093e\u092e \u0915\u0930\u0928\u0947 \u0915\u093e \u090f\u0915 Convenient Way Provide \u0915\u0930\u0924\u0947 \u0939\u0948\u0902\u0964 Array \u0915\u093e Index Number Zero \u0938\u0947 \u0936\u0941\u0930\u0942 \u0939\u094b\u0924\u093e \u0939\u0948| \u092f\u0926\u093f Array \u0915\u093e Size (n) \u0939\u0948, \u0924\u094b \u0906\u0916\u093f\u0930\u0940 Index Number (n-1) \u0939\u094b\u0917\u093e|<\/p>\n

Declaration of Array\u00a0<\/span><\/h4>\n
\n

data_type array_Name[arraySize] ;<\/p>\n<\/code><\/pre><\/div><\/section>\n

Example
\n<\/strong><\/p>\n

\n

int num[10];
\nint num[10];<\/p>\n<\/code><\/pre><\/div><\/section>\n

\u0907\u0938\u092e\u0947\u0902 int \u090f\u0915 Data Type<\/a> \u0939\u0948| \u091c\u094b \u0926\u0930\u094d\u0936\u093e\u0924\u093e \u0939\u0948, \u0915\u093f \u0907\u0938 Array \u092e\u0947\u0902 \u0915\u0947\u0935\u0932 Interger Type \u0915\u0947 Data \u0915\u094b Store \u0915\u0930 \u0938\u0915\u0924\u0947 \u0939\u0948| \u0914\u0930 num \u0909\u0938 Array \u0915\u093e \u0928\u093e\u092e \u0939\u0948, \u091c\u093f\u0938\u0915\u0947 \u0926\u094d\u0935\u093e\u0930\u093e \u0909\u0938 Array \u0915\u094b Access \u0915\u0930\u0947\u0902\u0917\u0947| \u0924\u0925\u093e Bracket \u092e\u0947\u0902 \u0932\u093f\u0916\u093e 10 Array \u0915\u0947 Length \u0915\u094b \u0926\u0930\u094d\u0936\u093e\u0924\u093e \u0939\u0948, \u092f\u0947 \u092c\u0924\u093e\u0924\u093e \u0939\u0948 \u0915\u093f num Array \u092e\u0947\u0902 (10) variable \u0939\u0948 |<\/p>\n

Length of Array<\/h4>\n

Method 1 – Using sizeof Function : <\/strong>Array \u0915\u093e Length Find \u0915\u0930\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f sizeof() Function \u0915\u093e use \u0915\u093f\u092f\u093e \u091c\u093e \u0938\u0915\u0924\u093e \u0939\u0948\u0964<\/p>\n

Example<\/strong><\/p>\n

\n
#include<\/span> <iostream><\/span>\r\nusing<\/span> namespace<\/span> std<\/span>;<\/span>\r\nint<\/span> main<\/span>()<\/span> {<\/span>\r\n\u00a0 \u00a0<\/span>int<\/span> arr<\/span>[<\/span>5<\/span>]<\/span> =<\/span> {<\/span>4<\/span>,<\/span> 1<\/span>,<\/span> 8<\/span>,<\/span> 2<\/span>,<\/span> 9<\/span>};<\/span>\r\n\u00a0 \u00a0<\/span>int<\/span> len <\/span>=<\/span> sizeof<\/span>(<\/span>arr<\/span>)\/<\/span>sizeof<\/span>(<\/span>arr<\/span>[<\/span>0<\/span>]);<\/span>\r\n\u00a0 \u00a0cout <\/span><<<\/span> \"The length of the array is: \"<\/span> <<<\/span> len<\/span>;<\/span>\r\n\u00a0 \u00a0<\/span>return<\/span> 0<\/span>;<\/span>\r\n}<\/span><\/pre>\n<\/code><\/pre><\/div><\/section>\n

Output<\/strong><\/p>\n

\n

The length of the array is: 5<\/p>\n<\/code><\/pre><\/div><\/section>\n

Method 2 – Using Pointers : <\/strong>Pointer Arithmetic \u0915\u093e use \u0915\u093f\u0938\u0940 Array \u0915\u093e Length Find \u0915\u0930\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f \u0915\u093f\u092f\u093e \u091c\u093e \u0938\u0915\u0924\u093e \u0939\u0948|<\/p>\n

Example<\/strong><\/p>\n

\n
#include<\/span> <iostream><\/span>\r\nusing<\/span> namespace<\/span> std<\/span>;<\/span>\r\nint<\/span> main<\/span>()<\/span> {<\/span>\r\n\u00a0 \u00a0<\/span>int<\/span> arr<\/span>[<\/span>5<\/span>]<\/span> =<\/span> {<\/span>5<\/span>,<\/span> 8<\/span>,<\/span> 1<\/span>,<\/span> 3<\/span>,<\/span> 6<\/span>};<\/span>\r\n\u00a0 \u00a0<\/span>int<\/span> len <\/span>=<\/span> *(&<\/span>arr <\/span>+<\/span> 1<\/span>)<\/span> -<\/span> arr<\/span>;<\/span>\r\n\u00a0 \u00a0cout <\/span><<<\/span> \"The length of the array is: \"<\/span> <<<\/span> len<\/span>;<\/span>\r\n\u00a0 \u00a0<\/span>return<\/span> 0<\/span>;<\/span>\r\n}<\/span><\/pre>\n<\/code><\/pre><\/div><\/section>\n

Output<\/strong><\/p>\n

\n

The length of the array is: 5<\/p>\n<\/code><\/pre><\/div><\/section>\n

Manipulating Array Elements<\/h4>\n

Example<\/strong><\/p>\n

\n
#include<\/span> <stdio.h><\/span>\r\nint<\/span> main<\/span>()<\/span>{<\/span>\r\n   int<\/span> n<\/span>[<\/span>10<\/span>];<\/span> \/* n is an array of 10 integers *\/<\/span>\r\n   int<\/span> i<\/span>,<\/span>j<\/span>;<\/span>\r\n   \/* initialize elements of array n to 0 *\/<\/span>         \r\n   for<\/span>(<\/span>i<\/span>=<\/span>0<\/span>;<\/span> i<\/span><<\/span>10<\/span>;<\/span> i<\/span>++<\/span>)<\/span>{<\/span>\r\n      n<\/span>[<\/span>i<\/span>]<\/span> =<\/span> i<\/span>+<\/span>100<\/span>;<\/span> \/* set element at location i to i + 100 *\/<\/span>\r\n   }<\/span>\r\n   \/* output each array element's value *\/<\/span>\r\n   for<\/span>(<\/span>j<\/span>=<\/span>0<\/span>;<\/span> j<\/span><<\/span>10<\/span>;<\/span> j<\/span>++<\/span>)<\/span>{<\/span>\r\n      printf<\/span>(<\/span>\"Element[%d] = %d\\n\"<\/span>,<\/span> j<\/span>,<\/span> n<\/span>[<\/span>j<\/span>]<\/span> );<\/span>\r\n   }<\/span><\/pre>\n
return<\/span> 0<\/span>;<\/span>\r\n}<\/span><\/pre>\n<\/code><\/pre><\/div><\/section>\n

Output<\/strong><\/p>\n

\n
Element[0] = 100\r\nElement[1] = 101\r\nElement[2] = 102\r\nElement[3] = 103\r\nElement[4] = 104\r\nElement[5] = 105\r\nElement[6] = 106\r\nElement[7] = 107\r\nElement[8] = 108\r\nElement[9] = 109\r\n<\/code><\/pre><\/div><\/section><\/pre>\n

Type of Array<\/h4>\n

Single Dimensional Array<\/h5>\n

C Programming Language \u092e\u0947\u0902 Single Dimensional Array \u0915\u093e use Same Data Type \u0915\u0947 Values \u0915\u0940 List \u0915\u094b Store \u0915\u0930\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f \u0915\u093f\u092f\u093e \u091c\u093e\u0924\u093e \u0939\u0948\u0964 \u0905\u0930\u094d\u0925\u093e\u0924, Values \u0915\u0940 \u090f\u0915 Row \u0915\u094b Store \u0915\u0930\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f Single Dimensional Array \u0915\u093e use \u0915\u093f\u092f\u093e \u091c\u093e\u0924\u093e \u0939\u0948\u0964 Single Dimensional Array \u092e\u0947\u0902 Data Linear Form \u092e\u0947\u0902 Store \u0939\u094b\u0924\u093e \u0939\u0948\u0964 Single Dimensional Array \u0915\u094b One-Dimensional Arrays, Linear Array \u092f\u093e \u0915\u0947\u0935\u0932 1-D Array \u092d\u0940 \u0915\u0939\u093e \u091c\u093e\u0924\u093e \u0939\u0948\u0964<\/p>\n

Syntax –<\/b><\/p>\n

\n

datatype arrayName [size] ;<\/p>\n<\/code><\/pre><\/div><\/section>\n

\n

Example –<\/strong><\/p>\n

\n

#include <stdio.h><\/p>\n

int main() {
\nint arr[5] = {7, 8};<\/p>\n

for (int i = 0; i < 2; i++) {
\nprintf(“%d “, arr[i]);
\n}
\nreturn 0;
\n}<\/p>\n<\/code><\/pre><\/div><\/section>\n

Output<\/strong><\/p>\n

\n

7 8<\/p>\n<\/code><\/pre><\/div><\/section>\n

\n
Two-Dimensional Array<\/h5>\n

Two-Dimensional Array \u090f\u0915 Multidimensional Array \u0915\u093e \u090f\u0915 \u0935\u093f\u0936\u0947\u0937 \u0930\u0942\u092a \u0939\u0948, \u091c\u093f\u0938\u092e\u0947\u0902 Two Dimension \u0939\u094b\u0924\u0947 \u0939\u0948\u0902\u0964 Data Structure \u092e\u0947\u0902 Matrix \u0915\u093e Representation \u0915\u0930\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f C Programming \u092e\u0947\u0902 \u0938\u092d\u0940 \u092a\u094d\u0930\u0915\u093e\u0930 \u0915\u0940 Arrays \u092e\u0947\u0902 \u0907\u0938\u0915\u093e \u0935\u094d\u092f\u093e\u092a\u0915 \u0930\u0942\u092a \u0938\u0947 use \u0915\u093f\u092f\u093e \u091c\u093e\u0924\u093e \u0939\u0948\u0964<\/p>\n

Syntax –<\/strong><\/p>\n

\n

data_type array_name[sizeof_1st_dimension (row)][sizeof_2nd_dimension(column)];<\/p>\n

\n<\/code><\/pre><\/div><\/section>\n<\/div>\n<\/div>\n

Example –<\/b><\/p>\n

\n

#include <stdio.h>
\nvoid main()
\n{
\nint score[3][2]= {10,20,30,40,50,60};
\nint i,j;
\nfor(i=0;i<3;i++)
\n{
\nprintf(“\\n”);
\nfor(j=0;j<2;j++)
\nprintf(“%d\\t”,score[i][j]);
\n}
\n}<\/p>\n<\/code><\/pre><\/div><\/section>\n

Output<\/b><\/p>\n

\n10\u00a0\u00a0\u00a0\u00a0\u00a0\u00a020
\n30\u00a0\u00a0\u00a0\u00a0\u00a0\u00a040
\n50\u00a0\u00a0\u00a0\u00a0\u00a0\u00a060<\/p>\n<\/code><\/pre><\/div><\/section>\n
Multi-Dimensional Array<\/h5>\n

Multidimensional Array, Single-Dimensional Array \u0915\u093e \u090f\u0915 Advanced Version \u0939\u0948, \u091c\u093f\u0938\u0947 Multilevel \u0924\u0915 Nested \u0915\u093f\u092f\u093e \u091c\u093e \u0938\u0915\u0924\u093e \u0939\u0948\u0964<\/p>\n

Syntax –<\/strong><\/p>\n

\n

data_type array_name[sizeof_1st_dimension][sizeof_2nd_dimension]…..[sizeof_nth_dimension];<\/p>\n<\/code><\/pre><\/div><\/section>\n

Example<\/strong><\/p>\n

\n

#include <stdio.h>
\nvoid main()
\n{
\nint arr[3][3][3],i,j,k;
\nprintf(“\\n Enter the elements for the array:”);
\nfor(i=0;i<2;i++)
\n{
\nfor(j=0;j<2;j++)
\n{
\nfor(k=0;k<2;k++)
\n{
\nprintf(“\\n array [%d][%d][%d] = “,i,j,k);
\nscanf(“%d”,&arr[i][j][k]);
\n}
\n}<\/p>\n

}
\nprintf(“\\n The matrix is:”);
\nfor(i=0;i<2;i++)
\n{
\nprintf(“\\n\\n”);
\nfor(j=0;j<2;j++)
\n{
\nprintf(“\\n”);
\nfor(k=0;k<2;k++)
\nprintf(“\\t array[%d][%d][%d]=%d”,i,j,k, arr[i][j][k]);
\n}
\n}
\n}<\/p>\n<\/code><\/pre><\/div><\/section>\n

Output<\/strong><\/p>\n

\n

Enter the elements for the array: 10,20,30,40,50,60,70,80
\narray [0][0][0] = 10
\narray [0][0][1] = 20
\narray [0][1][0] = 30
\narray [0][1][1] = 40
\narray [1][0][0] = 50
\narray [1][0][1] = 60
\narray [1][1][0] = 70
\narray [1][1][1] = 80<\/p>\n<\/code><\/pre><\/div><\/section>\n<\/div>\n","protected":false},"excerpt":{"rendered":"

Introduction of Arrays C Programming \u092e\u0947\u0902 Arrays, Element \u0915\u093e \u090f\u0915 Collection \u0939\u094b\u0924\u093e \u0939\u0948| \u091c\u093f\u0938\u092e\u0947 Same Data Type \u0915\u0947 Element \u090f\u0915 Variable Name \u092e\u0947\u0902 Grouped \u0939\u094b\u0924\u0947 \u0939\u0948\u0964 \u0907\u0928 Element \u0915\u094b Contiguous Memory Location \u092e\u0947\u0902 Store \u0915\u093f\u092f\u093e \u091c\u093e\u0924\u093e \u0939\u0948, \u091c\u093f\u0938\u0938\u0947 \u0907\u0928\u094d\u0939\u0947\u0902 Access \u0914\u0930 Manipulate \u0915\u0930\u0928\u093e Efficient \u0939\u094b \u091c\u093e\u0924\u093e \u0939\u0948\u0964 Array \u090f\u0915 \u0939\u0940 Type \u0915\u0947 Data \u0915\u0947 \u092c\u0921\u093c\u0947 […]<\/p>\n","protected":false},"author":2,"featured_media":1371,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[13],"tags":[],"_links":{"self":[{"href":"https:\/\/thelearnify.in\/wp-json\/wp\/v2\/posts\/959"}],"collection":[{"href":"https:\/\/thelearnify.in\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thelearnify.in\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thelearnify.in\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thelearnify.in\/wp-json\/wp\/v2\/comments?post=959"}],"version-history":[{"count":7,"href":"https:\/\/thelearnify.in\/wp-json\/wp\/v2\/posts\/959\/revisions"}],"predecessor-version":[{"id":3155,"href":"https:\/\/thelearnify.in\/wp-json\/wp\/v2\/posts\/959\/revisions\/3155"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thelearnify.in\/wp-json\/wp\/v2\/media\/1371"}],"wp:attachment":[{"href":"https:\/\/thelearnify.in\/wp-json\/wp\/v2\/media?parent=959"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thelearnify.in\/wp-json\/wp\/v2\/categories?post=959"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thelearnify.in\/wp-json\/wp\/v2\/tags?post=959"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}