int main(){
// Def.1
int arr[3];
arr[0] = 10;
arr[1] = 20;
arr[2] = 30;
// Def.2
int arr2[4] = { 10, 20, 30}; // so arr2[3] is default 0 as it's not defined
// Def.3
int arr3[] = { 90, 80, 70, 60, 50, 40, 30, 20, 10};
system("pause");
return true;
}
int arr[5] = {1,2,3,4,5};
cout<< sizeof(arr[0]) << endl; // to get 1st element storage length
cout<< sizeof(arr) << endl; // to get arr storage length
cout<< arr << endl; // to get the first storage position
cout<< (int)arr << endl; // to get the first storage position in decimal
cout<< (int)&arr[0] << endl; // to get the first element storage position in decimal.
// Specific element position requires & sign
// Get the minimus value
#include <stdio.h>
#include <iostream>
int main(void){
int array[5] = {300, 350, 200, 400, 250};
int min = array[0];
for (int i = 0; i < 5; i++){
if (array[i] < min){
min = array[i];
}
}
printf("The minimum value is %d \n", min);
std::cout << "The minimum value is " << min << std::endl;
return 0;
}
// Get the inverse array
#include <stdio.h>
#include <iostream>
int main(void){
int array[5] = {300, 350, 200, 400, 250};
int array_inv[5] = {0, 0, 0, 0, 0};
for (int i = 0; i < 5; i++){
array_inv[i] = array[4-i];
}
for (int i = 0; i < 5; i++){
std::cout << array_inv[i] << std::endl;
}
return 0;
}
// Bubble ranking
#include <stdio.h>
#include <iostream>
int main(void){
int array[5] = {300, 350, 200, 400, 250};
for (int i=0; i<4; i++){
for (int j=0; j<4-i; j++){
if (array[j] > array[j+1]){
int temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}
for (int i = 0; i < 5; i++){
std::cout << array[i] << std::endl;
}
}
// Definition 1
string letters[2][4] = {
{ "A", "B", "C", "D" },
{ "E", "F", "G", "H" }
};
// Definition 2
int arr[2][3];
arr[0][0] = 1;
arr[0][1] = 2;
arr[0][2] = 3;
arr[1][0] = 4;
arr[1][1] = 5;
arr[1][2] = 6;
// Definition 3
int arr[2][3] = {1,2,3,4,5,6};
// Definition 4
int arr[][3] = {1,2,3,4,5,6};