C++ Programming Tutorial 14: Compound Data Types - Arrays :: Videos
Description:
In this video we are talking about:
- What is an Array?
- Initializing an Array.
- Accessing the value of an Array.
- Character Sequence or Character Array.
What is an Array?
- A Way of storing multiple values in only one identifier.
- If you have three different int values stored in an int array, then it can be represented as:
-
| Index: |
0 |
1 |
2 |
| Values: |
Value1 |
Value2 |
Value3 |
Declaring an array.
- An array of integer named MyArray to store 3 values can be declared as:
- Basic syntax would be:
Initializing an array
- When declaring an array in local scope, like in a function, without specifying a value, each element in the array will have an undetermined value, where as global and static array of fundamental data types will be initialized to 0.
- To assign a value while declaring, you have enclose the values in { } and separate by a comma.
- For Example:
Accessing the value:
- Each value in the array can be accessed to read and write by calling the array variable in following format:
- Example:
-
int MyArray[7] = {7, 256, 1024, 77, 88, 12};
MyArray[6] = 100;
int X = MyArray[5];
Character Sequence:
- Strings data types are just a sequence of characters, so char array and strings are interchangeable.
- Char sequence should end with null character '\\0'
Have a look at the sample program Array.cc which can be downloaded from below:
Resource files:
Thank you for watching. Please comment and subscribe.
|
|