程序员面试宝典-第三讲 C语言

上传人:只**** 文档编号:244060713 上传时间:2024-10-02 格式:PPT 页数:28 大小:222.50KB
返回 下载 相关 举报
程序员面试宝典-第三讲 C语言_第1页
第1页 / 共28页
程序员面试宝典-第三讲 C语言_第2页
第2页 / 共28页
程序员面试宝典-第三讲 C语言_第3页
第3页 / 共28页
点击查看更多>>
资源描述
单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,*,第三讲,C/C+,1,、编译器规则,#include,using namespace std;,int,main(),int,a,x,;,for(a,=0,x=0;a=1&!,x+;a,+),a+;,cout,ax,endl,;,return 0;,#include,using namespace std;,int,main(),int,a,x,;,for(a=0,x=0;a=1),a+;,cout,ax,endl,;,return 0;,A,、,1 2 B,、,2 1,#include,main(),int,b=3;,int,arr,=6,7,8,9,10;,int,*,ptr,=,arr,;,*(,ptr,+)+=123;,printf(%d,%dn,*,ptr,*(+,ptr,);,A,、,8 8 B,、,130 8 C,、,7 7 D,、,7 8,2,、类型转换,#include,int,main(),unsigned,int,a=0 xFFFFFFF7;,unsigned char i=(unsigned,char)a,;,char*b=(char*),printf(%08x,%08x,i,*b);,3,、运算符问题,#include,using namespace std;,int,main(),unsigned char a=0 xA5;,unsigned char b=a4+1;,printf(b,=%,dn,b,);,return 0;,A.245 B.246 C.250 D.2,int,f(int,x,int,y),return(x&y)+(xy,)1);,f(729,271)=?,有两个变量,a,、,b,,不用,if,?:,switch,或其他判断语句,找出两个数中间比较大的。,如何将,a,、,b,的值进行交换,并且不使用任何中间变量?,4,、预处理、,const,用一个宏定义,FIND,求一个结构体,struc,里某个变量相对,struc,的偏移量。,#define,FIND(struc,e,)(,size_t)&(struc,*)0)-e),用预处理指令,#define,声明一个常数,用以表明,1,年中有多少秒,(,忽略闰年问题,),。,#define SECONDS_PER_YEAR(60*60*24*365),写一个“标准”宏,MIN,,这个宏输入两个参数并返回较小的一个。,#define MIN(A,B)(A)=(B)?(A),:(B),5,、,sizeof,#include,#include,#include,using namespace std;,struct,short a1;,short a2;,short a3;,A;,struct,long a1;,short a2;,B;,int,main(),char*ss1=0123456789;,char ss2=0123456789;,char ss3100=0123456789;,int,ss4100;,char q1=,abc,;,char q2=an;,char*q3=an;,char*str1=(char*)malloc(100);,void*str2=(void*)malloc(100);,cout,sizeof(ss1);,cout,sizeof(ss2);,cout,sizeof(ss3);,cout,sizeof(ss4);,cout,sizeof(q1);,cout,sizeof(q2);,cout,sizeof(q3);,cout,sizeof(A,);,cout,sizeof(B,);,cout,sizeof(str1);,cout,sizeof(str2);,return 0;,class B,private:,bool,m_bTemp,;,int,m_nTemp,;,bool,m_bTemp2;,;,class C,private:,int,m_nTemp,;,bool,m_bTemp,;,bool,m_bTemp2;,;,cout,sizeof(B,),endl,;,cout,sizeof(C,),endl,;,#include,#include,using namespace std;,int,main(int,argc,char,*,argv,),/To output,TreadMicroSoftUSCN,string strArr1=,Trend,Micro,Soft,;,string*pStrArr1=new string2;,pStrArr10=US;,pStrArr11=CN;,for(,int,i=0;isizeof(strArr1)/sizeof(string);i+),cout,strArr1i;,for(,int,j=0;jsizeof(pStrArr1)/sizeof(string);j+),cout,pStrArr1j;,return 0;,char var10,int,test(char,var,),return,sizeof(var,);,;,class B,float f;,char p;,int,adf3;,;,cout,sizeof(B,);,#include,#include,#include,using namespace std;,class A,;,class A2,;,class,B:public,A,;,class,C:public,virtual B,;,class,D:public,A,public,A2,;,int,main(int,argc,char,*,argv,),cout,sizeof(A,):,sizeof(A,),endl,;,cout,sizeof(B,):,sizeof(B,),endl,;,cout,sizeof(C,):,sizeof(C,),endl,;,cout,sizeof(D,):,sizeof(D,),endl,;,return 0;,6,、指针,#include,using namespace std;,int,main(),int,iv;/1,int,iv2=1024;/2,int,iv3=999;/3,int,&,reiv,;/4,int,/5,int,/6,int,*pi;/7,*pi=5;/8,pi=/9,const double,di,;/10,const double,maxWage,=10.0;/11,const double,minWage,=0.5;/12,const double*pc=&,maxWage,;/13,return 0;,#include,using namespace std;,void swap1(int,p,int,q),int,temp;,temp=p;,p=q;,q=temp;,void swap2(int*,p,int,*q),int,*temp;,*temp=*p;,*p=*q;,*q=*temp;,void swap3(int*,p,int,*q),int,*temp;,temp=p;,p=q;,q=temp;,void swap4(int*,p,int,*q),int,temp;,temp=*p;,*p=*q;,*q=temp;,void swap5(int&,p,int,&q),int,temp;,temp=p;,p=q;,q=temp;,#include,void,GetMemory(char,*,p,int,num),p=(char*),malloc(sizeof(char,)*num);,;,int,main(),char*,str,=NULL;,GetMemory(str,100);,strcpy(str,hello,);,return 0;,运行后结果是什么?,这个函数有什么问题?怎么修改?,char*,strA,(),char,str,=hello world;,return,str,;,int a3;,a0=0;a1=1;a2=2;,int*p,*q;,p=a;,q=,coutaq-pn;,#include,class A,public:,A(),m_a,=1;m_b=2;,A();,void,fun()printf(%d%d,m_a,m_b,);,private:,int,m_a,m_b,;,;,class B,public:,B(),m_c,=3;,B();,void,fun()printf(%d,m_c,);,private:,int,m_c,;,;,void main(),A a;,B*,pb,=(B*)(,pb,-fun();,#include,using namespace std;,class A,public:,int,a;,A(),a=1;,void print(),printf(%d,a,);,;,class,B:public,A,public:,int,a;,B()a,=2;,;,void main(),B b;,b.print,();,printf(%d,b.a,);,#include,int,max(int,x,int,y),return x,y?x:y,;,int,main(),int,max(x,y,);,int,*p=,int,a,b,c,d,;,printf(Please,input three integern);,scanf(%d,%d%,d,a,b,c,);,d=(*p)(*,p)(a,b),c,);,printf(Among,%,d,%d,and,%,d,the,maxmal,integer is%,dn,a,b,c,d,);,return 0;,#include,int,max(int,x,int,y),return x,y?x:y,;,int,main(),int,max(int,int,),;,int,(*,p)(int,int,),=,int,a,b,c,d,;,printf(Please,input three integern);,scanf(%d,%d%,d,&a,&b,&c,);,d=(*p)(*,p)(a,b),c,);,printf(Among,%,d,%d,and,%,d,the,maxmal,integer is%,dn,a,b,c,d,);,return 0;,指针数组和数组指针,一个指向整型数组的指针的定义为(),A,、,int,(*,ptr,)B,、,int,*,ptr,C,、,int,*(,ptr,)D,、,int,ptr,int,a=1,2,3,4,5;,Int,*,ptr,=(,int,*)(,Printf(“%d,%d”,*(a+1),*(ptr-1);,迷途指针,typedef,unsigned short,int,USHORT;,#include,int,main(),USHORT*,pInt,=new USHORT;,*,pInt,=0;,cout,*,pInt,:*,pInt,endl,;,delete,pInt,;,pInt,=0;,long*,pLong,=new long;,*,pLong,=90000;,cout,*,pLong,:*,pLong,endl,;,*,pInt,=20;,cout,*,pInt,:*,pInt,endl,;,cout,*,pLong,:*,pLong,endl,;,delete,pLong,;,return 0;,
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 管理文书 > 方案规范


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!