[C/C++ Digestion] – ×Ôµ×ÏòÉϵØ̽¾¿Ð麯Êý
[C/C++ Digestion] –
×Ôµ×ÏòÉϵØ̽¾¿Ð麯Êý
×÷Õߣº
Jason Lee @
http://blog.csdn.net/jasonblog
ÈÕÆÚ£º
2010-05-19
»·¾³£º
Visual C++ Express
2008
ÉùÃ÷£º±¾ÎÄ·¢±íÔÚ
csdn
²©¿Í£¬ÈçÓÐתÔØ£¬Çë×¢Ã÷³ö´¦
[1]C++
¶ÔÏóÄ£ÐÍ»ù´¡
Ò»¸öÀàÖпÉÒÔ°üº¬¾²Ì¬Êý¾Ý³ÉÔ±¡¢¾²Ì¬³ÉÔ±º¯Êý¡¢·Ç¾²Ì¬³ÉÔ±º¯ÊýºÍ·Ç¾²Ì¬Êý¾Ý³ÉÔ±ÒÔ¼°Ð麯Êý¡£ÆäÖУ¬Ç°ÈýÕߣ¨¾²Ì¬Êý¾Ý³ÉÔ±¡¢¾²Ì¬³ÉÔ±º¯Êý¡¢·Ç¾²Ì¬³ÉÔ±º¯Êý£©¶¼²¢Ã»Óб»·Åµ½¶ÔÏóµÄ²¼¾ÖÖУ¬¿ÉÒÔ´ÓÒÔÏÂÁ½¶Î´úÂëµÃµ½ÑéÖ¤£º
#include <iostream>
using namespace std;
class Base {
};
int main(){
Base a;
cout << sizeof (a) << endl;// Êä³ö1
return 0;
}
ÉÏÊöµÄ
Base
ÀàÊÇÒ»¸ö¿ÕÀ࣬ռ¾ÝÁËÒ»¸ö×Ö½ÚµÄÄÚ´æ¿Õ¼ä£¬ÕâÊÇΪÁ˱£Ö¤Ã¿¸öÀàʵÀý»¯ºó¶¼ÓµÓжÀÒ»ÎÞ¶þµÄÄÚ´æ¿Õ¼ä¡£½Ó×ÅÎÒÃÇÍù
Base
ÀàÖÐÌí¼Ó¾²Ì¬Êý¾Ý³ÉÔ±¡¢¾²Ì¬³ÉÔ±º¯ÊýºÍ·Ç¾²Ì¬³ÉÔ±º¯Êý£º
#include <iostream>
using namespace std;
class Base {
public :
Base(){}
~Base(){}
static int v1;
static void f1(){}
void f2(){}
};
int main(){
Base a;
cout << sizeof (a) << endl;// ÈÔÈ»Êä³ö1
return 0;
}
ÔÚ¾¹ýÄÚÈÝÌî³äºó£¬
Base
ÀàµÄʵÀý
a
ÈÔÈ»½öÕ¼¾Ý
1
¸ö×Ö½ÚµÄÄÚ´æ¿Õ¼ä£¬Óë¿ÕÀàÎÞÒ죬Õâ˵Ã÷Á˾²Ì¬Êý¾Ý³ÉÔ±¡¢¾²Ì¬³ÉÔ±º¯ÊýºÍ·Ç¾²Ì¬³ÉÔ±º¯Êý²¢Î´±»·ÅÔÚ¶ÔÏóµÄÄÚ´æ²¼¾Öµ±ÖÐ
¡£
½ÓÏÂÀ´ÍùÀàÖÐÌí¼Ó·Ç¾²Ì¬Êý¾Ý³ÉÔ±£º
#include <iostream>
using namespace std;
class Base {
public :
int a;
int b;
};
int main(){
Base a;
cout << sizeof (a) << endl;// Êä³ö8
cout << hex << &a << endl;// Êä³ö0012F 3CC
cout << hex << &a.a << endl;// Êä³ö0012F 3CC
cout << hex << &a.b << endl;// Êä³ö0012F 3D0
return 0;
}
´ÓÉÏÃæµÄ´úÂë¿ÉÒÔ¿´³ö£ºÒ»£¬·Ç¾²Ì¬Êý¾Ý³ÉÔ±Êǻᱻ·Åµ½¶ÔÏóµÄÄÚ´æ²¼¾ÖÖУ»¶þ£¬Êý¾Ý³ÉÔ±ÊǸù¾ÝÉùÃ÷˳ÐòÓÐÐòµØÔÚÄÚ´æÖнøÐзֲ¼µÄ£»Èý£¬ÔÚûÓÐÐ麯ÊýµÄÇé¿ö϶ÔÏóËùÕ¼¾ÝµÄÄÚ´æ´óС¾ÍÊÇÊý¾Ý³ÉÔ±ËùÕ¼¾ÝµÄ¿Õ¼äÖ®ºÍ¡£²¼¾ÖÈçÏÂͼ£º
a
b
ÄÇôÈç¹ûÌí¼ÓÁËÐ麯ÊýÒÔºóÄØ£¿ÏÈ¿´Ò»¶Î´úÂ룺
#include <iostream>
usin
Ïà¹ØÎĵµ£º
CÖÐÈçºÎµ÷ÓÃC++£¿C++ÖÐÈçºÎµ÷ÓÃC?Õâ¸öÎÊÌâÊÇÐí¶àÈí¼þ¹«Ë¾ÃæÊÔ¹ý³ÌÖлáÎʵ½µÄÒ»¸ö³£¼ûÎÊÌâ¡£»Ø´ðÕâ¸öÎÊÌâ²¢²»À§ÄÑ£¬ÄǾÍÊÇʹÓÃ
extern "C",µ«ÊÇÃæÊÔ¹Ù¿ÉÄÜÏëͨ¹ýÕâ¸öÎÊÌâÁ˽âÄã¶ÔC/C++ÕÆÎյij̶ȡ£ÏÂÃæ×Ðϸ·ÖÎö¸ÃÎÊÌâ¡£
Ê×ÏÈ£¬×÷
ΪexternÊÇC/C++ÓïÑÔÖбíÃ÷º¯ÊýºÍÈ«¾Ö±äÁ¿×÷Ó÷¶Î§£¨¿ ......
Eclipse³ýÁË¿ÉÒÔ開發JavaÖ®Í⣬還Ö§Ô®ÁË許¶à語ÑÔ£¬現ÔÚÏȽé紹
C¡¢C++µÄ開發環¾³設¶¨£¬ÒÔááÓÐ機會ÔÙ½é紹ÆäËüµÄ¡£Enjoy it£¡
OS£ºWindows XP Professional SP1
ʹÓð汾£ºEclipse 2.1.2
Ò».Ê×ÏÈÒªÏÂ載CDT£¬Eclipse 2.1.2 ......
Ê×ÏÈ¿´ÏÂÏÂÃæÕâ¶Î£º
int main()
{
char *name = "fengkewei";
char name1[] = "fengkewei";
char *name2 = "fengkewei";
char *name3 = "woaifengkewei";
int i = 10;
int j = 10;
int k = 11;
return 0;
}
ÈôÄú¾õµÃËüÃÇÓ¦¸Ã¶¼±£´æÔÚÄÚ´æÖеÄÒ»¿éµØ·½£¬ÄÇÇëÍùÏ¿´¡£¡£¡£¡£
ÏÂÃæÊDZàÒëÆ÷Ϊ¸÷¸ö±äÁ¿·ÖÅäµÄÄÚ´æµØ ......
freadº¯ÊýºÍfwriteº¯Êý
1.º¯Êý¹¦ÄÜ
ÓÃÀ´¶Áдһ¸öÊý¾Ý¿é¡£
2.Ò»°ãµ÷ÓÃÐÎʽ
fread(buffer,size,count,fp);
fwrite(buffer,size,count,fp);
3.˵Ã÷
£¨1£©buffer£ºÊÇÒ»¸öÖ¸Õ룬¶ÔfreadÀ´Ëµ£¬ËüÊǶÁÈëÊý¾ÝµÄ´æ·ÅµØÖ·¡£¶ÔfwriteÀ´Ëµ£¬ÊÇÒªÊä³öÊý¾ÝµÄµØÖ·¡£
£¨2£©size£ºÒª¶ÁдµÄ×Ö½ÚÊý ......