<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3633095353052479181</id><updated>2011-11-28T08:53:42.822+08:00</updated><category term='java'/><category term='C/C++'/><title type='text'>Hello World !</title><subtitle type='html'>学习工作笔记</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://helloworld-world.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://helloworld-world.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Pern</name><uri>http://www.blogger.com/profile/14279149889893810974</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>14</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3633095353052479181.post-4927209654733113646</id><published>2007-10-20T22:54:00.000+08:00</published><updated>2007-10-20T22:57:18.600+08:00</updated><title type='text'>今后所有关于语言学习的文章将直接发布至google文档</title><content type='html'>如题 &lt;a href="http://docs.google.com"&gt;http://docs.google.com&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3633095353052479181-4927209654733113646?l=helloworld-world.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://helloworld-world.blogspot.com/feeds/4927209654733113646/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3633095353052479181&amp;postID=4927209654733113646' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/4927209654733113646'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/4927209654733113646'/><link rel='alternate' type='text/html' href='http://helloworld-world.blogspot.com/2007/10/google.html' title='今后所有关于语言学习的文章将直接发布至google文档'/><author><name>Pern</name><uri>http://www.blogger.com/profile/14279149889893810974</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3633095353052479181.post-1860042194190047074</id><published>2007-10-19T00:06:00.000+08:00</published><updated>2007-10-19T00:12:30.609+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>关于C++类的拷贝构造函数</title><content type='html'>&lt;code&gt;&lt;pre&gt;&lt;br /&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;class A&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;   A() {cout &amp;lt;&amp;lt; "A()" &amp;lt;&amp;lt; endl;}&lt;br /&gt;   A(const A&amp;amp; a){ cout &amp;lt;&amp;lt; "A(const A&amp;amp; a)" &amp;lt;&amp;lt; endl;}&lt;br /&gt;   void print() const {cout &amp;lt;&amp;lt; "print in A" &amp;lt;&amp;lt; endl;}&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;class B : public A&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;   B() {cout &amp;lt;&amp;lt; "B()" &amp;lt;&amp;lt; endl;}&lt;br /&gt;   B(const B&amp;amp; a){ cout &amp;lt;&amp;lt; "B(const A&amp;amp; a)" &amp;lt;&amp;lt; endl;}&lt;br /&gt;   void print() const {cout &amp;lt;&amp;lt; "print in B" &amp;lt;&amp;lt; endl;}&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;void printByValue(A a)&lt;br /&gt;{&lt;br /&gt;   a.print();&lt;br /&gt;}&lt;br /&gt;void printByRef(const A&amp;amp; a)&lt;br /&gt;{&lt;br /&gt;   a.print();&lt;br /&gt;}&lt;br /&gt;int main(int argc, char* argv[])&lt;br /&gt;{&lt;br /&gt;   A a;&lt;br /&gt;   printByValue(a);&lt;br /&gt;   printByRef(a);&lt;br /&gt;   B b;&lt;br /&gt;   printByValue(b);&lt;br /&gt;   printByRef(b);&lt;br /&gt;   a = b;&lt;br /&gt;   printByValue(a);&lt;br /&gt;   printByRef(a);&lt;br /&gt;&lt;br /&gt;   return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;结果为：&lt;br /&gt;A()&lt;br /&gt;A(const A&amp;amp; a)&lt;br /&gt;print in A&lt;br /&gt;print in A&lt;br /&gt;A()&lt;br /&gt;B()&lt;br /&gt;A(const A&amp;amp; a)&lt;br /&gt;print in A&lt;br /&gt;print in A&lt;br /&gt;A(const A&amp;amp; a)&lt;br /&gt;print in A&lt;br /&gt;print in A&lt;br /&gt;&lt;br /&gt;注：函数参数直接传值和“=”赋值均会调用拷贝构造函数。&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3633095353052479181-1860042194190047074?l=helloworld-world.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://helloworld-world.blogspot.com/feeds/1860042194190047074/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3633095353052479181&amp;postID=1860042194190047074' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/1860042194190047074'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/1860042194190047074'/><link rel='alternate' type='text/html' href='http://helloworld-world.blogspot.com/2007/10/c.html' title='关于C++类的拷贝构造函数'/><author><name>Pern</name><uri>http://www.blogger.com/profile/14279149889893810974</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3633095353052479181.post-2914348193600991715</id><published>2007-08-10T17:26:00.001+08:00</published><updated>2008-09-25T14:41:04.479+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>关于自定义类型名与变量名</title><content type='html'>今天看linux的源代码，居然发现一个地方自定义的类型名与变量名重名！试了一下，果然如此：&lt;code&gt;&lt;/code&gt;&lt;pre&gt;#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;&lt;br /&gt;struct S&lt;br /&gt;{&lt;br /&gt;   int i;&lt;br /&gt;};&lt;br /&gt;typedef int I;&lt;br /&gt;class C&lt;br /&gt;{&lt;br /&gt;   int j;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;   S S;&lt;br /&gt;   S.i = 4;&lt;br /&gt;&lt;br /&gt;   I I;&lt;br /&gt;   I = 4;&lt;br /&gt;   cout &amp;lt;&amp;lt; I &amp;lt;&amp;lt; endl;&lt;br /&gt;&lt;br /&gt;   C C;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;以上程序是正确的，能通过编译。&lt;br /&gt;另注：&lt;br /&gt;若如此使用了，接下来的程序若再次用，比如说，类C定义变量，则必须像这样用：&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;class&lt;/span&gt; C cx;&lt;/span&gt;&lt;br /&gt;而用&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;C cx;&lt;/span&gt;&lt;br /&gt;则会报错！&lt;br /&gt;（如果此时是typedef，而不是class或是struct，该怎么使用呢？）&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3633095353052479181-2914348193600991715?l=helloworld-world.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://helloworld-world.blogspot.com/feeds/2914348193600991715/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3633095353052479181&amp;postID=2914348193600991715' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/2914348193600991715'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/2914348193600991715'/><link rel='alternate' type='text/html' href='http://helloworld-world.blogspot.com/2007/08/blog-post.html' title='关于自定义类型名与变量名'/><author><name>Pern</name><uri>http://www.blogger.com/profile/14279149889893810974</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3633095353052479181.post-8670092013051795940</id><published>2007-04-01T20:15:00.000+08:00</published><updated>2007-04-01T20:20:50.940+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>关于变量名空间的一小点</title><content type='html'>在C/C++中，变量名与(类名、结构名、typedef定义的类型名)属于不同的名空间。因此它们是可以相同的。如：&lt;br /&gt;&lt;code&gt;&lt;/code&gt;&lt;pre&gt;struct S { ... };&lt;br /&gt;class C { ... };&lt;br /&gt;typedef int INT;&lt;br /&gt;&lt;br /&gt;S S;   // right&lt;br /&gt;C C;   // right&lt;br /&gt;INT INT = 3;  // right&lt;/pre&gt;&lt;code&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3633095353052479181-8670092013051795940?l=helloworld-world.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://helloworld-world.blogspot.com/feeds/8670092013051795940/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3633095353052479181&amp;postID=8670092013051795940' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/8670092013051795940'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/8670092013051795940'/><link rel='alternate' type='text/html' href='http://helloworld-world.blogspot.com/2007/04/blog-post.html' title='关于变量名空间的一小点'/><author><name>Pern</name><uri>http://www.blogger.com/profile/14279149889893810974</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3633095353052479181.post-5723913964881395249</id><published>2007-03-21T21:11:00.000+08:00</published><updated>2007-03-21T22:12:48.070+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>重拾java（3）：继承</title><content type='html'>❁java不支持多继承&lt;br /&gt;&lt;br /&gt;❁子类不能访问父类中声明为private的类成员&lt;br /&gt;&lt;br /&gt;❁java与C++中均一样，父类引用不能访问仅在子类中定义的函数或变量：&lt;code&gt;&lt;pre&gt;public class t2 {&lt;br /&gt; public static void main(String args[]) {&lt;br /&gt;  F p = new S();&lt;br /&gt;  int i = p.s;  // wrong&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class F {&lt;br /&gt; int f;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class S extends F {&lt;br /&gt; int s;&lt;br /&gt;}&lt;/pre&gt;&lt;/code&gt;❁super()必须永远是一个子类构造函数内执行的第一条语句。如下面的程序将会报错：&lt;code&gt;&lt;pre&gt;class S extends F {&lt;br /&gt; int s;&lt;br /&gt; S() {&lt;br /&gt;  int u;&lt;br /&gt;  super();  // Wrong! Constructor &lt;br /&gt;            call must be the first &lt;br /&gt;            statement in a constructor&lt;br /&gt;  int k;&lt;br /&gt; }&lt;br /&gt;}&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;因为构造函数按派生顺序，从超类到子类被调用。&lt;br /&gt;&lt;br /&gt;❁如下程序例1。父类中的变量虽被覆盖，但p仍访问的是父类变量。而父类中的方法却被覆盖，因此p.pr()访问的是子类函数，类似于C++中的虚函数。这一点非常奇怪。因为在C++中，不管是变量还是函数，它们都是统一的，要覆盖就都会被覆盖，像这种动态的函数调用必须通过virtual来声明。另：C++中类中变量不能为virtual，只能是函数才可以用virtual修饰。这也许是java中要如此分开对待的原因吧。&lt;code&gt;&lt;pre&gt;public class t2 {&lt;br /&gt; public static void main(String args[]) {&lt;br /&gt;  F p = new S();&lt;br /&gt;  System.out.println(p.i);   // 1 父亲中的变量&lt;br /&gt;  p.pr();  // In S...  儿子的方法&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class F {&lt;br /&gt; int f;&lt;br /&gt; int i;&lt;br /&gt; F() {&lt;br /&gt;  ;&lt;br /&gt; }&lt;br /&gt; void pr()&lt;br /&gt; { System.out.println("In F..."); }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class S extends F {&lt;br /&gt; int s;&lt;br /&gt; int i;&lt;br /&gt; S() {&lt;br /&gt;  super.i = 1;&lt;br /&gt;  i = 2;&lt;br /&gt; }&lt;br /&gt; void pr()&lt;br /&gt; { System.out.println("In S..."); }&lt;br /&gt;}&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;例2：&lt;code&gt;&lt;pre&gt;public class t2 {&lt;br /&gt; public static void main(String args[]) {&lt;br /&gt;  F p1 = new S();&lt;br /&gt;  System.out.println(p1.i);   // 1&lt;br /&gt;  &lt;br /&gt;  S p2 = new S();&lt;br /&gt;  System.out.println(p2.i);   // 2&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;class F {&lt;br /&gt; int f;&lt;br /&gt; int i;&lt;br /&gt; F() {&lt;br /&gt;  ;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;class S extends F {&lt;br /&gt; int s;&lt;br /&gt; int i;&lt;br /&gt; S() {&lt;br /&gt;  super.i = 1;&lt;br /&gt;  i = 2;&lt;br /&gt; }&lt;br /&gt;}&lt;/pre&gt;&lt;/code&gt;❁抽象abstract：&lt;br /&gt;子类必须实现父类中所有的抽象函数。&lt;br /&gt;包含一个或多个抽象方法的任何类也必须被声明为抽象的。&lt;br /&gt;不能声明抽象构造函数或抽象静态方法。&lt;br /&gt;抽象类虽不可被实例化，但可以被用来创建对象引用。&lt;br /&gt;同C++中virtual类似，abstract不能用来修饰类中变量，而只能是函数。&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3633095353052479181-5723913964881395249?l=helloworld-world.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://helloworld-world.blogspot.com/feeds/5723913964881395249/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3633095353052479181&amp;postID=5723913964881395249' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/5723913964881395249'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/5723913964881395249'/><link rel='alternate' type='text/html' href='http://helloworld-world.blogspot.com/2007/03/java3.html' title='重拾java（3）：继承'/><author><name>Pern</name><uri>http://www.blogger.com/profile/14279149889893810974</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3633095353052479181.post-6699768997576354192</id><published>2007-03-21T12:02:00.000+08:00</published><updated>2007-03-21T21:10:11.794+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>重拾java（2）</title><content type='html'>1、类型&lt;br /&gt;(1) 自动类型提升&lt;br /&gt;&lt;code&gt;&lt;pre&gt;byte a = 40;&lt;br /&gt;byte b = 50;&lt;br /&gt;byte c = 100;&lt;br /&gt;int d = a * b / c;   // a、b、c在计算中，&lt;br /&gt;                     其类型自动提升为int型&lt;br /&gt;System.out.println(d);&lt;br /&gt;&lt;br /&gt;byte e = 5;&lt;br /&gt;e = e * e;   // wrong. Type mismatch: cannot &lt;br /&gt;                convert from int to byte&lt;br /&gt;byte a = 64, b;&lt;br /&gt;b = (byte)(a &amp;lt;&amp;lt; 2); &lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;一个浮点文字自动为double，如：&lt;br /&gt;&lt;code&gt;&lt;pre&gt;float ff = 3.55; //wrong&lt;br /&gt;float f = 5 / 3 + 7.88;   //wrong! Type mismatch: &lt;br /&gt;                            cannot convert from &lt;br /&gt;                            double to float&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;应该为：&lt;br /&gt;&lt;code&gt;&lt;pre&gt;float ff = 3.55F;&lt;br /&gt;float f = 5 / 3 + 7.88f;  //right!&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;2、数组&lt;br /&gt;(1) 数组是作为对象实现的，因此有类内变量length：&lt;br /&gt;&lt;code&gt;&lt;pre&gt;int m[][] = new int[4][];&lt;br /&gt;m[0] = new int[5];&lt;br /&gt;m[1] = new int[8];&lt;br /&gt;System.out.println("m[][] = " + m.length);  // 4&lt;br /&gt;System.out.println("m[0] = " + m[0].length);  // 5&lt;br /&gt;//System.out.println("m[1][] = " + m[1][].length);  &lt;br /&gt;                                       // wrong&lt;br /&gt;//System.out.println("m[1][3] = " + m[1][3].length);  &lt;br /&gt;                                       // wrong&lt;br /&gt;//System.out.println("m[3] = " + m[3].length);  &lt;br /&gt;                                       // wrong&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;(2) 数组越界：运行时错误（C/C++不提供运行时边界检查）&lt;br /&gt;&lt;code&gt;&lt;pre&gt;int m[] = new int[2];&lt;br /&gt;m[0] = 0;&lt;br /&gt;m[1] = 1;&lt;br /&gt;m[2] = 2;  //wrong&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;(3) 同C/C++，“int n[] = { 1, 2, 3, 4, };” 是正确的（即末尾可多一个逗号）。&lt;br /&gt;&lt;br /&gt;(4) java支持多维不等数组。如：&lt;br /&gt;&lt;code&gt;&lt;pre&gt;int twoD[][] = new int[3][];   // 仅需第一维指定内存&lt;br /&gt;twoD[0] = new int[5];&lt;br /&gt;twoD[1] = new int[3];&lt;br /&gt;twoD[2] = new int[1];&lt;/pre&gt;&lt;/code&gt;3、运算符&lt;br /&gt;(1) java中，“%”运算符可以用于浮点类型，而C/C++不能。如：&lt;br /&gt;&lt;code&gt;&lt;pre&gt;double d = 22.33 % 2.34;&lt;/pre&gt;&lt;/code&gt;(2) &amp;gt;&amp;gt; ：向右移   &amp;gt;&amp;gt;&amp;gt; ：向右移，左补零&lt;br /&gt;byte类型的值最高位若为1，则&amp;gt;&amp;gt;&amp;gt;对其是不可能的。如：&lt;br /&gt;byte b = 0xf1; 则 b&amp;gt;&amp;gt;4为0xff，b&amp;gt;&amp;gt;&amp;gt;4为0xff，(b &amp; 0xff)&amp;gt;&amp;gt;4为0x0f。&lt;br /&gt;&lt;br /&gt;(3) java中对boolean类型的值来说有运算符&amp;amp;（逻辑与）与&amp;amp;&amp;amp;（短路与）的区分（|与||同）。&lt;br /&gt;&lt;br /&gt;(4)&lt;br /&gt;&lt;code&gt;&lt;pre&gt;float f = 3;&lt;br /&gt;int i = 3;&lt;br /&gt;if(i == f)&lt;br /&gt;　　System.out.println("Yes"); // This will be printed&lt;br /&gt;else&lt;br /&gt;　　System.out.println("No");&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;4、程序控制语句&lt;br /&gt;(1) 在程序控制语句中，除了for语句可以使用逗号作为分隔符外，其他的地方不能使用逗号。如：&lt;br /&gt;&lt;code&gt;&lt;pre&gt;int k = 0;&lt;br /&gt;int i = true ? (k=3,k) : (k=4,k);  &lt;br /&gt;        // 错误，Syntax error on token&lt;br /&gt;        ",", invalid  AssignmentOperator&lt;/pre&gt;&lt;/code&gt;这一点与C/C++不同。&lt;br /&gt;&lt;br /&gt;(2) switch语句中，若default语句不在最后，其后也应该跟一个break语句。如：&lt;br /&gt;&lt;code&gt;&lt;pre&gt;int i = 4;&lt;br /&gt;int k = 0;&lt;br /&gt;switch(i)&lt;br /&gt;{&lt;br /&gt;　　default :&lt;br /&gt;　　　　k = 4;&lt;br /&gt;　　case 1:&lt;br /&gt;　　　　k = 1;&lt;br /&gt;　　　　break;&lt;br /&gt;　　case 2:&lt;br /&gt;　　　　k = 2;&lt;br /&gt;　　　　break;&lt;br /&gt;　　case 3:&lt;br /&gt;　　　　k = 3;&lt;br /&gt;　　　　break;&lt;br /&gt;}&lt;br /&gt;System.out.println(k);&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;将打印出“k=1”。&lt;br /&gt;&lt;br /&gt;(3) java中break、continue后可以跟一个标号。如：&lt;br /&gt;&lt;code&gt;&lt;pre&gt;one:for(int j=0;j&amp;lt;100;j++)&lt;br /&gt;{&lt;br /&gt;  if(j==10) break one;&lt;br /&gt;  System.out.println(j + " ");&lt;br /&gt;}&lt;/pre&gt;&lt;/code&gt;而在C/C++中不可以。&lt;br /&gt;&lt;br /&gt;(4) 像“7 + 8;”这样的无意义的语句在java中是不允许的；而C/C++中可以。&lt;br /&gt;&lt;br /&gt;5、函数&lt;br /&gt;(1) 关于重载，java与C++中都是允许的，而在C中是不允许的。&lt;br /&gt;在C++中，看下面这个例子：&lt;br /&gt;&lt;code&gt;&lt;pre&gt;#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;&lt;br /&gt;//函数1&lt;br /&gt;//void f()&lt;br /&gt;//{ printf("haha1\n"); }&lt;br /&gt;&lt;br /&gt;//函数2&lt;br /&gt;void f(int i)&lt;br /&gt;{ printf("haha2\n"); }&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;  int g = (int)f;  //(*)&lt;br /&gt;  ((void (*)())g)();&lt;br /&gt;&lt;br /&gt;  return 0;&lt;br /&gt;}&lt;/pre&gt;&lt;/code&gt;若不将函数1、2中的一个注释掉，赋值语句(*)处将会报错，因为在这里产生了二义。而只留有一个函数即没有重载，就没有事。&lt;br /&gt;&lt;br /&gt;6、类&lt;br /&gt;(1) java中默认为近似public的属性，而C++中为private。&lt;br /&gt;&lt;br /&gt;(2) 关于类实例的声明：&lt;br /&gt;java中：&lt;br /&gt;&lt;code&gt;&lt;pre&gt;X x = new X();  // X x = new X;的形式是错误的&lt;br /&gt;x.i = 0;&lt;/pre&gt;&lt;/code&gt;C++中：&lt;br /&gt;&lt;code&gt;&lt;pre&gt;X x = new X(); 或 X x = new X;&lt;br /&gt;x-&amp;gt;i = 0;&lt;br /&gt;或&lt;br /&gt;X x;  // 若没有构造函数或构造函数无参数，则 X x();的形式是错的的&lt;br /&gt;x.i = 0;&lt;/pre&gt;&lt;/code&gt;(3) C++中类定义结尾必须有分号，而java可有可无。&lt;br /&gt;&lt;br /&gt;(4) java中finalize方法与C++的析构函数是有区别的。protected void finalize()函数仅在垃圾收集时被调用，而当一个对象在作用域外时，她是不会被调用的。&lt;br /&gt;这意味着你不知道什么时候或是否会执行finalize()。因此，你的程序必须提供其他的方法来释放被对象使用的系统资源。&lt;br /&gt;这与C++是不同的。C++的析构函数在对象处于作用域外时被调用。&lt;br /&gt;java中因为所有的对象是使用new动态分配的，因此不需要担心关于对象在作用域范围之外的问题。因为对象创建时所在的方法终止了，&lt;br /&gt;对象将继续存在，只要在你的程序中的某处存在一个此对象的引用。当不存在它的引用时，下次垃圾收集起作用时，将重新收回这个对象。&lt;br /&gt;&lt;br /&gt;(5) 在C++中，如下：&lt;br /&gt;&lt;code&gt;&lt;pre&gt;class X {&lt;br /&gt;public:&lt;br /&gt;  int i;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;  X x();&lt;br /&gt;&lt;br /&gt;  return 0;&lt;br /&gt;}&lt;/pre&gt;&lt;/code&gt;此x将被认为是函数的声明。如：&lt;br /&gt;&lt;code&gt;&lt;pre&gt;class X {&lt;br /&gt;public:&lt;br /&gt;  int i;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;  X x();&lt;br /&gt;  x();&lt;br /&gt;  return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;X x()&lt;br /&gt;{&lt;br /&gt;  cout &amp;lt;&amp;lt; "haha\n":   &lt;br /&gt;  ... &lt;br /&gt;}&lt;/pre&gt;&lt;/code&gt;(6) 在函数中的参数，简单类型是按值传递，而对象则按引用传递&lt;br /&gt;&lt;br /&gt;(7) 关于类中的static&lt;br /&gt;声明为static的方法有几条限制：&lt;br /&gt;─它们仅可以调用其他static方法；&lt;br /&gt;─它们只能访问static数据；&lt;br /&gt;─它们不能以任何方式引用this或super。&lt;br /&gt;关于static块，这个块仅在该类被第一次加载时执行一次。例：&lt;br /&gt;&lt;code&gt;&lt;pre&gt;public class t2 {&lt;br /&gt;static int i;&lt;br /&gt;public static void main(String args[]) {&lt;br /&gt;  System.out.println("Start in main");&lt;br /&gt;&lt;br /&gt;  Y y = new Y();&lt;br /&gt;&lt;br /&gt;  System.out.println("End in main");&lt;br /&gt;&lt;br /&gt;  y = null;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Y {&lt;br /&gt;int i;&lt;br /&gt;static int a = 3;&lt;br /&gt;static int b;&lt;br /&gt;static {&lt;br /&gt;  System.out.println("Static block");&lt;br /&gt;  b = a * 4;&lt;br /&gt;}&lt;br /&gt;Y() {&lt;br /&gt;  System.out.println("Con...");&lt;br /&gt;}&lt;br /&gt;protected void finalize() {&lt;br /&gt;  System.out.println("decon...");&lt;br /&gt;}&lt;br /&gt;}&lt;/pre&gt;&lt;/code&gt;打印：&lt;br /&gt;Start in main&lt;br /&gt;Static block&lt;br /&gt;Con...&lt;br /&gt;End in main&lt;br /&gt;&lt;br /&gt;(8) 关于类嵌套（C++中没有）&lt;br /&gt;A：外壳类  B：核类&lt;br /&gt;A可知B，而A外的作用域不可知B。&lt;br /&gt;B可访问A的成员，包括私有成员；A不能访问B的成员。&lt;br /&gt;B可分为静态的（修饰以static）和非静态的（内部类）。静态的B必须通过一个对象来访问A的成员，而不能直接引用之；而非静态类则可以&lt;br /&gt;访问A的所有成员，并且可以像A的其他非静态成员那样以同样的方式直接引用它们。&lt;br /&gt;另外，嵌套类可以定义在任何块内，比如函数、for循环内等等。&lt;br /&gt;&lt;br /&gt;(9) String&lt;br /&gt;&lt;code&gt;&lt;pre&gt;String ss = "wre"+"fsd";  // 对&lt;br /&gt;String ss = "wre""fsd";   // 错，虽然在&lt;br /&gt;                          C/C++中可以这样&lt;/pre&gt;&lt;/code&gt;(10) 与C/C++不同，java的命令行参数计数不是从所运行的程序名开始的。如：&lt;br /&gt;&lt;code&gt;&lt;pre&gt;class CommandLine {&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt; for(int i=0;i&amp;lt;args.length;i++)&lt;br /&gt; {&lt;br /&gt;   System.out.println("args["+i+"]:"+args[i]);&lt;br /&gt; }&lt;br /&gt;}&lt;/pre&gt;&lt;/code&gt;执行 # java CommandLine this is a test 100 -1&lt;br /&gt;将打印出&lt;br /&gt;args[0]:this&lt;br /&gt;args[1]:is&lt;br /&gt;args[2]:a&lt;br /&gt;args[3]:test&lt;br /&gt;args[4]:100&lt;br /&gt;args[5]:-1&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3633095353052479181-6699768997576354192?l=helloworld-world.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://helloworld-world.blogspot.com/feeds/6699768997576354192/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3633095353052479181&amp;postID=6699768997576354192' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/6699768997576354192'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/6699768997576354192'/><link rel='alternate' type='text/html' href='http://helloworld-world.blogspot.com/2007/03/java2.html' title='重拾java（2）'/><author><name>Pern</name><uri>http://www.blogger.com/profile/14279149889893810974</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3633095353052479181.post-8852253973738404410</id><published>2007-03-20T19:18:00.000+08:00</published><updated>2007-03-20T19:23:16.109+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>不用循环和递归，用C打印1~999</title><content type='html'>同学出了rt的这道题。没作出来。看看答案，果然厉害，让我想起linux内核源代码中的一大堆的define扩展。&lt;br /&gt;答案：&lt;blockquote style="font-family: courier new; font-size: 85%;"&gt;&lt;pre&gt;#define A(x) x;x;x;x;x;x;x;x;x;x;&lt;br /&gt;int main ()&lt;br /&gt;{&lt;br /&gt; int i = 1;&lt;br /&gt; A(A(A(printf("%d", i++))));&lt;br /&gt;}&lt;/pre&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3633095353052479181-8852253973738404410?l=helloworld-world.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://helloworld-world.blogspot.com/feeds/8852253973738404410/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3633095353052479181&amp;postID=8852253973738404410' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/8852253973738404410'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/8852253973738404410'/><link rel='alternate' type='text/html' href='http://helloworld-world.blogspot.com/2007/03/c1999.html' title='不用循环和递归，用C打印1~999'/><author><name>Pern</name><uri>http://www.blogger.com/profile/14279149889893810974</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3633095353052479181.post-8125488995217128107</id><published>2007-03-19T22:25:00.000+08:00</published><updated>2007-03-19T23:26:44.868+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>重拾java</title><content type='html'>上星期六去参加了IBM的研究生实习招聘的笔试。两份卷子，其中一份厚厚一叠都是java。作下来很不爽，java几乎都忘光了。所以决心重拾java。晚上在我的ubuntu上弄好了eclipse，然后看了点书，作笔记如下（大部分是java与C/C++间的比较）：&lt;br /&gt;1、&lt;br /&gt;java和C中，变量名中可以使用$，如“int $hu;”。&lt;br /&gt;2、&lt;br /&gt;java是强类型的，甚至比C/C++还严格。如：&lt;br /&gt;在java中，int i = 4.5; // 错误&lt;br /&gt;而在C中，int i = 4.5;  // 可以&lt;br /&gt;3、&lt;br /&gt;java不支持无符号的正整数。&lt;br /&gt;java中byte（8）、short（16）、int（32）、long（64）其宽度是固定的，不随目标机器的不同而不同 。&lt;br /&gt;java中char是16位（无符号数）的Unicode表示。&lt;br /&gt;4、&lt;br /&gt;“boolean b = true;&lt;br /&gt;System.out.print("boolean true is : " + b);”&lt;br /&gt;将打印出“true”而不是“1”。&lt;br /&gt;5、&lt;br /&gt;关于char型变量的数字表示，在java与C/C++中有一些区别:&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;&lt;br /&gt;&lt;/th&gt;&lt;th&gt;java&lt;/th&gt;&lt;th&gt;C/C++&lt;/th&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;八进制&lt;/td&gt;&lt;td&gt;\ddd&lt;/td&gt;&lt;td&gt;\ddd&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;十六进制&lt;/td&gt;&lt;td&gt;\uhhhh&lt;/td&gt;&lt;td&gt;\xhh&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;6、&lt;br /&gt;对于java的字符串，它们必须在同一行开始和结束，没有像在其他语言中的行连续转义（如C/C++中的“\”）序列（对于很长的字符串，要换行可以使用+号连接）。&lt;br /&gt;7、&lt;br /&gt;关于块作用域，在java中，你不能声明一个变量为与外部作用域的变量一样的名称。如下面的程序：&lt;br /&gt;&lt;blockquote style="font-family: courier new; font-size: 85%;"&gt;&lt;pre&gt;class ScopeErr {&lt;br /&gt;public static void main(String arg[]) {&lt;br /&gt;  int bar = 1;&lt;br /&gt;  {               // creates a new scope&lt;br /&gt;    int bar = 2;  // Compile-time error - bar already defined!&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;}&lt;/pre&gt;&lt;/blockquote&gt;而这种情况在C/C++中是合法的。&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3633095353052479181-8125488995217128107?l=helloworld-world.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://helloworld-world.blogspot.com/feeds/8125488995217128107/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3633095353052479181&amp;postID=8125488995217128107' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/8125488995217128107'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/8125488995217128107'/><link rel='alternate' type='text/html' href='http://helloworld-world.blogspot.com/2007/03/java.html' title='重拾java'/><author><name>Pern</name><uri>http://www.blogger.com/profile/14279149889893810974</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3633095353052479181.post-2055132334126530470</id><published>2007-03-16T09:47:00.000+08:00</published><updated>2007-03-16T10:03:05.280+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>阅读《C陷阱与缺陷》：……</title><content type='html'>&lt;ul&gt;&lt;br /&gt;&lt;li&gt;宏中的空格&lt;/li&gt;&lt;br /&gt;在语句“#define f (x) ((x)-1)”中，若要定义类似函数f(x)的功能，则f后的空格将会引起错误的替换。正确的写法是“#define f(x) ((x)-1)”。但此空格规则不适合宏调用，如“f (3)”其值仍为2。&lt;br /&gt;&lt;li&gt;兼容性一例&lt;/li&gt;&lt;br /&gt;为保持与老版本编译器的兼容性，函数定义如：&lt;br /&gt;&lt;blockquote style="font-family: courier new; font-size: 85%;"&gt;&lt;pre&gt;void func(int arg1,int arg2)&lt;br /&gt;{ ... }&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;也可写成&lt;br /&gt;&lt;blockquote style="font-family: courier new; font-size: 85%;"&gt;&lt;pre&gt;void func(arg1,arg2)&lt;br /&gt;int arg1, arg2;&lt;br /&gt;{ ... }&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;或&lt;br /&gt;&lt;blockquote style="font-family: courier new; font-size: 85%;"&gt;&lt;pre&gt;void func(arg1,arg2)&lt;br /&gt;int arg1; int arg2;&lt;br /&gt;{ ... }&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;li&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;在C中（包括gcc与MSC），如下写法是错误的：&lt;br /&gt;&lt;blockquote style="font-family: courier new; font-size: 85%;"&gt;&lt;pre&gt;for(int i=0;i&amp;lt;n;i++) { ... } &lt;/pre&gt;&lt;/blockquote&gt;而应该写成&lt;blockquote style="font-family: courier new; font-size: 85%;"&gt;&lt;pre&gt;int i;&lt;br /&gt;for(i=0;i&amp;lt;n;i++) { ... }&lt;/pre&gt;&lt;/blockquote&gt;&lt;li&gt;多余的逗号&lt;/li&gt;&lt;br /&gt;在C中，允许初始化列表中出现多余的逗号。例如：&lt;br /&gt;&lt;blockquote style="font-family: courier new; font-size: 85%;"&gt;&lt;pre&gt;int days[] = {1,2,3,4,5,};&lt;/pre&gt;&lt;/blockquote&gt;但只能在 末尾 多 一 个。&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3633095353052479181-2055132334126530470?l=helloworld-world.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/2055132334126530470'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/2055132334126530470'/><link rel='alternate' type='text/html' href='http://helloworld-world.blogspot.com/2007/03/c_16.html' title='阅读《C陷阱与缺陷》：……'/><author><name>Pern</name><uri>http://www.blogger.com/profile/14279149889893810974</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-3633095353052479181.post-87574880956843662</id><published>2007-03-13T22:05:00.000+08:00</published><updated>2007-03-13T22:09:13.783+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>阅读《C陷阱与缺陷》：语法“陷阱”</title><content type='html'>函数调用“f(...)” 等价于 “(*f)(...)”；前者只是后者的简写形式。&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3633095353052479181-87574880956843662?l=helloworld-world.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://helloworld-world.blogspot.com/feeds/87574880956843662/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3633095353052479181&amp;postID=87574880956843662' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/87574880956843662'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/87574880956843662'/><link rel='alternate' type='text/html' href='http://helloworld-world.blogspot.com/2007/03/c_13.html' title='阅读《C陷阱与缺陷》：语法“陷阱”'/><author><name>Pern</name><uri>http://www.blogger.com/profile/14279149889893810974</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3633095353052479181.post-4397500226967829565</id><published>2007-03-13T19:44:00.000+08:00</published><updated>2007-03-13T20:12:32.692+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>阅读《C陷阱与缺陷》：导读、词法“陷阱”</title><content type='html'>&lt;ul&gt;&lt;li&gt;边界溢出一例&lt;/li&gt;&lt;blockquote style="font-family: courier new; font-size: 85%;"&gt;&lt;pre&gt;#define N 10&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;  int i;&lt;br /&gt;  int a[N];&lt;br /&gt;&lt;br /&gt;  printf("Begin...\n");&lt;br /&gt;&lt;br /&gt;  for(i=0;i&lt;=N;i++)     &lt;br /&gt;    a[i] = 0;    //有可能会陷入死循环！&lt;br /&gt;&lt;br /&gt;  printf("End...\n");&lt;br /&gt;&lt;br /&gt;  return 0; &lt;br /&gt;}&lt;/pre&gt;&lt;/blockquote&gt;因为每次循环结束时a溢出，使得i复为0。&lt;br /&gt;&lt;br /&gt;&lt;li&gt;词法分析中的贪心法&lt;/li&gt;&lt;br /&gt;1、a---b等价于a-- - b而不是a - --b；&lt;br /&gt;2、“y = x/*p  /* p指向余数 */;”，其中“/*”为注释起始而不是除以*p。&lt;br /&gt;&lt;br /&gt;&lt;li&gt;以0开头的数字为八进制表示&lt;/li&gt;&lt;br /&gt;如041=33。&lt;br /&gt;&lt;br /&gt;&lt;li&gt;单引号引起的问题&lt;/li&gt;&lt;br /&gt;1、printf('\n');  //危险！打印地址为'\n'处的字符串。&lt;br /&gt;2、如下程序：&lt;br /&gt;&lt;blockquote style="font-family: courier new; font-size: 85%;"&gt;&lt;pre&gt;int main()&lt;br /&gt;{&lt;br /&gt;  int i = '1234';  //MSVC与gcc均编译通过，&lt;br /&gt;             但若单引号内的字符大于4则会报错&lt;br /&gt;&lt;br /&gt;  printf("%x\n", i);   // 0x31323334&lt;br /&gt;&lt;br /&gt;  return 0;&lt;br /&gt;}&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;编译器将会把单引号内的字符所对应的ASCII码依次填入整型变量的4个字节中。&lt;br /&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3633095353052479181-4397500226967829565?l=helloworld-world.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://helloworld-world.blogspot.com/feeds/4397500226967829565/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3633095353052479181&amp;postID=4397500226967829565' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/4397500226967829565'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/4397500226967829565'/><link rel='alternate' type='text/html' href='http://helloworld-world.blogspot.com/2007/03/c.html' title='阅读《C陷阱与缺陷》：导读、词法“陷阱”'/><author><name>Pern</name><uri>http://www.blogger.com/profile/14279149889893810974</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3633095353052479181.post-1009869390621248135</id><published>2007-03-13T17:27:00.000+08:00</published><updated>2007-03-13T17:43:53.483+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>关于函数printf()[2]</title><content type='html'>有下面一段代码：&lt;br /&gt;&lt;blockquote style="font-family: courier new; font-size: 85%;"&gt;&lt;pre&gt;...&lt;br /&gt;char str[20];&lt;br /&gt;...&lt;br /&gt;scanf("Please input a string less than 20: %s", str);&lt;br /&gt;...&lt;br /&gt;printf(str);&lt;br /&gt;...&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;危险在于：若用户输入的字符串中包含格式化参数如%x、%d等等，语句printf(str)将会把邻接内存内的内容按照所给的格式化参数打印出来。更危险的是，如果用户输入的字符串中使用了%n，则会向相应的内存中写入数据。格式化参数$的使用则会便利这种危险的内存注入。&lt;br /&gt;因此，正确的写法应该是&lt;br /&gt;&lt;blockquote style="font-family: courier new; font-size: 85%;"&gt;&lt;pre&gt;printf("%s", str);&lt;pre&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3633095353052479181-1009869390621248135?l=helloworld-world.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://helloworld-world.blogspot.com/feeds/1009869390621248135/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3633095353052479181&amp;postID=1009869390621248135' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/1009869390621248135'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/1009869390621248135'/><link rel='alternate' type='text/html' href='http://helloworld-world.blogspot.com/2007/03/printf2.html' title='关于函数printf()[2]'/><author><name>Pern</name><uri>http://www.blogger.com/profile/14279149889893810974</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3633095353052479181.post-3884979348796075791</id><published>2007-03-12T21:16:00.000+08:00</published><updated>2007-03-13T11:52:15.019+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>关于函数printf()</title><content type='html'>printf()函数有一个可变参数列表。在其实现里，先通过第一个参数找到可变参数列表的首地址，然后根据可变参数的类型依次定位。而所依据的类型则是在第一个参数──即格式化字符串中给出的。因此格式化字符串中必须给出与后面可变参数列表中各个参数相一致的类型，否则则会发生意想不到的结果，如下面一个例子：&lt;br /&gt;&lt;span style=";font-family:courier new;font-size:85%;"  &gt;&lt;blockquote&gt;&lt;pre&gt;int main()&lt;br /&gt;{&lt;br /&gt;  float n1 = 11.11;&lt;br /&gt;  double n2 = 222.222;&lt;br /&gt;  long n3 = 3333;&lt;br /&gt;  long n4 = 4444;&lt;br /&gt;&lt;br /&gt;  printf("Right: %f,%f,%ld,%ld\n",n1,n2,n3,n4);&lt;br /&gt;  printf("Wrong: %ld,%ld,%ld,%ld\n",n1,n2,n3,n4);&lt;br /&gt;&lt;br /&gt;  return 0;&lt;br /&gt;}&lt;/pre&gt;&lt;/blockquote&gt;&lt;/span&gt;&lt;br /&gt;其输出结果为：&lt;br /&gt;root@BlueIris:~# ./printf_type&lt;br /&gt;Right: 11.110000,222.222000,3333,4444&lt;br /&gt;Wrong: -536870912,1076246609,-1614907703,1080805146&lt;br /&gt;%f指示应该在内存中往后读8个字节，而%ld只有4个，因此出现偏差。&lt;br /&gt;&lt;br /&gt;参考：&lt;a href="http://docs.google.com/Doc?id=dhkxw883_6cpcstk"&gt;深入printf&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3633095353052479181-3884979348796075791?l=helloworld-world.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://helloworld-world.blogspot.com/feeds/3884979348796075791/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3633095353052479181&amp;postID=3884979348796075791' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/3884979348796075791'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/3884979348796075791'/><link rel='alternate' type='text/html' href='http://helloworld-world.blogspot.com/2007/03/printf.html' title='关于函数printf()'/><author><name>Pern</name><uri>http://www.blogger.com/profile/14279149889893810974</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3633095353052479181.post-4767409077680798028</id><published>2007-03-12T20:28:00.000+08:00</published><updated>2008-12-13T04:32:58.339+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>关于函数strcat()</title><content type='html'>摘自glibc-2.4/string/strcat.c：&lt;br /&gt;&lt;blockquote&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;  &lt;pre&gt;char *&lt;br /&gt;strcat (dest, src)&lt;br /&gt;    char *dest;&lt;br /&gt;    const char *src;&lt;br /&gt;{&lt;br /&gt;  char *s1 = dest;&lt;br /&gt;  const char *s2 = src;&lt;br /&gt;  reg_char c;&lt;br /&gt;&lt;br /&gt;  /* Find the end of the string. */&lt;br /&gt;  do&lt;br /&gt;  c = *s1++;&lt;br /&gt;  while (c != '\0');&lt;br /&gt;&lt;br /&gt;  /* Make S1 point before the next character, so we can increment&lt;br /&gt;  it while memory is read (wins on pipelined cpus). */&lt;br /&gt;  s1 -= 2;&lt;br /&gt;&lt;br /&gt;  do&lt;br /&gt;  {&lt;br /&gt;    c = *s2++;&lt;br /&gt;    *++s1 = c;&lt;br /&gt;  }&lt;br /&gt;  while (c != '\0');&lt;br /&gt;&lt;br /&gt;  return dest;&lt;br /&gt;}&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt;摘自MVC：&lt;br /&gt;&lt;blockquote&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;pre&gt;char * strcat (char * dst, char * src)&lt;br /&gt;{&lt;br /&gt;  char * cp = dst;&lt;br /&gt;&lt;br /&gt;  while( *cp )&lt;br /&gt;    ++cp;           /* Find end of dst */&lt;br /&gt;  while( *cp++ = *src++ )&lt;br /&gt;    ;               /* Copy src to end of dst */&lt;br /&gt;  return( dst );&lt;br /&gt;}&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt;从函数strcat()的实现中我们可以看出，它并不会对其参数进行检查。因此我们写程序时应该格外小心，因为源字符串若长度不够，则会溢出，从而有可能覆盖掉邻接的内存里的内容。可以看一个例子：&lt;br /&gt;&lt;blockquote&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;pre&gt;int main()&lt;br /&gt;{&lt;br /&gt;  char a[] = {'1','1','1','\0'};&lt;br /&gt;  char d[] = {'2','2','2','\0'};&lt;br /&gt;  char s[] = {'3','3','3','\0'};&lt;br /&gt;&lt;br /&gt;  printf("before strcat() a is %s\n", a);&lt;br /&gt;  printf("before strcat() d is %s\n", d);&lt;br /&gt;&lt;br /&gt;  strcat(d,s);&lt;br /&gt;&lt;br /&gt;  printf("after strcat() a is %s\n", a);&lt;br /&gt;  printf("after strcat() d is %s\n", d);&lt;br /&gt;}&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt;其输出为：&lt;br /&gt;root@BlueIris:~# ./strcpy_error&lt;br /&gt;before strcat() a is 111&lt;br /&gt;before strcat() d is 222&lt;br /&gt;after  strcat() a is 33&lt;br /&gt;after  strcat() d is 222333&lt;br /&gt;可见字符数组a已经被d溢出的部分所覆盖。原理见下图。&lt;br /&gt;&lt;div style="text-align: left;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/__7vqqLx2ZQQ/RfVP_1QVMqI/AAAAAAAAAZ4/Af84QeblDLA/s1600-h/strcat.jpg"&gt;&lt;img dragover="true" style="cursor: pointer;" src="http://4.bp.blogspot.com/__7vqqLx2ZQQ/RfVP_1QVMqI/AAAAAAAAAZ4/Af84QeblDLA/s320/strcat.jpg" alt="" id="BLOGGER_PHOTO_ID_5041023315957068450" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3633095353052479181-4767409077680798028?l=helloworld-world.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://helloworld-world.blogspot.com/feeds/4767409077680798028/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3633095353052479181&amp;postID=4767409077680798028' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/4767409077680798028'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3633095353052479181/posts/default/4767409077680798028'/><link rel='alternate' type='text/html' href='http://helloworld-world.blogspot.com/2007/03/strcat.html' title='关于函数strcat()'/><author><name>Pern</name><uri>http://www.blogger.com/profile/14279149889893810974</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/__7vqqLx2ZQQ/RfVP_1QVMqI/AAAAAAAAAZ4/Af84QeblDLA/s72-c/strcat.jpg' height='72' width='72'/><thr:total>0</thr:total></entry></feed>
