Vous êtes sur la page 1sur 2

ARRAYS

1. An Array is a Collection of Homogeneous Data Items shared by a


common name
2. An Array is a Collection of similar data items
3. An Array will be Stored in Sequential emory locations
!. An 1"D array is also #nown as $ector% or single subscri&ted 'ariable
(. An 2" D array is also #nown as atri)% or double subscri&ted 'ariable
or *able.
+. An array with more than 1 dimension is called ulti Dimensional
array.
,. *he array name re&resents base address-starting address. of the array
/)0 int a11234 a and 5a123 both refers to base address
6. In int a11234 77a will throws an error since base address can not be
changed.
8. *he /lements of an array can be accessed using indices or subscri&ts
/)0 int a11234 12 here re&resents si9e of the array % always should be a
&ositi'e 'alue % and the elements of this array can be accessible in the
following manner0 a123%a113%a123%a133:::::a183
12.An Array always starts with an Inde) 2 and last inde) will be ;"1
where ; is the si9e of the array.
11. Always the si9e of an Array 'ariable should be a Constant $alue
12.An Array will be stored on row ma<or order fashion.
13.Array Declaration0 =data ty&e > array name1 si9e 34
a. /)0 int a11234
b. ?loat b12234
c. Char name13234
1!.Static Initiali9ation 0 int a13 @ A1%2%3%!%(B4 " while initiali9ing an array
statically% si9e is o&tional .
1(.static int a11234 " sets all the elements to 2
1+.int a11234 " an array will be created by default contains garbage
1,.*he total Cytes Dccu&ied by an array is 0 Si9e of array E si9eof
-dataty&e.
16.C language has a drawbac# it has no array bound chec#ing
for e)am&le0 int a11234
Starting inde)0 2 last inde)0 8 % if we access a1223 the com&iler
wont generate any error.
18.Arrays can be accessed in ! ways.
a. int a1 12 34 the array element a133 can accessed using !
ways
&rintf-FGd Gd Gd Gd H %a133%31a3%E-a73.%E-37a..4
22.int a1234 " error4 while declaring the array the si9e should be > 2.
21.int a134 " error 4 si9e is must in declaring an array
22.int a13123123 @ A1%2%3%!%(%+%,%6B4 " In a ulti Dimensional Array the
first subscri&t can be left em&ty.
23.Arrays usually follow the static memory allocation.
2!.In /fficient emory Itili9ation is the &roblem associated with arrays%
to rectify this dynamic memory allocation using &ointers can be used
2(.alloc.h is the header file that contains malloc-.%calloc-.%realloc-.%free-.
functions for dynamic allocation and freeing the memory
2+.memset-.% memc&y-.% memcm&-. functions are in mem.h header file.
2,. Array name and subscri&ted 'ariables are different
/)0 int a11234 where JaK is name of the array
a123%a113%a123:::::.are called subscri&ted 'ariables.
26.int a1 3123133 @ A A A 1 % 2 % 3 B%A ! % ( % + B B%
A A , % 6 % 8B% A 12 % 11 % 12BB
B4
Let us assume starting address of the array is +(!,6
a re&resents starting address of the 3"D array " +(!,6
Ea re&resents starting address of the 2 M D array " +(!,6
EEa re&resents starting address of the 1"D array " +(!,6
EEEa re&resents 'alue at the base address of the array M 1
a71 " +(!82
Ea71 " +(!6!
EEa71 " +(!62
28.int a11234
&rintf -FGd H%a1"13.4 " &rints un&redictable garbage 'alue
32.int a11234
&rintf-FGdH%si9eof-a.Nsi9eof-a123..4
" &rints number of elements in the array.

Vous aimerez peut-être aussi