﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-anchao1987-文章分类-C\C++</title><link>http://www.cppblog.com/anchao1987/category/16244.html</link><description /><language>zh-cn</language><lastBuildDate>Sun, 20 Mar 2011 15:47:59 GMT</lastBuildDate><pubDate>Sun, 20 Mar 2011 15:47:59 GMT</pubDate><ttl>60</ttl><item><title>指针加const脑细胞杀伤器</title><link>http://www.cppblog.com/anchao1987/articles/142185.html</link><dc:creator>Moking</dc:creator><author>Moking</author><pubDate>Fri, 18 Mar 2011 18:18:00 GMT</pubDate><guid>http://www.cppblog.com/anchao1987/articles/142185.html</guid><wfw:comment>http://www.cppblog.com/anchao1987/comments/142185.html</wfw:comment><comments>http://www.cppblog.com/anchao1987/articles/142185.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/anchao1987/comments/commentRss/142185.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/anchao1987/services/trackbacks/142185.html</trackback:ping><description><![CDATA[<div style="position: absolute; left: 0pt; top: 0pt; z-index: 1000; font-family: arial; font-size: 13px; margin: 5px; background: none repeat scroll 0% 0% yellow; -moz-border-radius: 5px 5px 5px 5px; opacity: 0.9; display: none;" id="dictdiv"></div>
<div style="font-style: italic; font-weight: bold;" id="dictaudio"></div>
<p>1、想想以下定义中的<code class="literal">const</code>分别起什么作用？编写程序验证你的猜测。</p>
<pre class="programlisting">//**p1不可以改变，p1可以改变。<br>const char **p1;<br>//*p2不可以改变，p2可以改变。<br>char *const *p2;<br>//p3不可以改变<br>char **const p3;<br><br>一些总结内容，引用自http://learn.akae.cn/akabook/ch23s06_2。<br>
<div style="position: absolute; left: 0pt; top: 0pt; z-index: 1000; font-family: arial; font-size: 13px; margin: 5px; background: none repeat scroll 0% 0% yellow; -moz-border-radius: 5px 5px 5px 5px; opacity: 0.9; display: none;" id="dictdiv"></div>
<div id="dictaudio"></div>
<pre>/* test.c */<br>int main(int argc, char *argv[])<br>{<br>	char const *  * const * * pp=0;  //line 4<br>	pp++;		// line 5<br>	(*pp)++;	// line 6<br>	(**pp)++;	// line 7<br>	(***pp)++;	// line 8<br>	(****pp)++;	// line 9<br>	return 0;<br>}<br><br>上面的例子，大家在line 4中&#8220;*&#8221;号前后随意增删关键字const，编译,看line5到line 9，那些行会报错，能找到如下规律。<br><br>从右往左数，如果第n过*前有const关键字，那么 *...*pp 的值就不能改变。  *...*表示n个星<br><br>上例中：char const *  * const * * pp=0; 从右往左数,第二个"*"和第4个前有const，所以, (**p) 和(****p)的值不可改变</pre>
<br></pre>
<br><br><br>  <img src ="http://www.cppblog.com/anchao1987/aggbug/142185.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/anchao1987/" target="_blank">Moking</a> 2011-03-19 02:18 <a href="http://www.cppblog.com/anchao1987/articles/142185.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>