易截截图软件、单文件、免安装、纯绿色、仅160KB

c指针的各种用法试验

#include <iostream.h>
void fun0(int* p)
{
int* a=new int[3];
*a=0;
*(a+1)=1;
*(a+2)=2;
p=a;
}
void fun1(int* &p)
{
int* a=new int[3];
*a=0;
*(a+1)=1;
*(a+2)=2;
p=a;
}
void fun2(int* p)
{
*p=0;
*(p+1)=1;
*(p+2)=2;
}
//warning:returning address of local variable or temporary
int* fun3()
{
int a[]={1,2,3};
return a;
}
//warning C4172: returning address of local variable or temporary
int*& fun4()
{
int* a=new int[3];
a[0]=0;
a[1]=1;
a[2]=2;
return a;
}
void fun5(int* p[3])
{
*p[0]=0; *(p[0]+1)=10;
*p[1]=1; *(p[1]+1)=11;
*p[2]=2; *(p[2]+1)=12;
}
//cannot convert from 'int [3]' to 'int *&
/*
int*& fun6()
{
int a[]={1,2,3};
return a;
}
*/
void main()
{
int* p=new int[3];
// int* p; //runtime error:the memory connot be written
//it is necessory to allocate memory
cout<<"test: void fun0(int* p)"<<endl;
fun0(p);
for(int i=0;i<3;i++){
cout<<*(p+i)<<endl;
}
delete[3] p;
p=new int[3];
cout<<endl<<"test: void fun1(int* &p)"<<endl;
fun1(p);
for(i=0;i<3;i++){
cout<<*(p+i)<<endl;
}
delete[3] p;
p=new int[3];
cout<<endl<<"test: void fun2(int* p)"<<endl;
cout<<" allocate memory for the parameter"<<endl;
fun2(p);
for(i=0;i<3;i++){
cout<<" "<<*(p+i)<<endl;
}
cout<<" donot allocate memory for the parameter"<<endl;
cout<<" memory connot be written"<<endl;
/*
int* pt;
fun2(pt); //runtime error:memory connot be written
for(i=0;i<3;i++){
cout<<*(pt+i)<<endl;
}
*/
delete[3] p;
p=new int[3];
cout<<endl<<"test: int* fun3()"<<endl;
cout<<" debug assertion failed"<<endl;
/*
p=fun3(); //debug assertion failed
for(i=0;i<3;i++){
cout<<*(p+i)<<endl;
}
*/
delete[3] p;
p=new int[3];
cout<&


相关文档:

C语言写的字节查询器(初学C练手用)

用C语言写的一个简单的字节型查询器,主要功能是实现对        signed int        float        unsigned int        double        s ......

Linux: S3C2410的RTC驱动

----------------------------------------------------------------------------------------------------------------------------------------
/**/
/*
********************************************************************************************************
*  @Description:s3c2410的rtc驱动的实 ......

常用的C/C++工程Makefile模板

转帖:一辉的文章
在Linux下做开发难免要接触makefile,整个项目的构建都依赖于它。100个developer有100种makefile的写法,在一个较大的项目中,各种各样的makefile无论在开发、后期维护还是整个系统的持续集成都是一个负担。
有幸参与重构一个遗留系统的makefile,以下是一些心得和一个makefile模板。
重构目的:
1.清 ......

Windows Via C/C++: CreateThread函数

CreateThread函数
前面讲过,进程的主线程会在CreateProcess调用时自动创建。假如你要手工创建线程,你可以调用CreateThread函数:
HANDLE CreateThread(
PSECURITY_ATTRIBUTES psa,
DWORD cbStackSize,
PTHREAD_START_ROUTINE pfnStartAddr,
PVOID pvParam,
DWORD dwCreateFlags,
PDWORD pdwThreadID) ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号