{"id":2183,"date":"2025-01-16T08:00:00","date_gmt":"2025-01-16T07:00:00","guid":{"rendered":"https:\/\/www.fuhselab.de\/?p=2183"},"modified":"2025-11-02T11:19:34","modified_gmt":"2025-11-02T10:19:34","slug":"c-und-das-array-2","status":"publish","type":"post","link":"https:\/\/www.fuhselab.de\/index.php\/2025\/01\/16\/c-und-das-array-2\/","title":{"rendered":"C++ und das Array (2)"},"content":{"rendered":"\n<p><br>Im letzten Artikel ging es um ein fixed-size Array und in diesem Artikel geht es jetzt da weiter wo wir aufgeh\u00f6rt haben\u2026<\/p>\n\n\n\n<!--more-->\n\n\n\n<p><strong>Initialisierung der Werte im Array:<\/strong><\/p>\n\n\n\n<p>Per for-Schleife wurde das Array aus dem letzten Artikel gef\u00fcllt und es steht immer noch die Frage im Raum, weshalb man das hier so gel\u00f6st hat&#8230;Nat\u00fcrlich geht das auch anders.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;\n#include &lt;string&gt;\n\nint main() {\nstd::string countries&#91;5] = {\"Deutschland\", \"Frankreich\", \"Italien\", \"Spanien\", \"Portugal\"};\n\nfor(int i = 0; i &lt; 5; ++i) {\nstd::cout &lt;&lt; countries&#91;i] &lt;&lt; \" \";\n}\nreturn 0;\n}<\/code><\/pre>\n\n\n\n<p>Die Deklaration des Arrays sollte noch nachvollziehbar sein. Es wird ein fixed-size Arrays mit 5 Elementen vom Typ std::string erstellt. Deklaration und Initialisierung werden hier aber in einem Schritt durchgef\u00fchrt.<\/p>\n\n\n\n<p><strong>Das multidimensionale Array:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream>\n\nint main() {\n\n\/\/ Deklaration des 2D-Arrays (L\u00e4nge x Breite)\nstd::string lander&#91;2]&#91;5] = {\n{\"Deutschland\", \"Frankreich\", \"Italien\", \"Spanien\", \"England\"},\n{\"Berlin\", \"Paris\", \"Rom\", \"Madrid\", \"London\"}\n};\n\n\/\/ Ausgabe des 2D-Arrays\nfor (int i = 0; i &lt; 2; ++i) {\nstd::cout &lt;&lt; \"Land: \";\nfor (int j = 0; j &lt; 5; ++j) {\nstd::cout &lt;&lt; lander&#91;i]&#91;j] &lt;&lt; \" \";\n}\nstd::cout &lt;&lt; std::endl;\n}\nreturn 0;\n}<\/code><\/pre>\n\n\n\n<p><br>Mit den Arrays soll es das jetzt vorerst gewesen sein. Im n\u00e4chsten Artikel basteln wir uns ein C++ L\u00e4nderquiz.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Im letzten Artikel ging es um ein fixed-size Array und in diesem Artikel geht es jetzt da weiter wo wir aufgeh\u00f6rt haben\u2026<\/p>\n","protected":false},"author":1,"featured_media":543,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[32],"class_list":["post-2183","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding-club","tag-coding-club-peine"],"_links":{"self":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts\/2183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/comments?post=2183"}],"version-history":[{"count":3,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts\/2183\/revisions"}],"predecessor-version":[{"id":2898,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts\/2183\/revisions\/2898"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/media\/543"}],"wp:attachment":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/media?parent=2183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/categories?post=2183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/tags?post=2183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}