Array

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Array It is a collection of similar elements.

String Array of characters is called string.


int marks[30] 30 is called the dimension of the array. It tells the compiler how
much element array will contain. [] tells the compiler that we are dealing with
array.

However big an array its elements are always stored in contiguous


memory locations.

int num[6] = { 2, 4, 12, 5, 45, 5 } ;


2 bytes is reserved for each number inside array but in windows and linux, 4
bytes are reserved.
Storage class of array is auto then numbers inside the array will be garbage if
values are not defined.
Storage class- static all array elements will be 0
int is 2 bytes long(in windows/linux it is 4 bytes long)
float is 4 bytes long
character is 1 byte long
Following operations on pointer cant possible
(a) Addition of two pointers
(b) Multiplication of a pointer with a constant
(c) Division of a pointer with a constant

main( )
{
int arr[ ] = { 10, 20, 30, 45, 67, 56, 74 } ;
int *i, *j ;
i = &arr[1] ;
j = &arr[5] ;
printf("%d \n %d\n", i, j);
printf("%d \n %d\n", *i, *j);
printf ( "%d %d", j - i, *j - *i ) ;
}
Pointer variables can be compared provided both variables point to objects of the
same data type.
display ( &num[0], 6 ) ;
display ( num, 6 ) ; display is a function, both statements are same

All following notations are same - num[i]


*( num + i )
*( i + num )
i[num]

An array cannot be declared to be of the type in char.

scanf(%d, &a[i]); - It will be used to take input from user


scanf(%d, a[i]) It will not show any error but it will not work
Dimension of the array should be constant, it should be not like arr[size] where
size is a variable
An array is a collection of same data type placed next to each other in memory.
Doubt
If array[] is declared this way then how many element will be in that array?

You might also like