<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Verständnisfrage Speicheradresse Arrays]]></title><description><![CDATA[<p>beschäftige mich grad mit Arrays und hab so ein kleines Beispielprogramm geschrieben. Wie Arrays funktionieren ist mir glaub ich jetzt klar. Nur eins versteh ich jetzt nicht. Ih habe ein Integer-Array erstellt und die Adressen mit ausgegeben. Danach hab ich ein double-array erstellt. Warum beginnen die Elemente wieder mit der gleichen Adresse?</p>
<pre><code class="language-cpp">#include &quot;stdafx.h&quot;

using namespace std;
#define SIZE 10

int _tmain(int argc, _TCHAR* argv[])
{
	int iarray[SIZE] = {0,1,2,3,4,5,6,7}; // Elemente definiert und initialisiert
	iarray[0] = 100;      // weist dem ersten Element den Wert 100 zu
	iarray[1] = 44;
	iarray[2] = 1645;

	for (int i=0; i&lt;SIZE; i++) {
		cout &lt;&lt; &quot;Index &quot; &lt;&lt; setw(2) &lt;&lt; i  &lt;&lt; &quot; Wert: &quot; &lt;&lt; setw(10) &lt;&lt; iarray[i] &lt;&lt; &quot; Adresse: &quot; &lt;&lt; &amp;iarray[i] 
			&lt;&lt; &quot; Groesse: &quot; &lt;&lt; sizeof(iarray[i]) &lt;&lt; &quot; Bytes&quot; &lt;&lt; endl;
	}
	cout &lt;&lt; endl;
	cout &lt;&lt; &quot;Groesse des ges. Arrays: &quot; &lt;&lt; sizeof(iarray) &lt;&lt; endl;
	int groesse = sizeof(iarray)/sizeof(int);
	cout &lt;&lt; &quot;Anzahl der Elemente    : &quot; &lt;&lt; groesse &lt;&lt; endl;
	cout &lt;&lt; &quot;erste Adresse          : &quot; &lt;&lt; &amp;iarray &lt;&lt; endl;
	cout &lt;&lt; endl;

	double darray[] = {2.1,6.2,7.8};
	groesse = sizeof(darray)/sizeof(double);
	for (int i=0; i&lt;groesse; i++) {
		cout &lt;&lt; &quot;Index &quot; &lt;&lt; setw(2) &lt;&lt; i  &lt;&lt; &quot; Wert: &quot; &lt;&lt; setw(10) &lt;&lt; darray[i] &lt;&lt; &quot; Adresse: &quot; &lt;&lt; &amp;iarray[i] 
			&lt;&lt; &quot; Groesse: &quot; &lt;&lt; sizeof(darray[i]) &lt;&lt; &quot; Bytes&quot; &lt;&lt; endl;;
	}

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/258077/verständnisfrage-speicheradresse-arrays</link><generator>RSS for Node</generator><lastBuildDate>Wed, 09 Sep 2026 14:55:39 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/258077.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 06 Jan 2010 13:17:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Verständnisfrage Speicheradresse Arrays on Wed, 06 Jan 2010 13:17:49 GMT]]></title><description><![CDATA[<p>beschäftige mich grad mit Arrays und hab so ein kleines Beispielprogramm geschrieben. Wie Arrays funktionieren ist mir glaub ich jetzt klar. Nur eins versteh ich jetzt nicht. Ih habe ein Integer-Array erstellt und die Adressen mit ausgegeben. Danach hab ich ein double-array erstellt. Warum beginnen die Elemente wieder mit der gleichen Adresse?</p>
<pre><code class="language-cpp">#include &quot;stdafx.h&quot;

using namespace std;
#define SIZE 10

int _tmain(int argc, _TCHAR* argv[])
{
	int iarray[SIZE] = {0,1,2,3,4,5,6,7}; // Elemente definiert und initialisiert
	iarray[0] = 100;      // weist dem ersten Element den Wert 100 zu
	iarray[1] = 44;
	iarray[2] = 1645;

	for (int i=0; i&lt;SIZE; i++) {
		cout &lt;&lt; &quot;Index &quot; &lt;&lt; setw(2) &lt;&lt; i  &lt;&lt; &quot; Wert: &quot; &lt;&lt; setw(10) &lt;&lt; iarray[i] &lt;&lt; &quot; Adresse: &quot; &lt;&lt; &amp;iarray[i] 
			&lt;&lt; &quot; Groesse: &quot; &lt;&lt; sizeof(iarray[i]) &lt;&lt; &quot; Bytes&quot; &lt;&lt; endl;
	}
	cout &lt;&lt; endl;
	cout &lt;&lt; &quot;Groesse des ges. Arrays: &quot; &lt;&lt; sizeof(iarray) &lt;&lt; endl;
	int groesse = sizeof(iarray)/sizeof(int);
	cout &lt;&lt; &quot;Anzahl der Elemente    : &quot; &lt;&lt; groesse &lt;&lt; endl;
	cout &lt;&lt; &quot;erste Adresse          : &quot; &lt;&lt; &amp;iarray &lt;&lt; endl;
	cout &lt;&lt; endl;

	double darray[] = {2.1,6.2,7.8};
	groesse = sizeof(darray)/sizeof(double);
	for (int i=0; i&lt;groesse; i++) {
		cout &lt;&lt; &quot;Index &quot; &lt;&lt; setw(2) &lt;&lt; i  &lt;&lt; &quot; Wert: &quot; &lt;&lt; setw(10) &lt;&lt; darray[i] &lt;&lt; &quot; Adresse: &quot; &lt;&lt; &amp;iarray[i] 
			&lt;&lt; &quot; Groesse: &quot; &lt;&lt; sizeof(darray[i]) &lt;&lt; &quot; Bytes&quot; &lt;&lt; endl;;
	}

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1833625</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1833625</guid><dc:creator><![CDATA[rudpower]]></dc:creator><pubDate>Wed, 06 Jan 2010 13:17:49 GMT</pubDate></item><item><title><![CDATA[Reply to Verständnisfrage Speicheradresse Arrays on Wed, 06 Jan 2010 13:20:39 GMT]]></title><description><![CDATA[<p>Copy/Paste ist böse!<br />
Schau dir mal genau an, was du da für eine Adresse ausgibst. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1833627</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1833627</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Wed, 06 Jan 2010 13:20:39 GMT</pubDate></item><item><title><![CDATA[Reply to Verständnisfrage Speicheradresse Arrays on Wed, 06 Jan 2010 13:20:53 GMT]]></title><description><![CDATA[<p>Hast Dich beim Copy+Paste vertan.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1833628</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1833628</guid><dc:creator><![CDATA[SG1]]></dc:creator><pubDate>Wed, 06 Jan 2010 13:20:53 GMT</pubDate></item><item><title><![CDATA[Reply to Verständnisfrage Speicheradresse Arrays on Wed, 06 Jan 2010 13:25:50 GMT]]></title><description><![CDATA[<p>oh^^ sorry.<br />
was so ein kleines 'd' so ausmachen kann.</p>
<p>aber prinzipiell werden die Daten hintereinanderim Stack abgelegt oder? und die Adressen je nach Variablengröße erhöht? Wann werden die Speicher wieder gelöscht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1833630</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1833630</guid><dc:creator><![CDATA[rudpower]]></dc:creator><pubDate>Wed, 06 Jan 2010 13:25:50 GMT</pubDate></item><item><title><![CDATA[Reply to Verständnisfrage Speicheradresse Arrays on Wed, 06 Jan 2010 13:28:48 GMT]]></title><description><![CDATA[<p>Freigegeben wird der Speicher im Grunde wenn du den Scope verläßt, in diesem Fall die main-Methode. Dadurch wird aber auch dein Programm beendet, was eh den Speicher freigibt.<br />
Neue Scopes erstellst du zB mit Funkionen, innerhalb von Schleifen oder auch mit simplen geschweiften Klammern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1833635</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1833635</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Wed, 06 Jan 2010 13:28:48 GMT</pubDate></item><item><title><![CDATA[Reply to Verständnisfrage Speicheradresse Arrays on Wed, 06 Jan 2010 13:29:40 GMT]]></title><description><![CDATA[<p>das Wort scope ist neu für mich</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1833637</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1833637</guid><dc:creator><![CDATA[rudpower]]></dc:creator><pubDate>Wed, 06 Jan 2010 13:29:40 GMT</pubDate></item><item><title><![CDATA[Reply to Verständnisfrage Speicheradresse Arrays on Wed, 06 Jan 2010 13:36:30 GMT]]></title><description><![CDATA[<p>rudpower schrieb:</p>
<blockquote>
<p>aber prinzipiell werden die Daten hintereinanderim Stack abgelegt oder? und die Adressen je nach Variablengröße erhöht? Wann werden die Speicher wieder gelöscht?</p>
</blockquote>
<p>Ja. Gelöscht, respektive freigegeben wird der Speicher wieder (bei automatischen Objekten, also die, die du ohne new/malloc erstellst) wenn du den aktuellen Scope (Bereich) verlässt. Das heisst z.B wenn du eine lokale Variable in einer Funktion hast, sobald die Funktion verlassen wird. Wenn du einen Member in einer Klasse hast sobald die Klasse selbst (oder besser das Objekt) zerstört wird. Man kann das auch ganz von selbst fein steuern, indem man { und } benutzt. Bsp:</p>
<pre><code class="language-cpp">class bar
{
 private:
  int m_;
};

int foo ()
{
 int n = 5;

 {
   int f = 2;
 } // f wird hier zerstört

} // n wird hier zerstört

int main ()
{
 foo ();

 bar b;
} // b wird hier zerstört und mit ihm auch die member m_
</code></pre>
<p>Wenn du aber z.B eine static Variable hast, dann wird diese erst wenn die main beendet wird zerestört. (egal, wo du sie erzeugt hast).<br />
Im Falle von dynamischen Speicher, den du mit new anfordern kannst geht die Lebensdauer solange bist du sie mit delete aufhebst. (oder bei modernen Betriebssystemen, wenn dein Programm selbst beendet wird).</p>
<p>/EDIT<br />
Ein Scope ist, wie schon gesagt ein Bereich. Am besten schaust du dir die Beispiele an, die sehr genau besagen, was ein Scope ist. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /><br />
Die Übersetzung auf Deutsch passt sogar anscheinend recht gut:<br />
<a href="http://www.dict.cc/englisch-deutsch/scope.html" rel="nofollow">http://www.dict.cc/englisch-deutsch/scope.html</a><br />
Bis auf Oszilloskop können imo alle Möglichkeiten als Synonyme betrachtet werden. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1833640</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1833640</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Wed, 06 Jan 2010 13:36:30 GMT</pubDate></item><item><title><![CDATA[Reply to Verständnisfrage Speicheradresse Arrays on Wed, 06 Jan 2010 14:19:42 GMT]]></title><description><![CDATA[<p>alles klar, danke für die Hilfe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1833679</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1833679</guid><dc:creator><![CDATA[rudpower]]></dc:creator><pubDate>Wed, 06 Jan 2010 14:19:42 GMT</pubDate></item></channel></rss>