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++ÖÐËüÊÇÈçºÎÓ¦Óõģ¬ÕâÀïΪÁË·½±ãÀí½â£¬¶ÔÒÔÇ ......
Delphi Óë C/C++ Êý¾ÝÀàÐͶÔÕÕ±í
DelphiÊý¾ÝÀàÐÍC/C++
ShorInt
8λÓзûºÅÕûÊý
char
Byte
8λÎÞ·ûºÅÕûÊý
BYTE,unsigned short
SmallInt
16λÓзûºÅÕûÊý
short
Word
16λÎÞ·ûºÅÕûÊý
unsigned short
Integer,LongInt
32λÓзûºÅÕûÊý
int,long
Cardinal,LongWord/DWORD
32λÎÞ·ûºÅÕûÊý
unsigned long
Int6 ......
ÏÂÃæµÄÀý×Ó¶¼ÔÚUbuntu8.04 GCCϱàÒëµÄ½á¹û£¬ÓÐЩûÓиø½á¹û
±à³ÌÒ»¶¨Òª×Ô¼º¶¯ÊÖÊÔÒ»ÊÔ£¡
1.¶¨ÒåÓëÉùÃ÷£¬¶¨ÒåÒª·ÖÅäÄڴ棬ÉùÃ÷Ö»ÊÇÉùÃ÷Ôڱ𴦶¨ÒåÁË
int a; //¶¨Òå
extern int a; //ÉùÃ÷
char str[100]
extern char str[] //ok
char * str[]
extern char str[] //error
char ......
C±äÁ¿µÄ´æ´¢·½Ê½-¡°¾²Ì¬´æ´¢¡±ºÍ¡°¶¯Ì¬´æ´¢¡± ±äÁ¿µÄ´æ´¢·½Ê½¿É·ÖΪ¡°¾²Ì¬´æ´¢¡±ºÍ¡°¶¯Ì¬´æ´¢¡±Á½ÖÖ¡£ ¾²Ì¬´æ´¢±äÁ¿Í¨³£ÊÇÔÚ±äÁ¿¶¨Òåʱ¾Í·Ö¶¨´æ´¢µ¥Ôª²¢Ò»Ö±±£³Ö²»±ä£¬Ö±ÖÁÕû¸ö³ÌÐò½áÊø¡£È«¾Ö±äÁ¿¼´ÊôÓÚ´ËÀà´æ´¢·½Ê½¡£¶¯Ì¬´æ´¢±äÁ¿ÊÇÔÚ³ÌÐòÖ´Ðйý³ÌÖУ¬Ê¹ÓÃËüʱ²Å·ÖÅä´æ´¢µ¥Ôª£¬Ê¹ÓÃÍê±ÏÁ¢¼´ ......