![]() |
Arrays
Hey can someone kinda of explain to me about arrays ? I have information about arrays but can't really understand them . I would like to know some basic uses of array and how and when they are used..and about one dimensional and two dimensional arrays . Thanks =)
|
Here is an example of a one-dimensional array:
:
int array[10]; // create an array, containing 10 integersand an example of a two-dimensional array: :
int array[10][5]; // create an array, containing 10 arrays, each containing 5 integershope this helps :) |
Okay so what are arrays used for ? Thanks for help
|
Arrays are basically used to store a series of values of the same category. They are also often used for an amount of data you don't know the size of when compiling - e.g. information read from a file. You can use dynamic memory allocation then - asking memory at runtime. If you want, i can also give you an example of that :).
|
Okay sure ..=)
|
:
int arraysize = 20; // this is the size of the array |
Thanks think i understood it ..=)
|
"This little thingy between the quotation marks is a sequential collection of characters. It could be stored in an array."
If that were stored in MyArray, MyArray [0] would contain "T" and MyArray [12] would contain "t". If you marked the end by adding a byte with the value, 0, it would actually constitute a C string. Simple, and useful. |
Hey ..I found this code on the web but can't understand how it works..
Thanks for help. #include <iostream> using namespace std; int main() { int x; int y; int array[8][8]; // Declares an array like a chessboard for ( x = 0; x < 8; x++ ) { for ( y = 0; y < 8; y++ ) array[x][y] = x * y; // Set each element to a value } cout<<"Array Indices:\n"; for ( x = 0; x < 8;x++ ) { for ( y = 0; y < 8; y++ ) cout<<"["<<x<<"]["<<y<<"]="<< array[x][y] <<" "; cout<<"\n"; } cin.get(); } |
you refuse to use CODE tags?
|
| All times are GMT -5. The time now is 4:15 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC