diff --git a/a.out b/a.out new file mode 100755 index 0000000..24d67af Binary files /dev/null and b/a.out differ diff --git a/arrays/a.out b/arrays/a.out new file mode 100755 index 0000000..d000456 Binary files /dev/null and b/arrays/a.out differ diff --git a/arrays/array.cpp b/arrays/array.cpp new file mode 100644 index 0000000..fb5e3fe --- /dev/null +++ b/arrays/array.cpp @@ -0,0 +1,9 @@ +#include + +using namespace std; + +int main() { + string cars[4] = { "Volvo" , "Opel", "Volkswage" , "xyn" }; + std::cout << cars[1]; + return 0; +} \ No newline at end of file diff --git a/arrays/array_for.cpp b/arrays/array_for.cpp new file mode 100644 index 0000000..d21655f --- /dev/null +++ b/arrays/array_for.cpp @@ -0,0 +1,11 @@ +#include + +using namespace std; + +int main() { + string cars[4] = {"Volvo", "Opel", "Volkswagen", "Auto"}; + + for (int i = 0; i < 4 ; i++) { // needs to be size of cars array else segfault + cout << cars[i] << "\n"; + } +} \ No newline at end of file diff --git a/arrays/get_size.cpp b/arrays/get_size.cpp new file mode 100644 index 0000000..cc2cbcc --- /dev/null +++ b/arrays/get_size.cpp @@ -0,0 +1,21 @@ +#include + +using namespace std; + +int return_byte_size() { + int number_array[10] = {1,2,3,4,5,6,7,8,9,10}; + return sizeof(number_array); +} + +int return_length_of() { + int number_array[10] = {1,2,3,4,5,6,7,8,9,10}; + return sizeof(number_array) / sizeof(number_array[0]); +} + +int main() { + cout << return_byte_size() << "\n"; + cout << return_length_of() << "\n"; + cout << "Looping through"; + cout << loop_sizeof() << "\n"; + return 0; +} \ No newline at end of file diff --git a/arrays/sizeof_loop.cpp b/arrays/sizeof_loop.cpp new file mode 100644 index 0000000..26664f8 --- /dev/null +++ b/arrays/sizeof_loop.cpp @@ -0,0 +1,10 @@ +#include + +using namespace std; + +int main() { + int numbers[10] = {1,2,3,4,5,6,7,8,9,10}; + for (int i = 0; i < sizeof(numbers) / sizeof(numbers[0]) ; i++) { + cout << numbers[i] << "\n"; + } +} \ No newline at end of file