From 38e3c732d86165a84cd872e96e10ca1e811f2bb1 Mon Sep 17 00:00:00 2001 From: Oskar Date: Thu, 15 Aug 2024 18:16:33 +0200 Subject: more exercises --- 3p43.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to '3p43.cpp') diff --git a/3p43.cpp b/3p43.cpp index a766d56..19fa0ce 100644 --- a/3p43.cpp +++ b/3p43.cpp @@ -2,6 +2,7 @@ #include #include "sales_data.hpp" #include "sales_item.hpp" +#include /* * @@ -11,5 +12,39 @@ */ int main () { + + int ia[3][4] = { + {1,2,3,4}, + {5,6,7,8}, + {9,10,11,12} + }; + + for (int (&a)[4] : ia) { // A reference to an array of 4 int's + // I'll be honest i would not have figured that out myself, i did search the internet for answers. + for (int aa : a) { + std::cout << aa << " "; + } + + std::cout << std::endl; + } + + std::cout << std::endl; + for(size_t i = 0 ; i != 3 ; ++i) { + for(size_t j = 0 ; j != 4 ; ++j) { + std::cout << ia[i][j] << " "; + } + + std::cout << std::endl; + } + + std::cout << std::endl; + for(int (*p)[4] = std::begin(ia) ; p != std::end(ia) ; ++p) { + for(int *pp = std::begin(*p) ; pp != std::end(*p) ; ++pp) { + std::cout << *pp << " "; + } + + std::cout << std::endl; + } + return 0; } -- cgit v1.2.3