文档详情

C语言面试课案.docx

发布:2017-05-24约1.33万字共82页下载文档
文本预览下载声明
char * const p; //常量指针,p的值不可以修改   char const * p;//指向常量的指针,指向的常量值不可以改   const char *p; //和char const *p 2. ?关键字static的作用是什么? 这个简单的问题很少有人能回答完全。在C语言中,关键字static有三个明显的作用:? 1). 在函数体,一个被声明为静态的变量在这一函数被调用过程中维持其值不变。? 2). 在模块内(但在函数体外),一个被声明为静态的变量可以被模块内所用函数访问,但不能被模块外其它函数访问。它是一个本地的全局变量。? 3). 在模块内,一个被声明为静态的函数只可被这一模块内的其它函数调用。那就是,这个函数被限制在声明它的模块的本地范围内使用。? 大多数应试者能正确回答第一部分,一部分能正确回答第二部分,同是很少的人能懂得第三部分。这是一个应试者的严重的缺点,因为他显然不懂得本地化数据和代码范围的好处和重要性。 3多态。overload 和 override的区别。 答:重载在相同范围(同一个类中),函数名字相同,参数不同,virtual关键字可有可无。 ?覆盖是指派生类函数覆盖基类函数,不同的范围,函数名字相同,参数相同,基类函数必须有virtual关键字。 4. Strcpy: #includestdio.h char *mystrcpy(char *p,const char *q) { char *d=p; while(*p++=*q++); return d; } int main() { char a[]=aaaa; char *b=dddd; char *c=mystrcpy(a,b); printf(%s\n,c); } 5. Strcat: #includestdio.h char *mystrcat(char *p,char *q) { char *d=p; while(*p) *p++; while(*q) *p++=*q++; return d; } int main() { char a[]=aaaa; char b[]=dddd; char *c=mystrcat(a,b); printf(%s\n,c); } 6. 字符串的倒序:、 #includestdio.h #includestring.h #includemalloc.h char *fan(char *p,int d) { char *t=(char *)malloc(sizeof(p)); char *a=t; while(*p) *p++; *p--; while(d--) *t++=*p--; return a; } int main() { char *a=abcdefg; int l=strlen(a); char *c=fan(a,l); printf(%s\n,c); } 6.两个数交换: #includestdio.h #includestring.h #includemalloc.h void swapp(int *p,int *q) { *p = *p^*q; *q = *p^*q; *p = *p^*q; } int main() { int a=10; int b=100; printf(%d,%d\n,a,b); swapp(a,b); printf(%d,%d\n,a,b); } 7.整数转化为字符串 itoa()函数有3个参数:第一个参数是要转换的数字,第二个参数是要写入转换结果的目标字符串,第三个参数是转移数字时所用 的基数。在上例中,转换基数为10。10:十进制;2:二进制... Atoi:字符串转为整数 8.在链表里如何发现循环链接? [cpp]? HYPERLINK /zhsenl/article/details/7416782 \o view plain view plain HYPERLINK /zhsenl/article/details/7416782 \o copy copy //基本思想:快慢指针?? #include?iostream?? #include?string?? using?namespace?std;?? ?? struct?Node?? {?? ????int?value;?? ????Node?*next;?? };?? bool?hasCircle(Node?*head)?? {?? ????Node?*fast;?? ????Node?*slow;?? ????fast?=?slow?=?head;?? ????if(head?==?
显示全部
相似文档