- P]
ҕУ@ƸPԇ}
1101044Ă(sh)ô24c?
(10*10-4)/4=24
2б_ʽ32λCgh(hun)µֵ()
class A
{
};
class B
{
public:
B();
virtual ~B();
};
class C
{
private:
#pragma pack(4)
int i;
short j;
float k;
char l[64];
long m;
char *p;
#pragma pack()
};
class D
{
private:
#pragma pack(1)
int i;
short j;
float k;
char l[64];
long m;
char *p;
#pragma pack()
};
int main(void)
{
printf("%d\n",sizeof(A));
printf("%d\n",sizeof(B));
printf("%d\n",sizeof(C));
printf("%d\n",sizeof(D));
return 0;
}
class A
{
};
class B
{
public:
B();
virtual ~B();
};
class C
{
private:
#pragma pack(4)
int i;
short j;
float k;
char l[64];
long m;
char *p;
#pragma pack()
};
class D
{
private:
#pragma pack(1)
int i;
short j;
float k;
char l[64];
long m;
char *p;
#pragma pack()
};
int main(void)
{
printf("%d\n",sizeof(A));
printf("%d\n",sizeof(B));
printf("%d\n",sizeof(C));
printf("%d\n",sizeof(D));
return 0;
}A148482 B448284 C448482 D148282
3³32λC\еĽY()
#pragma pack(4)
struct info_t
{
unsigned char version;
unsigned char padding;
unsigned char extension;
unsigned char count;
unsigned char marker;
unsigned char payload;
unsigned short sequence;
unsigned int timestamp;
unsigned int ssrc;
};
union info_u
{
unsigned char version;
unsigned char padding;
unsigned char extension;
unsigned char count;
unsigned char marker;
unsigned char payload;
unsigned short sequence;
unsigned int timestamp;
unsigned int ssrc;
};
#pragma pack()
int main(void)
{
printf("%d\n",sizeof(info_t));
printf("%d\n",sizeof(info_u));
return 0;
}
#pragma pack(4)
struct info_t
{
unsigned char version;
unsigned char padding;
unsigned char extension;
unsigned char count;
unsigned char marker;
unsigned char payload;
unsigned short sequence;
unsigned int timestamp;
unsigned int ssrc;
};
union info_u
{
unsigned char version;
unsigned char padding;
unsigned char extension;
unsigned char count;
unsigned char marker;
unsigned char payload;
unsigned short sequence;
unsigned int timestamp;
unsigned int ssrc;
};
#pragma pack()
int main(void)
{
printf("%d\n",sizeof(info_t));
printf("%d\n",sizeof(info_u));
return 0;
}A12 12 B12 4 C16 4 D16 12 E16 1
4±_ʽresultֵ()
#define VAL1(a,b) a*b
#define VAL2(a,b) a/b--
#define VAL3(a,b) ++a%b
int a = 1;
int b = 2;
int c = 3;
int d = 3;
int e = 5;
int result = VAL2(a,b)/VAL1(e,b)+VAL3(c,d);
#define VAL1(a,b) a*b
#define VAL2(a,b) a/b--
#define VAL3(a,b) ++a%b
int a = 1;
int b = 2;
int c = 3;
int d = 3;
int e = 5;
int result = VAL2(a,b)/VAL1(e,b)+VAL3(c,d);A-2 B1 C0 D2
5Ո³ݔ(5)
void swap_1(int a , int b)
{
int c;
c = a;
a = b;
b = c;
return ;
}
void swap_2(int &a , int &b)
{
int c;
c = a;
a = b;
b = c;
return ;
}
void swap_3(int *a , int *b)
{
int c;
c = *a;
*a = *b;
*b = c;
return ;
}
int main(void)
{
int a = 100;
int b = 200;
swap_1(a , b);
printf("a = %d , b = %d\n",a , b);
swap_2(a , b);
printf("a = %d , b = %d\n",a , b);
swap_3(&a , &b);
printf("a = %d , b = %d\n",a , b);
return 0;
}
void swap_1(int a , int b)
{
int c;
c = a;
a = b;
b = c;
return ;
}
void swap_2(int &a , int &b)
{
int c;
c = a;
a = b;
b = c;
return ;
}
void swap_3(int *a , int *b)
{
int c;
c = *a;
*a = *b;
*b = c;
return ;
}
int main(void)
{
int a = 100;
int b = 200;
swap_1(a , b);
printf("a = %d , b = %d\n",a , b);
swap_2(a , b);
printf("a = %d , b = %d\n",a , b);
swap_3(&a , &b);
printf("a = %d , b = %d\n",a , b);
return 0;
}ݔY
a = 100 , b = 200
a = 200 , b = 100
a = 100 , b = 200
6ijǷІ}І}Ոؘa(5)
void test_type(bool b , const char *p , float f)
{
if(!b)
{
return ;
}
else if(!p)
{
return ;
}
else if(!f)
{
return ;
}
}
void test_type(bool b , const char *p , float f)
{
if(!b)
{
return ;
}
else if(!p)
{
return ;
}
else if(!f)
{
return ;
}
}£
void test_type(bool b , const char *p , float f)
{
if(!b)
{
return ;
}
else if(!p)
{
return ;
}
else if(f > -1e-10 && f < 1e-10)
{
return ;
}
}
void test_type(bool b , const char *p , float f)
{
if(!b)
{
return ;
}
else if(!p)
{
return ;
}
else if(f > -1e-10 && f < 1e-10)
{
return ;
}
}7Ոָ³ʲô}(5)
void test_mem()
{
char *p = new char[64];
delete p;
p = NULL;
return ;
}
void test_mem()
{
char *p = new char[64];
delete p;
p = NULL;
return ;
}ԓĞ delete[]p; pָһַ͵Ĕ(sh)MgԭĴaֻǺεጷָՈgָ]ጷՈĿgɃȴ
ҕУ@ƸPԇ}
YϹƽ_
ҕУ@ƸPԇ}(http://www.shangyepx.com)new Ćăȴgĕr delete new[] һMăȴgĕr delete[]
ҕУ@ƸPԇ}P£
ҕУ@ƸǶʽ_l(f)Pԇ}06-24
У@ƸP(jng)10-31
У@ƸP(jng)10-29
S_HУ@ƸP(jng)10-03
У@ƸPԇ}05-26
W(wng)վУ@ƸPԇ}08-08
ܛУ@ƸPԇ}06-07
W(wng)У@ƸPԇ}10-06
У@ƸPԇ}Ŀ08-27