Arrays are nothing but elements of same type stored in contigues manner.
A list of programmers working in a company, list of softwares installed in computer. For example there 10 programmers and 200 softwares installed in the computer.
10 programmers, 200 softwares but they are not same type, how come arrays will be used. Yes, 10 programmers are just numbers we are not interested on each person whether he is male or female, young or old, black or white etc.
Confused leave that example.
IF there are 100 apples, then we can store these apples in array. Thats it.
We have one dimensional, 2 dimensional and upto n-dimensional array.
All n-dimensional arrays are again each 1-dimensional array.
Properties of arrays
1) Arrays should be same data type and cannot be mixed with other data types.
examples
int apple[100], float money[100], char names[500] etc.
Each one is unique.
2) Arrays will always start with index 0 and ends with <n> -1.
In the above example, loop your variable from 0 to 99, 0 to 499 etc to access each item from the array.
3) Arrays can be statically created or dynamically created. Above example shows static allocation.
Dynamically create the array as follows
int *p = (int*) malloc(100*(sizeof(int)) ;
and access using p[0], p[1] etc. and remember to free after the usage.
A list of programmers working in a company, list of softwares installed in computer. For example there 10 programmers and 200 softwares installed in the computer.
10 programmers, 200 softwares but they are not same type, how come arrays will be used. Yes, 10 programmers are just numbers we are not interested on each person whether he is male or female, young or old, black or white etc.
Confused leave that example.
IF there are 100 apples, then we can store these apples in array. Thats it.
We have one dimensional, 2 dimensional and upto n-dimensional array.
All n-dimensional arrays are again each 1-dimensional array.
Properties of arrays
1) Arrays should be same data type and cannot be mixed with other data types.
examples
int apple[100], float money[100], char names[500] etc.
Each one is unique.
2) Arrays will always start with index 0 and ends with <n> -1.
In the above example, loop your variable from 0 to 99, 0 to 499 etc to access each item from the array.
3) Arrays can be statically created or dynamically created. Above example shows static allocation.
Dynamically create the array as follows
int *p = (int*) malloc(100*(sizeof(int)) ;
and access using p[0], p[1] etc. and remember to free after the usage.
No comments:
Post a Comment