<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>memo.393 &#187; C</title>
	<atom:link href="http://memo.393.bz/archives/tag/c/feed" rel="self" type="application/rss+xml" />
	<link>http://memo.393.bz</link>
	<description>個人的メモです。間違いなどありましたらご指摘ください。。。</description>
	<lastBuildDate>Sun, 27 Nov 2011 15:27:41 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>[iPhone]C ポインタについて</title>
		<link>http://memo.393.bz/archives/1095</link>
		<comments>http://memo.393.bz/archives/1095#comments</comments>
		<pubDate>Tue, 27 Apr 2010 06:09:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[C]]></category>

		<guid isPermaLink="false">http://memo.393.bz/?p=1095</guid>
		<description><![CDATA[すぐにこんがらがるのでメモ ポインタとは、(変数の)メモリ上のアドレスの番地を格納するための仕組み //ポインタの定義 //型名 *変数名 int *p; int* p;//*の位置はこの書き方でもよい int a=10 [...]]]></description>
			<content:encoded><![CDATA[<p>すぐにこんがらがるのでメモ<br />
ポインタとは、(変数の)メモリ上のアドレスの番地を格納するための仕組み</p>
<pre name="code" class="c">

//ポインタの定義
//型名 *変数名
int *p;
int* p;//*の位置はこの書き方でもよい

int a=100;
//変数aのメモリ上のアドレスは、&amp;aとなる。
//ポインタpにaを参照させるには、
p = &amp;amp;a;//*pではないことに注意
//ポインタからaの値を取得するには
int b=*p;
printf(b);//出力：100
</pre>
<p>*の使い方についての注意<br />
定義するときの*と、それ以外の*では意味合いが異なるらしい</p>
<pre name="code" class="c">

//整数定義
int a = 100;
//整数型のポイントを定義
int *p;
*p = a;//これはNG
//定義後のポインタ変数に参照させるには、p = &amp;a;
//ただしポインタ定義時の初期化でaを代入するのはOK
int *q = a;//これはOK
//定義するときの*と、それ以外の*では意味合いが違うということらしい
</pre>
<p>配列のときは配列名には、&#038;はつける必要がない<br />
ポインタ名は配列と同じようだ。</p>
<pre name="code" class="c">

int a[20] = {1,12,23,34,45};
int b = 100;
int *pa;
int *pb;
pa = a;//&amp;aにはならない
pb = &amp;b;

//配列aの2番目の値を取得するには
//配列aを使う場合
printf(&quot;%d\n&quot;,a[1]);//出力：12
//ポインタpaを使う場合
printf(&quot;%d\n&quot;,*(pa+1));//出力：12
printf(&quot;%d\n&quot;,pa[1]);//出力：12
</pre>
<p>メモリを確保したポインタも配列と同じように扱える</p>
<pre name="code" class="as">

int *bufa;
//100バイト分のメモリを確保
bufa = (int *)malloc(sizeof(int)*100);
bufa[10] = 123;
//配列のように参照
printf(&quot;%d\n&quot;,bufa[10]);//出力：123
//ポインタとして参照
printf(&quot;%d\n&quot;,*(bufa+10));//出力：123
</pre>
]]></content:encoded>
			<wfw:commentRss>http://memo.393.bz/archives/1095/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[iP]C言語のポインタについて</title>
		<link>http://memo.393.bz/archives/940</link>
		<comments>http://memo.393.bz/archives/940#comments</comments>
		<pubDate>Fri, 26 Feb 2010 05:58:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://memo.393.bz/?p=940</guid>
		<description><![CDATA[Objective-Cの準備としてのC言語勉強中。 ポインタのお作法がこんがらがるのでメモしとく。 まず例文から （のつもりがそのまま注釈も書いちゃった） //整数型の変数：numberの定義 int number =  [...]]]></description>
			<content:encoded><![CDATA[<p>Objective-Cの準備としてのC言語勉強中。<br />
ポインタのお作法がこんがらがるのでメモしとく。</p>
<p>まず例文から<br />
（のつもりがそのまま注釈も書いちゃった）</p>
<pre name="code" class="c">

//整数型の変数：numberの定義
int number = 100;

//(numberを操作するための)ポインタ変数：pointerの定義
int *pointer;
//*pointerではなく、pointerがポインタ変数
//(*は宣言時の型的な役割→「int *」が型らしい)
//なので、↓でもOK(こう書いた方がわかりやすいかも)
int* pointer;
//intは、扱う変数の型
//(この例ではnumberの型と同じとする)

//ポインタ変数には、変数のアドレスを渡す。
//変数の頭に&amp;;を加えることで、変数のアドレスを意味する
pointer  = &amp;number;

//ポインタ変数を使って、変数numberを操作するには
*pointer = 200;
//*をつけると、そのアドレス対象にアクセスできる
//（この場合は*pointer == numberという感じらしい）

printf( %d\n, number);//出力：200
</pre>
]]></content:encoded>
			<wfw:commentRss>http://memo.393.bz/archives/940/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

