摘要:
#include <stdio.h>main(){int n=5;char c[5];for(int i=0; i <n; i++){scanf("%c",&c[i]);fflush(stdin);}printf(c);//为什么输出会多出奇怪的字符return 0;} 这是我最初的问题代码,是啊,为什么要输出一些奇怪的字符呢?因为我的数组没有结束字符'/0',就是这个原因!对于字符串我们平常是这样用的c[5]={"iwai"};或者是c[5]="iwai";其中已将包含'/0' 阅读全文
posted @ 2009-06-18 14:57
胡.杰
阅读(169)
评论(0)
推荐(0)
摘要:
________________________________________________________________________________________________________________________________________________strcmp("ha","he")是可以的。 但是如下代码: string str1 = "ha"; string str2 = "he"; strcmp(str1, str2); 会产生如下的ERROR: error C2664: 阅读全文
posted @ 2009-06-18 12:05
胡.杰
阅读(946)
评论(0)
推荐(0)
摘要:
#include <stdio.h>void main(){ int *p=NULL; *p=5; printf("%d/n",*p);}这串代码编译时没有错误,但是执行不了,为什么呢?是因为*p的定义,初始化问题,像这样定义是不行的,因为根本就没有明确的给指针变量p指定一个内存区域,只是将整数5的地址给了p。造成了运行时的错误!代码修改:#include <stdio.h>void main(){ int *p=NULL,a; a=5; p=&a; printf("%d/n",*p);} 阅读全文
posted @ 2009-06-18 12:03
胡.杰
阅读(141)
评论(0)
推荐(0)
摘要:
————————————————————————————————————————————————————————————数组越界如果申明int a[5];那么我索引到a[5],a[6]....这些数据是什么样的格式呢?int?还是以int型结构索引?是不是我定义了int型的数组,然后以int型读取从数组起始地址开始的内存区域吗(包括越界区域的读取)?例如我上一贴说到的测试程序:#include <iostream>using namespace std;int main(){ int i; double a[4]; for (i=0;i<7;i++) { a[i]=i; } 阅读全文
posted @ 2009-06-18 11:57
胡.杰
阅读(183)
评论(0)
推荐(0)
浙公网安备 33010602011771号