Skip to main content

Posts

Showing posts with the label Arrays

One dimensional array

           One dimensional array can be thought as a list of values. In one dimensional array, there is only one subscript like num[10], where 10 is called subscript or index.       e.g. int a[5];        1 th element     a[0] 2 nd element      a[1] 3 rd element    a[2] 4 th element      a[3] 5 th element    a[4]                                     2000                          2002             ...

Characteristics of Array

Ø   The declaration int a [5] is nothing but creation of 5 variables of integer types in the memory. Instead of declaring five variables for five values, the programmer can define them in the array. Ø   All the elements of an array share the same name, and they are distinguished from one another with the help of an element number. Ø   The element number in the array plays an important role for calling each element. Ø    Any particular element of an array can be modified separately without disturbing other elements. Ø   Any element of an array a[ ] can be assigned/equated to another ordinary variable or array variable of its type. e.g. int b, a[10];    b=a[5];    a[2]=a[3];

Array input and output in C programming

   Loops are used for array input/outputs. To access the individual elements of array, we use subscripts as a[subscript], where subscript could be a constant integer like 0 , 1, 5 or a integer variable like i, j or a integer expression like (i+j+2). One important thing to note is that the value of subscript should be integer. e.g:              #include<stdio.h> #include<conio.h> void main()   {   int a[10], i;   clrscr();   printf("Enter 10 numbers:\n");   for(i=0;i<10;i++)      scanf("%d",&a[i]);  /* array input */   printf("\n You have entered these 10 numbers:\n");   for(i=0;i<10;i++)     printf("\t%d",a[i]);  /* array output*/  getch();   }              ...

Arrays and Strings in C programming

           Array is a data structure that store a number of data items as a single entity (object). The individual data items are called elements and all of them have same data types. Array is used when multiple data items that have common characteristics are required (in such situation use of more variables is not efficient). In array system, an array represents multiple data items but they share same name. The individual data items can be characters, integers, floating point numbers etc. However, they must all be of the same type and the same storage class.     It is the fact that a string can be represented as a one-dimensional character -type array. Thus, character array is also known as string. Each character within the string will be stored within one element of the array. Strings are used by C to manipulate text such as words and sentences. A string is always terminated by a null character ( i.e \0). The terminating null characte...