﻿<?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>IT博客-龙霖天网-文章分类-c++</title><link>http://www.cnitblog.com/qlb5626267/category/7790.html</link><description>龙霖学习园地</description><language>zh-cn</language><lastBuildDate>Thu, 13 Oct 2011 05:49:03 GMT</lastBuildDate><pubDate>Thu, 13 Oct 2011 05:49:03 GMT</pubDate><ttl>60</ttl><item><title>C/C++面试题目集锦</title><link>http://www.cnitblog.com/qlb5626267/articles/51269.html</link><dc:creator>龙霖</dc:creator><author>龙霖</author><pubDate>Sun, 09 Nov 2008 14:53:00 GMT</pubDate><guid>http://www.cnitblog.com/qlb5626267/articles/51269.html</guid><wfw:comment>http://www.cnitblog.com/qlb5626267/comments/51269.html</wfw:comment><comments>http://www.cnitblog.com/qlb5626267/articles/51269.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/qlb5626267/comments/commentRss/51269.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/qlb5626267/services/trackbacks/51269.html</trackback:ping><description><![CDATA[<div class=tit>C/C++面试题目集锦(zz)</div>
<div class=date>2007-08-10 13:49</div>
<table style="TABLE-LAYOUT: fixed">
    <tbody>
        <tr>
            <td>
            <div class=cnt id=blog_text><a href="http://community.csdn.net/Expert/topic/3487/3487276.xml?temp=6.420314E-03" target=_blank><font color=#003399><u>一、输入一个n ，然后在屏幕上打印出NxN 的矩阵！</u></font></a> <br>例如，输入一个3，则 <br>1 2 3 <br>8 9 4 <br>7 6 5 <br>输入一个4，则 <br>1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2 3 4 <br>12 13 14 5 <br>11 16 15 6 <br>10 9 8 7 <br><a href="http://community.csdn.net/Expert/topic/3488/3488624.xml?temp=.5341608" target=_blank><font color=#003399><u>参考答案：</u></font></a> <br>
            <table style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; MARGIN: 10px; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" cellSpacing=0 cellPadding=10 width="90%">
                <tbody>
                    <tr>
                        <td bgColor=#eeeeee><font face="Courier New"><font color=#003399><br>#include&lt;stdio.h&gt; <br>#include&lt;conio.h&gt; <br>#define N 10 <br><br>void printCube(int a[][N],int n); <br><br>void main() <br>{ <br>&nbsp;&nbsp;&nbsp; int a[N][N],n; <br>&nbsp;&nbsp;&nbsp; printf("input n:\n"); <br>&nbsp;&nbsp;&nbsp; scanf("%d",&amp;n); <br>&nbsp;&nbsp;&nbsp; printCube(&amp;a[0],n); <br>&nbsp;&nbsp;&nbsp; getch(); <br>} <br><br>void printCube(int a[][N],int n) <br>{ <br>&nbsp;&nbsp;&nbsp; int i,j,round=1; <br>&nbsp;&nbsp;&nbsp; int m=1; <br>&nbsp;&nbsp;&nbsp; for(i=0;i&lt;n;i++) <br>a[0]<em>=m++; <br>&nbsp;&nbsp;&nbsp; for(i=n-1;i&gt;=n/2;i--) <br>&nbsp;&nbsp;&nbsp; { <br>for(j=round;j&lt;=i;j++) <br>&nbsp;&nbsp;&nbsp; a[j]<em>=m++; <br>for(j=i;j&gt;=round;j--) <br>&nbsp;&nbsp;&nbsp; a<em>[j-1]=m++; <br>for(j=i;j&gt;round;j--) <br>&nbsp;&nbsp;&nbsp; a[j-1][round-1]=m++; <br>for(j=round;j&lt;i;j++) <br>&nbsp;&nbsp;&nbsp; a[round][j]=m++; <br>round++; <br>&nbsp;&nbsp;&nbsp; } <br>&nbsp;&nbsp;&nbsp; for(i=0;i&lt;n;i++){ <br>for(j=0;j&lt;n;j++) <br>printf("%3d",a<em>[j]); <br>printf("\n"); <br>&nbsp;&nbsp;&nbsp; } <br>} <br></em></em></em></em></font></font></td>
                    </tr>
                </tbody>
            </table>
            <br><a href="http://community.csdn.net/Expert/topic/3490/3490286.xml?temp=.6910364" target=_blank><font color=#003399><u>二、朗讯面试题 ：</u></font></a> <br>There are two int variables: a and b, don&#8217;t use &#8220;if&#8221;, &#8220;? :&#8221;, &#8220;switch&#8221; or other judgement statements, find out the biggest one of the two numbers. <br><a href="http://community.csdn.net/Expert/topic/3490/3490293.xml?temp=.4209864" target=_blank><font color=#003399><u>参考答案：</u></font></a> <br>方案一
            <table style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; MARGIN: 10px; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" cellSpacing=0 cellPadding=10 width="90%">
                <tbody>
                    <tr>
                        <td bgColor=#eeeeee><font face="Courier New"><font color=#003399>int max = ((a+b)+abs(a-b)) / 2 </font></font></td>
                    </tr>
                </tbody>
            </table>
            <br>方案二
            <table style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; MARGIN: 10px; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" cellSpacing=0 cellPadding=10 width="90%">
                <tbody>
                    <tr>
                        <td bgColor=#eeeeee><font face="Courier New"><font color=#003399>int c = a -b; <br>char *strs[2] = {"a大","b大"}; <br>c = unsigned(c) &gt;&gt; (sizeof(int) * 8 - 1); </font></font></td>
                    </tr>
                </tbody>
            </table>
            <br><a href="http://community.csdn.net/Expert/topic/3490/3490046.xml?temp=.7987482" target=_blank><font color=#003399><u>三、朗讯面试题 ：</u></font></a> <br>如何打印出当前源文件的文件名以及源文件的当前行号？ <br>参考答案： <br>
            <table style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; MARGIN: 10px; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" cellSpacing=0 cellPadding=10 width="90%">
                <tbody>
                    <tr>
                        <td bgColor=#eeeeee><font face="Courier New"><font color=#003399>通常使用的就是__FILE__, __LINE__，在调试函数中利用&#8220;%s","%ld",打印就好了。</font></font></td>
                    </tr>
                </tbody>
            </table>
            <br><a href="http://community.csdn.net/Expert/topic/3490/3490045.xml?temp=.9329492" target=_blank><font color=#003399><u>四、朗讯面试题 ：</u></font></a> <br>main主函数执行完毕后，是否可能会再执行一段代码，给出说明？ <br>参考答案： <br>
            <table style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; MARGIN: 10px; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" cellSpacing=0 cellPadding=10 width="90%">
                <tbody>
                    <tr>
                        <td bgColor=#eeeeee><font face="Courier New"><font color=#003399>crt会执行另一些代码，进行处理工作。 <br>如果你需要加入一段在main退出后执行的代码，可以使用atexit()函数，注册一个函数。 <br>语法： <br>#include &lt;stdlib.h&gt; <br>int atexit(void (*function")(void)); <br>#include &lt;stdlib.h&gt; <br>#include &lt;stdio.h&gt; <br><br>void fn1( void ), fn2( void ), fn3( void ), fn4( void ); <br><br>int main( void ) <br>{ <br>&nbsp;&nbsp;&nbsp; atexit( fn1 ); <br>&nbsp;&nbsp;&nbsp; atexit( fn2 ); <br>&nbsp;&nbsp;&nbsp; atexit( fn3 ); <br>&nbsp;&nbsp;&nbsp; atexit( fn4 ); <br>&nbsp;&nbsp;&nbsp; printf( "This is executed first.\n" ); <br>} <br><br>void fn1() <br>{ <br>&nbsp;&nbsp;&nbsp; printf( "next.\n" ); <br>} <br><br>void fn2() <br>{ <br>&nbsp;&nbsp;&nbsp; printf( "executed " ); <br>} <br><br>void fn3() <br>{ <br>&nbsp;&nbsp;&nbsp; printf( "is " ); <br>} <br><br>void fn4() <br>{ <br>&nbsp;&nbsp;&nbsp; printf( "This " ); <br>} <br></font></font></td>
                    </tr>
                </tbody>
            </table>
            <br><a href="http://community.csdn.net/Expert/topic/3490/3490047.xml?temp=.5590937" target=_blank><font color=#003399><u>五、朗讯面试题 ：</u></font></a> <br>如何判断一段程序是由C编译程序还是由C++编译程序编译的？ <br>参考答案： <br>
            <table style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; MARGIN: 10px; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" cellSpacing=0 cellPadding=10 width="90%">
                <tbody>
                    <tr>
                        <td bgColor=#eeeeee><font face="Courier New"><font color=#003399>c++编译时定义了 __cplusplus <br>c编译时定义了 _STDC_</font></font></td>
                    </tr>
                </tbody>
            </table>
            <br>六、下面这道面试题怎么做（指针）？ <br>
            <table style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; MARGIN: 10px; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" cellSpacing=0 cellPadding=10 width="90%">
                <tbody>
                    <tr>
                        <td bgColor=#eeeeee><font face="Courier New"><font color=#003399>#include&lt;stdio.h&gt; <br>main(){ <br>int c[3][3]={1,2,3,4,5,6,7,8,9}; <br>for(int i=0;i&lt;3;i++) <br>for(int j=0;j&lt;3;j++) <br>printf("%ld\n",&amp;c<em>[j]); <br>printf("-------------------------\n"); <br>printf("%ld\n",(c+1)); <br>printf("%ld\n",(*c+1)); <br>printf("%ld\n",&amp;c[0][0]); <br>printf("%ld\n",**c); <br>printf("%ld\n",*c[0]); <br>if(int(c)==int(*c)) <br>printf("equl"); <br>} <br>为什么c，*c的值相等，（c+1），（*c+1）的值不等 <br>c，*c，**c，代表什么意思？</em></font></font></td>
                    </tr>
                </tbody>
            </table>
            <br><a href="http://community.csdn.net/Expert/topic/3484/3484734.xml?temp=.1186334" target=_blank><font color=#003399><u>参考答案：</u></font></a> <br>
            <table style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; MARGIN: 10px; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" cellSpacing=0 cellPadding=10 width="90%">
                <tbody>
                    <tr>
                        <td bgColor=#eeeeee><font face="Courier New"><font color=#003399>c是第一个元素的地址，*c是第一行元素的首地址，其实第一行元素的地址就是第一个元素的地址，这容易理解。**c是提领第一个元素。 <br>为什么c，*c的值相等？ <br>int c因为直接用c表示数组c[0][0] <br>printf("%ld\n",*c[0]);语句已将指针移到数组头。 <br>int(*c)表示c0的值为1，所以相等。 <br>数组c的存放空间示意如下：（机器中是行优先存放的） <br>c[0][0] c[0][1] c[0][2] <br>c[1][0] c[1][1] c[1][2] <br>c[2][0] c[2][1] c[2][2] <br><br>c是一个二维数组名，实际上它是一个指针常量，不能进行自加、自减运算，即：c++、c--、++c、--c <br>都是不允许的； <br>c： 数组名；是一个二维指针，它的值就是数组的首地址，也即第一行元素的首地址（等于 *c），也 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 等于第一行第一个元素的地址（ &amp; c[0][0]）；可以说成是二维数组的行指针。 <br>*c： 第一行元素的首地址；是一个一维指针，可以说成是二维数组的列指针。 <br>**c：二维数组中的第一个元素的值；即：c[0][0] <br>所以： <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c 和 *c的值是相等的，但他们两者不能相互赋值，（类型不同）； <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; （c + 1） ：c是行指针，（c + 1）是在c的基础上加上二维数组一行的地址长度，即从&amp;c[0][0] <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 变到了&amp;c[1][0]； <br>&nbsp;&nbsp;&nbsp;&nbsp; （*c + 1）：*c是列指针，（*c + 1）是在*c的基础上加上二数组一个元素的所占的长度，即从 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;c[0][0]变到了&amp;c[0][1] <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 从而（c + 1）和（*c + 1）的值就不相等了</font></font></td>
                    </tr>
                </tbody>
            </table>
            <br>七、定义 int **a[3][4], 则变量占有的内存空间为：_____ <br><a href="http://community.csdn.net/Expert/topic/3469/3469185.xml?temp=.8212244" target=_blank><font color=#003399><u>参考答案：</u></font></a> <br>
            <table style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; MARGIN: 10px; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" cellSpacing=0 cellPadding=10 width="90%">
                <tbody>
                    <tr>
                        <td bgColor=#eeeeee><font face="Courier New"><font color=#003399>int **p; /*16位下sizeof(p)=2, 32位下sizeof(p)=4*/ <br>总共 3*4*sizeof(p)</font></font></td>
                    </tr>
                </tbody>
            </table>
            <br>八、编写一个函数，要求输入年月日时分秒，输出该年月日时分秒的下一秒。如输入2004年12月31日23时59分59秒，则输出2005年1月1日0时0分0秒。 <br><a href="http://community.csdn.net/Expert/topic/3469/3469185.xml?temp=.8212244" target=_blank><font color=#003399><u>参考答案：</u></font></a> <br>
            <table style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; MARGIN: 10px; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" cellSpacing=0 cellPadding=10 width="90%">
                <tbody>
                    <tr>
                        <td bgColor=#eeeeee><font face="Courier New"><font color=#003399>判断年份是否是闰年，月份的大小月， <br>月（12进制）、日（与闰年、大小月有关）、时（24进制）、分（60进制）、妙（60进制）</font></font></td>
                    </tr>
                </tbody>
            </table>
            <p>--------------------------------------------------</p>
            <p>汤姆逊的面试试题：怎么快速检测出一个巨大的链表中的死链？</p>
            <p><a href="http://community.csdn.net/Expert/topic/3343/3343269.xml?temp=.509823"><u><font color=#0000ff>http://community.csdn.net/Expert/topic/3343/3343269.xml?temp=.509823</font></u></a></p>
            <p>看到几道面试题,很基础,但不好回答(进入有分) </p>
            <p><a href="http://community.csdn.net/Expert/topic/3451/3451720.xml?temp=9.774417E-02"><u><font color=#0000ff>http://community.csdn.net/Expert/topic/3451/3451720.xml?temp=9.774417E-02</font></u></a></p>
            <p>贴几个经典面试题，怎么做 </p>
            <p><a href="http://community.csdn.net/Expert/topic/3378/3378595.xml?temp=.1972315"><font color=#0000ff><u>http://community.csdn.net/Expert/topic/3378/3378595.xml?temp=.1972315</u></font></a></p>
            <p><a href="http://community.csdn.net/Expert/topic/3356/3356378.xml?temp=.07922" target=_blank><font color=#003399><u>文件操作，读取一组数进行排序然后写入文件</u></font></a> </p>
            <p><a href="http://community.csdn.net/Expert/topic/3356/3356378.xml?temp=.07922"><u><font color=#0000ff>http://community.csdn.net/Expert/topic/3356/3356378.xml?temp=.07922</font></u></a></p>
            <p>一道面试题!在线恭候大家！交换两个数，不用第三块儿内存！请问怎么实现？</p>
            <p>int a,intb</p>
            <p>a ^= b ^= a ^= b;</p>
            <p>a+=b;</p>
            <p>b=a-b;</p>
            <p>a=a-b;</p>
            <p><a href="http://community.csdn.net/Expert/topic/3343/3343124.xml?temp=.1771509"><u><font color=#0000ff>http://community.csdn.net/Expert/topic/3343/3343124.xml?temp=.1771509</font></u></a></p>
            <p>[高分求教]C语言笔试或面试一般会问到什么问题？</p>
            <p><a href="http://community.csdn.net/Expert/topic/3218/3218202.xml?temp=.8798181"><u><font color=#0000ff>http://community.csdn.net/Expert/topic/3218/3218202.xml?temp=.8798181</font></u></a></p>
            <p>&nbsp;&nbsp;&nbsp; 有一个函数里面是大概是这样的。<br>&nbsp;&nbsp;&nbsp;&nbsp; function（a*，b*）｛<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case：变量｛<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; default;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while(........){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 1:&nbsp;&nbsp;&nbsp; a++ ＝ b++；<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 2： a++ ＝ b++；<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 3:&nbsp;&nbsp;&nbsp; a++ ＝ b++；<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 4： a++ ＝ b++； <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 5： a++ ＝ b++；<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 6： a++ ＝ b++；<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ｝<br>&nbsp;&nbsp;&nbsp;&nbsp; ｝<br>问题是这个函数在做什么，看了半天，不明白为什么case 的分项会放到一个循环里。</p>
            <p><a href="http://community.csdn.net/Expert/topic/3313/3313398.xml?temp=5.338687E-02"><u><font color=#0000ff>http://community.csdn.net/Expert/topic/3313/3313398.xml?temp=5.338687E-02</font></u></a><br><br><br><a href="http://community.csdn.net/Expert/topic/3218/3218202.xml?temp=.8798181" target=_blank rel=nofollow><font color=#003399>C/C++笔试提问</font></a> <br><a href="http://community.csdn.net/Expert/topic/3313/3313398.xml?temp=5.338687E-02" target=_blank rel=nofollow><font color=#003399>蛮有意思的题目</font></a> <br><a href="http://community.csdn.net/Expert/topic/3215/3215643.xml?temp=.1959192" target=_blank rel=nofollow><font color=#003399>关于Const常量问题，华为面试题。</font></a> <br><a href="http://community.csdn.net/Expert/topic/3293/3293716.xml?temp=.7074396" target=_blank rel=nofollow><font color=#003399>四个面试问题</font></a> <br><a href="http://community.csdn.net/Expert/topic/3274/3274011.xml?temp=.1997187" target=_blank rel=nofollow><font color=#003399>难度系数、具体的实现算法？</font></a> <br><a href="http://community.csdn.net/Expert/topic/3224/3224699.xml?temp=.2033655" target=_blank rel=nofollow><font color=#003399>两道面试题，最好能提供一个完整的实现代码！</font></a> <br><a href="http://community.csdn.net/Expert/topic/3209/3209258.xml?temp=.7044336" target=_blank rel=nofollow><font color=#003399>求用一段C或C++程序写求 f(x)=100! 的完整程序？</font></a> <br><a href="http://community.csdn.net/Expert/topic/3203/3203144.xml?temp=.2724115" target=_blank rel=nofollow><font color=#003399>25匹马，每次捡5匹跑，几次可找出最快的5匹马？</font></a> <br><a href="http://community.csdn.net/Expert/topic/3169/3169555.xml?temp=.9761927" target=_blank rel=nofollow><font color=#003399>一个面试题 求 n! <br><br></font></a></em></em></em></em></em></p>
            <p>1.给定下面的声明:<br>typedef struct<br>{<br>&nbsp;&nbsp;&nbsp; int x;<br>&nbsp;&nbsp;&nbsp; int y;<br>}Point;</p>
            <p>Point x,y;<br>Point *a=&amp;x, *b=&amp;y;<br>解释下列各语名的含义:<br>a x=y;<br>b a=y;<br>c a=b;<br>d a=*b;<br>e *a=*b;</p>
            <p><br>2.给定下列声明<br>int array[4][5][3];<br>把下列各个指针表达式转换为下标表达式</p>
            <p>表达式&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 下标表达式<br>*array<br>*(array+2)<br>*(array+1)+4<br>*(*(array+1)+4)<br>*(*(*(array+3)+1)+2)<br>*(*(*array+1)+2)<br>*(**array+2)<br>**(*array+1)<br>***array</p>
            <p>&nbsp;</p>
            <p>3.当你拨打长途电话时,电话公司所保存的信息包括你拨打电话的日期和时间.它还包括三个电话号码,<br>:你使用的那个电话,你呼叫的那个电话以及你付帐的那个电话.这些电话号码的每一个都由三个部分组成,<br>:区号,交换台和站号码.请为这些记帐信息编定一个结构声明</p>
            <p>&nbsp;</p>
            <p>4.表达式(a)和(b)的求值过程有没有区别,如果有的话,区别在哪里?假定变量offset的<br>值是3.<br>int i[10];<br>int *p=&amp;i[0];<br>int offset;<br>p+=offset;&nbsp;&nbsp;&nbsp;&nbsp; (a)<br>p+=3;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (b</p>
            <p><a href="http://community.csdn.net/Expert/topic/3293/3293716.xml?temp=.7074396"><u><font color=#0000ff>http://community.csdn.net/Expert/topic/3293/3293716.xml?temp=.7074396</font></u></a></p>
            <p>一道面试题，请大虾们帮忙评测一下：难度系数、具体的实现算法，谢谢</p>
            <p><a href="http://community.csdn.net/Expert/topic/3274/3274011.xml?temp=.1997187"><u><font color=#0000ff>http://community.csdn.net/Expert/topic/3274/3274011.xml?temp=.1997187</font></u></a></p>
            <p>1. Project Assignment -- Bounded Buffer Producer Consumer</p>
            <p>Implement the bounded buffer producer and consumer problem and write a<br>simulation on your implementation. The size of the bounded buffer<br>should be adjustable at initialization. You can assume that the type<br>of the item produced and consumed is of an integer type, and that<br>producers produce a sequence of integers. The simulation should<br>include multiple producers and multiple consumers sharing the same<br>bounded buffer. Run the simulation for 10000 iterations, in each of<br>which an item is produced or consumed.</p>
            <p>2. Project Assignment -- The Shell</p>
            <p>Write the UNIX shell. Even the simplest of real UNIX shells is<br>thousands of lines of C code. Don&#8217;t worry, you will be writing a<br>minuscule, super-simplified shell. Your shell shall accept lines of<br>input from standard input until EOF. Don&#8217;t worry about issuing a<br>prompt, command-line editing, etc. Each line is a command to be<br>executed. The shell should fork to create a new process in which to<br>run the command, exec the program, wait for and report the exit<br>status, and report the user and system time consumed by the<br>command. You may assume that each command is formatted as follows:</p>
            <p>command {argument {argument...} }</p>
            <p>The above optional arguments are whitespace-delimited, i.e. they are<br>separated by one or more tabs or spaces. This will simplify parsing. A<br>line that begins with the # character is a comment and should be<br>ignored.<br></p>
            <p><a href="http://community.csdn.net/Expert/topic/3224/3224699.xml?temp=.2033655"><u><font color=#0000ff>http://community.csdn.net/Expert/topic/3224/3224699.xml?temp=.2033655</font></u></a></p>
            <p>面试题:求用一段C或C++程序写求 f(x)=100! 的完整程序</p>
            <p><a href="http://community.csdn.net/Expert/topic/3209/3209258.xml?temp=.7044336"><u><font color=#0000ff>http://community.csdn.net/Expert/topic/3209/3209258.xml?temp=.7044336</font></u></a></p>
            <p>25匹马，每次捡5匹跑，几次可找出最快的5匹马？</p>
            <p><a href="http://community.csdn.net/Expert/topic/3203/3203144.xml?temp=.2724115"><u><font color=#0000ff>http://community.csdn.net/Expert/topic/3203/3203144.xml?temp=.2724115</font></u></a></p>
            <p>一个面试题 求 n! （n的阶层）需要考虑溢出</p>
            <p><a href="http://community.csdn.net/Expert/topic/3169/3169555.xml?temp=.9761927"><u><font color=#0000ff>http://community.csdn.net/Expert/topic/3169/3169555.xml?temp=.9761927</font></u></a><br><br><br><br>
            <table style="WIDTH: 600px" cellSpacing=1 cellPadding=1 border=0>
                <tbody>
                    <tr>
                        <td colSpan=3>
                        <div id=relative_posts><strong>相关文章:</strong><br><script language=javascript src="http://zzk.cnblogs.com:8080/RCS?tp=0&amp;tt=%5b%e6%94%b6%e9%9b%86%5d+%e7%bb%8f%e5%85%b8C%2fC%2b%2b%e9%9d%a2%e8%af%95%e9%a2%98%ef%bc%88%e5%85%ad%ef%bc%89&amp;tg=&amp;ct=%e9%9d%a2%e8%af%95&amp;url=http%3a%2f%2fwww.cnblogs.com%2fForEverKissing%2farchive%2f2008%2f07%2f04%2f1235392.html" type=text/javascript charset=utf-8></script><a href="http://kb.cnblogs.com/page/42065/" target=_blank><font color=#1a8bc8>小菜编程成长记（一 面试受挫——代码无错就是好？）</font></a><br><a href="http://kb.cnblogs.com/page/42193/" target=_blank><font color=#1a8bc8>面试技巧问题：面试典型问题回答技巧</font></a><br><a href="http://www.cnblogs.com/zxj911/archive/2005/03/09/115379.html" target=_blank><font color=#1a8bc8>张小娴的经典句子 </font></a><br><a href="http://www.cnblogs.com/lixyvip/archive/2007/11/30/978192.html" target=_blank><font color=#1a8bc8>C#下如何实现服务器+客户端的聊天程序</font></a><br><a href="http://news.cnblogs.com/n/43333/" target=_blank><font color=#1a8bc8>Google将使用OCR技术索引收集文档信息</font></a><br><a href="http://space.cnblogs.com/question/692/" target=_blank><font color=#1a8bc8>如何面试考查网站运营经理，请大家指点下。</font></a><br><a href="http://space.cnblogs.com/question/1871/" target=_blank><font color=#1a8bc8>求.net面试题目</font></a><br><a href="http://space.cnblogs.com/group/topic/5660/" target=_blank><font color=#1a8bc8>&#8220;蛮力推广&#8221;引爆IT面试书</font></a><br><a href="http://space.cnblogs.com/group/topic/2084/" target=_blank><font color=#1a8bc8>编程之美——微软技术面试心得</font></a></div>
                        </td>
                    </tr>
                    <tr>
                        <td colSpan=3>
                        <div id=div_a4_ads><br><strong>相关链接:</strong> <script type=text/javascript>
                        var title = document.title;
                        document.write("
                        <div id=\"a4_ads_output\">");
                        document.write("
                        <script type='text/javascript' src='http://a4.yeshj.com/adwords/EN017?num=7&title="+ encodeURIComponent(title) +"&tag="+ encodeURIComponent(GetMeta("keywords")) +"'></scri"+"pt>");
                        document.write("</div>
                        ");
                        </script>
                        <div id=a4_ads_output><script src="http://a4.yeshj.com/adwords/EN017?num=7&amp;title=%5B%E6%94%B6%E9%9B%86%5D%20%E7%BB%8F%E5%85%B8C%2FC%2B%2B%E9%9D%A2%E8%AF%95%E9%A2%98%EF%BC%88%E5%85%AD%EF%BC%89%20-%20%E6%8C%A5%E7%9D%80%E5%B0%8F%E9%B8%9F%E7%9A%84%E7%BF%85%E8%86%80%20-%20%E5%8D%9A%E5%AE%A2%E5%9B%AD&amp;tag=%E6%94%B6%E9%9B%86%2C%E7%BB%8F%E5%85%B8C%2CC%2C%E9%9D%A2%E8%AF%95%E9%A2%98%2C%E5%85%AD" type=text/javascript></script></div>
                        <a href="http://a4.yeshj.com/rd?aid=17831&amp;zid=0&amp;url=http%3a%2f%2fts.hjenglish.com%2fmusic%2f54077%2f" target=_blank><font color=#1a8bc8>经典乡村：隐形的翅膀 Rascal Flatts</font></a><br><a href="http://a4.yeshj.com/rd?aid=16893&amp;zid=0&amp;url=http%3a%2f%2fwww.cnblogs.com%2fdflying%2farticles%2f364458.html" target=_blank><font color=#1a8bc8>C#面试基础问题</font></a><br><a href="http://a4.yeshj.com/rd?aid=14806&amp;zid=0&amp;url=http%3a%2f%2fzt.hjbook.net%2fzt%2f09kydagang%2f" target=_blank><font color=#1a8bc8>考研英语高分作文经典背诵100篇</font></a><br><a href="http://a4.yeshj.com/rd?aid=18241&amp;zid=0&amp;url=http%3a%2f%2fa8.yeshj.com%2fzt%2f365English%2f" target=_blank><font color=#1a8bc8>来这里，免费获得经典《商务口语》正版CD</font></a><br><a href="http://a4.yeshj.com/rd?aid=15219&amp;zid=0&amp;url=http%3a%2f%2fwww.hjbook.net%2fproduct%2f2289" target=_blank><font color=#1a8bc8>08年博客园纪念T恤珍藏版</font></a><br><a href="http://a4.yeshj.com/rd?aid=16983&amp;zid=0&amp;url=http%3a%2f%2fa8.yeshj.com%2fzt%2fsakura%2f" target=_blank><font color=#1a8bc8>流利口语+面试技巧</font></a><br><a href="http://a4.yeshj.com/rd?aid=14857&amp;zid=0&amp;url=http%3a%2f%2fbulo.hjenglish.com%2fmenu%2f1164" target=_blank><font color=#1a8bc8>概率经典例题38道</font></a><br></div>
                        </td>
                    </tr>
                    <tr>
                        <td colSpan=3><font color=#1a8bc8></font></td>
                    </tr>
                    <tr>
                        <td colSpan=3>
                        <div id=AjaxHolder_PostComment_RelativePosts1_divRelativePosts style="MARGIN-TOP: 2px"><br><strong>所属分类的其他文章:</strong><br><span style="LIST-STYLE-TYPE: none"><a href="http://www.cnblogs.com/ForEverKissing/archive/2008/08/06/1261689.html"><font color=#1a8bc8>[收集] 工作面试时最难的25个问题</font></a><br></span><span style="LIST-STYLE-TYPE: none"><a href="http://www.cnblogs.com/ForEverKissing/archive/2008/07/29/1255408.html"><font color=#1a8bc8>[转] 面试必问的16个经典问题的回答思路</font></a><br></span><span style="DISPLAY: none; LIST-STYLE-TYPE: none"><a href="http://www.cnblogs.com/ForEverKissing/archive/2008/07/04/1235392.html"><font color=#1a8bc8>[收集] 经典C/C++面试题（六）</font></a><br></span><span style="LIST-STYLE-TYPE: none"><a href="http://www.cnblogs.com/ForEverKissing/archive/2008/06/19/1226048.html"><font color=#1a8bc8>[收集] 经典C/C++面试题（五） </font></a><br></span><span style="LIST-STYLE-TYPE: none"><a href="http://www.cnblogs.com/ForEverKissing/archive/2008/06/19/1226041.html"><font color=#1a8bc8>[收集] 经典C/C++面试题（四） </font></a><br></span><span style="LIST-STYLE-TYPE: none"><a href="http://www.cnblogs.com/ForEverKissing/archive/2008/06/19/1226013.html"><font color=#1a8bc8>[收集] 经典C/C++面试题（三） </font></a><br></span><span style="LIST-STYLE-TYPE: none"><a href="http://www.cnblogs.com/ForEverKissing/archive/2008/06/19/1226011.html"><font color=#1a8bc8>[收集] 经典C/C++面试题（二） </font></a><br></span><span style="LIST-STYLE-TYPE: none"><a href="http://www.cnblogs.com/ForEverKissing/archive/2008/06/19/1226009.html"><font color=#1a8bc8>[收集] 经典C/C++面试题（一）</font></a><br></span><span style="LIST-STYLE-TYPE: none"><a href="http://www.cnblogs.com/ForEverKissing/archive/2008/02/13/1067956.html"><font color=#1a8bc8>[转] 外企面试官最爱提的问题 TOP10</font></a><br></span></div>
                        <div class=itnews><br><strong>最新IT新闻:</strong><br><a href="http://news.cnblogs.com/n/43469/" target=_blank><font color=#1a8bc8>百度遭遇中国网络反垄断调查第一案</font></a><br><a href="http://news.cnblogs.com/n/43467/" target=_blank><font color=#1a8bc8>红杉资本1500万美元投向图片存储网ImageShack</font></a><br><a href="http://news.cnblogs.com/n/43466/" target=_blank><font color=#1a8bc8>LinkedIn推出社交事件功能 可向用户智能推荐</font></a><br><a href="http://news.cnblogs.com/n/43465/" target=_blank><font color=#1a8bc8>玩游戏成瘾被正式纳入精神病诊断范畴</font></a><br><a href="http://news.cnblogs.com/n/43464/" target=_blank><font color=#1a8bc8>微软发布Windows 7产品路线图 简体中文版靠前</font></a><br></div>
                        </td>
                    </tr>
                </tbody>
            </table>
            <br><br><br><br><br><br><br></p>
            </div>
            </td>
        </tr>
    </tbody>
</table>
<img src ="http://www.cnitblog.com/qlb5626267/aggbug/51269.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/qlb5626267/" target="_blank">龙霖</a> 2008-11-09 22:53 <a href="http://www.cnitblog.com/qlb5626267/articles/51269.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++中const的使用</title><link>http://www.cnitblog.com/qlb5626267/articles/51263.html</link><dc:creator>龙霖</dc:creator><author>龙霖</author><pubDate>Sun, 09 Nov 2008 11:52:00 GMT</pubDate><guid>http://www.cnitblog.com/qlb5626267/articles/51263.html</guid><wfw:comment>http://www.cnitblog.com/qlb5626267/comments/51263.html</wfw:comment><comments>http://www.cnitblog.com/qlb5626267/articles/51263.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/qlb5626267/comments/commentRss/51263.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/qlb5626267/services/trackbacks/51263.html</trackback:ping><description><![CDATA[<p>&nbsp; 这是我在CSDN的第一篇博文。近日学习C++，应该说接触C++有一年多了，但从来没有系统的学习一遍，VC++开发技术也学了，但学习VC并不能提高C++技能，VC开发只是C++的一种应用，学习VC学不到C++的精髓，所以我要好好的把C++系统的学一遍，我发现C++确实比VC有魅力，希望自己能学有所成。</p>
<p>下面是关于C++基本概念的一篇文章——C++中const的使用</p>
<p><br>关于C++中的const关键字的用法非常灵活，而使用const将大大改善程序的健壮性。在网上搜寻相关主题，发现大多数文章雷同，而关键地方并不是很清楚。在网络资料，参考书的基础上，结合本人的一些体会总结如下，期望对大家有所帮助： <br>一 const基础<br>下面四个定义语句是大多数书籍讲解const关键字都会用到的，<br>[1]const int* a = &amp;b;<br>[2]int const *a = &amp;b;<br>[3]int* const a = &amp;b;<br>[4]const int* const a = &amp;b;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如果你能区分出上述四种情况，证明你基础不错，不过也不要高兴太早，这个只是最基础的部分了。不知道也很容易：如果const位于星号的左侧（不管const在类型修饰符的左还是右），则const就是用来修饰指针所指向的变量，即指针指向为常量；如果const位于星号的右侧，const就是修饰指针本身，即指针本身是常量。[1]和[2]的情况相同，都是指针所指向的内容为常量，这种情况下不允许对内容进行更改操作，如不能*a = 3 ；这样的一种声明方式的作用是可以修改pi这个指针所指向的内存地址却不能修改指向对象的值；[3]为指针本身是常量，而指针所指向的内容不是常量，这种情况下不能对指针本身进行更改操作，如a++是错误的;[4]为指针本身和指向的内容均为常量。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 另外const 的一些强大的功能在于它在函数声明中的应用。在一个函数声明中，const 可以修饰函数的返回值，或某个参数；对于成员函数，还可以修饰是整个函数。有如下几种情况，以下会逐渐的说明用法：<br>A_class&amp; operator=(const A_class&amp; a);&nbsp;&nbsp;&nbsp;&nbsp; //A_class 为一个已经定义的类，下文同<br>void fun0(const A_class* a ); <br>void fun1( ) const;&nbsp;&nbsp;&nbsp;&nbsp; // fun1( ) 为类成员函数<br>const A_class fun2( );<br>二 const的初始化<br>先看一下const变量初始化的情况<br>1) 非指针const常量初始化的情况：<br>A_class b; <br>const A_class a = b;<br>2) 指针(引用)const常量初始化的情况：<br>A_class* d = new A_class();&nbsp;&nbsp;&nbsp; <br>const A_class* c = d;<br>或者,<br>const A_class* c = new A_class();<br>引用：&nbsp;&nbsp;&nbsp; <br>A_class f;&nbsp;&nbsp;&nbsp; <br>const A_class&amp; e = f;&nbsp;&nbsp;&nbsp; // 这样作e只能访问声明为const的函数，而不能访问一般的成员函数；<br>[思考1]： 以下的这种赋值方法正确吗？<br>const A_class* c=new A_class();<br>A_class* e = c;<br>这种方法不正确，因为声明指针的目的是为了对其指向的内容进行改变，而声明的指针e指向的是一个常量，所以不正确；<br>[思考2]： 以下的这种赋值方法正确吗？<br>A_class* const c = new A_class();<br>A_class* b = c;<br>这种方法正确，因为声明指针所指向的内容可变；</p>
<p>三 作为参数和返回值的const修饰符</p>
<p>其实，不论是参数还是返回值，道理都是一样的，参数传入时候和函数返回的时候，初始化const变量<br>1 修饰参数的const,如,<br>void fun0(const A_class* a ); <br>void fun1(const A_class&amp; a);<br>调用函数的时候，用相应的变量初始化const常量，则在函数体中，按照const所修饰的部分进行常量化，如形参为const A_class* a，则不能对传递进来的指针的内容进行改变，保护了原指针所指向的内容；如形参为const A_class&amp; a，则不能对传递进来的引用对象进行改变，保护了原对象的属性。<br>[注意]：参数const通常用于参数为指针或引用的情况;<br>2 修饰返回值的const，如,<br>const A_class fun2( ); const A_class* fun3( );<br>这样声明了返回值后，const按照"修饰原则"进行修饰，起到相应的保护作用。<br>const Rational operator*(const Rational&amp; lhs, const Rational&amp; rhs)<br>{<br>return Rational(lhs.numerator() * rhs.numerator(), lhs.denominator() * rhs.denominator());<br>}<br>返回值用const修饰可以防止这样的操作发生:<br>Rational a,b;<br>Radional c;<br>(a*b) = c;<br>一般用const修饰返回值为对象本身（非引用和指针）的情况多用于二目操作符重载函数并产生新对象的时候。<br>[总结]一般情况下，函数的返回值为某个对象时，如果将其声明为const时，多用于操作符的重载。<br>通常，不建议用const修饰函数的返回值类型为某个对象或对某个对象引用的情况。<br>原因如下：如果返回值为某个对象为const（const A_class test = A_class 实例）或某个对象的引用为const（const A_class&amp; test = A_class实例） ，则返回值具有const属性，则返回实例只能访问类A_class中的公有（保护）数据成员和const成员函数，并且不允许对其进行赋值操作，这在一般情况下很少用到。<br>[思考3]： 这样定义赋值操作符重载函数可以吗？<br>const A_class&amp; operator=(const A_class&amp; a);<br>不正确；在const A_class::operator=(const A_class&amp; a)中，参数列表中的const的用法正确，而当这样连续赋值的时侯，问题就出现了：A_class a,b,c:(a=b)=c;因为a.operator=(b)的返回值是对a的const引用，不能再将c赋值给const常量。 </p>
<p>四 类成员函数中const的使用<br>一般放在函数体后，形如：<br>void fun() const;<br>如果一个成员函数的不会修改数据成员，那么最好将其声明为const，因为const成员函数中不允许对数据成员进行修改，如果修改，编译器将报错，这大大提高了程序的健壮性。</p>
<p>五 使用const的一些建议<br>1 要大胆的使用const，这将给你带来无尽的益处，但前提是你必须搞清楚原委；<br>2 要避免最一般的赋值操作错误，如将const变量赋值，具体可见思考题；<br>3 在参数中使用const应该使用引用或指针，而不是一般的对象实例，原因同上；<br>4 const在成员函数中的三种用法（参数、返回值、函数）要很好的使用；<br>5 不要轻易的将函数的返回值类型定为const;6除了重载操作符外一般不要将返回值类型定为对某个对象的const引用;</p>
<p><br>文章出处：<a href="http://www.diybl.com/course/3_program/c++/cppsl/2007104/75983.html">http://www.diybl.com/course/3_program/c++/cppsl/2007104/75983.html</a></p>
<img src ="http://www.cnitblog.com/qlb5626267/aggbug/51263.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/qlb5626267/" target="_blank">龙霖</a> 2008-11-09 19:52 <a href="http://www.cnitblog.com/qlb5626267/articles/51263.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>typedef和#define的用法与区别</title><link>http://www.cnitblog.com/qlb5626267/articles/51262.html</link><dc:creator>龙霖</dc:creator><author>龙霖</author><pubDate>Sun, 09 Nov 2008 11:28:00 GMT</pubDate><guid>http://www.cnitblog.com/qlb5626267/articles/51262.html</guid><wfw:comment>http://www.cnitblog.com/qlb5626267/comments/51262.html</wfw:comment><comments>http://www.cnitblog.com/qlb5626267/articles/51262.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/qlb5626267/comments/commentRss/51262.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/qlb5626267/services/trackbacks/51262.html</trackback:ping><description><![CDATA[<table cellSpacing=3 cellPadding=0 width=760 align=center border=0>
    <tbody>
        <tr>
            <td vAlign=top>
            <table width="100%">
                <tbody>
                    <tr>
                        <td align=middle><!--baidu广告开始--><script language=javascript src="/ad/contentg.js"></script><!--baidu广告结束--></td>
                    </tr>
                    <tr>
                        <td class=bf14>
                        <p><strong>一、typedef的用法</strong></p>
                        <p>&nbsp;&nbsp;&nbsp;在C/C++语言中，typedef常用来定义一个标识符及关键字的别名，它是语言编译过程的一部分，但它并不实际分配内存空间，实例像：</p>
                        <p>&nbsp;&nbsp;&nbsp;typedef&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INT;<br>&nbsp;&nbsp;&nbsp;typedef&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ARRAY[10];<br>&nbsp;&nbsp;&nbsp;typedef&nbsp;&nbsp; (int*)&nbsp;&nbsp; pINT;</p>
                        <p>typedef可以增强程序的可读性，以及标识符的灵活性，但它也有&#8220;非直观性&#8221;等缺点。</p>
                        <p><strong>二、#define的用法</strong></p>
                        <p>&nbsp;&nbsp;&nbsp;#define为一宏定义语句，通常用它来定义常量(包括无参量与带参量)，以及用来实现那些&#8220;表面似和善、背后一长串&#8221;的宏，它本身并不在编译过程中进行，而是在这之前(预处理过程)就已经完成了，但也因此难以发现潜在的错误及其它代码维护问题，它的实例像：</p>
                        <p>#define&nbsp;&nbsp; INT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int<br>#define&nbsp;&nbsp; TRUE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br>#define&nbsp;&nbsp; Add(a,b)&nbsp;&nbsp;&nbsp;&nbsp; ((a)+(b));<br>#define&nbsp;&nbsp; Loop_10&nbsp;&nbsp;&nbsp; for (int i=0; i&lt;10; i++)</p>
                        <p>&nbsp;&nbsp;&nbsp;在Scott Meyer的Effective C++一书的条款1中有关于#define语句弊端的分析，以及好的替代方法，大家可参看。</p>
                        <p><strong>三、typedef与#define的区别</strong></p>
                        <p>&nbsp;&nbsp;&nbsp;从以上的概念便也能基本清楚，typedef只是为了增加可读性而为标识符另起的新名称(仅仅只是个别名)，而#define原本在C中是为了定义常量，到了C++，const、enum、inline的出现使它也渐渐成为了起别名的工具。有时很容易搞不清楚与typedef两者到底该用哪个好，如#define INT int这样的语句，用typedef一样可以完成，用哪个好呢？我主张用typedef，因为在早期的许多C编译器中这条语句是非法的，只是现今的编译器又做了扩充。为了尽可能地兼容，一般都遵循#define定义&#8220;可读&#8221;的常量以及一些宏语句的任务，而typedef则常用来定义关键字、冗长的类型的别名。</p>
                        <p>&nbsp;&nbsp;&nbsp;宏定义只是简单的字符串代换(原地扩展)，而typedef则不是原地扩展，它的新名字具有一定的封装性，以致于新命名的标识符具有更易定义变量的功能。请看上面第一大点代码的第三行：</p>
                        <p>typedef&nbsp;&nbsp;&nbsp; (int*)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pINT;<br>以及下面这行:<br>#define&nbsp;&nbsp;&nbsp; pINT2&nbsp;&nbsp;&nbsp; int*</p>
                        <p>效果相同？实则不同！实践中见差别：pINT a,b;的效果同int *a; int *b;表示定义了两个整型指针变量。而pINT2 a,b;的效果同int *a, b;表示定义了一个整型指针变量a和整型变量b。</p>
                        </td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
    </tbody>
</table>
<img src ="http://www.cnitblog.com/qlb5626267/aggbug/51262.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/qlb5626267/" target="_blank">龙霖</a> 2008-11-09 19:28 <a href="http://www.cnitblog.com/qlb5626267/articles/51262.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>