1 strutsԼstrutsʵMVCܹģ
struts frameworkһֻjavaļWebӦó򿪷Աͨstruts frameworkɳơԼ"дһΡ"ŵ㡣StrutsṩһִWebӦóĿܣжӦóʾʾݵĺ˴˳StrutsjspΪMVCͼ,ActionServletָactionΪMVCеCͼģ֮Ľÿڵ㶼Ϊstruts-config.xmlļáļͼӳΪضJAVAԽӦĴָһͼλáStrutsеģҪָľjavabeanģ͵ĴҪװݺҵ߼

Java Java


1 strutsԼstrutsʵMVCܹģ
struts frameworkһֻjavaļWebӦó򿪷Աͨstruts frameworkɳơԼ"дһΡ"ŵ㡣StrutsṩһִWebӦóĿܣжӦóʾʾݵĺ˴˳StrutsjspΪMVCͼ,ActionServletָactionΪMVCеCͼģ֮Ľÿڵ㶼Ϊstruts-config.xmlļáļͼӳΪضJAVAԽӦĴָһͼλáStrutsеģҪָľjavabeanģ͵ĴҪװݺҵ߼
StrutsĴ̣
l гʼȡļΪͬStrutsģʼӦModulConfig
l Http󣬲ActionConfigҳӦڸAction࣬ûжӦActionֱӽתJSP߾̬ҳ棬ַActionд
l ڿþActionExecute֮ǰActionFormHttpеĲѡActionFormеValidateĺϷԣҿԷһдϢActionErrors
l ִоĵExecuteķִӦҵ߼ִ󣬷һActionForward󣬿ͨActionForwardתҲ԰ActionҪҵ߼װJavaBeanУϵͳлEJBôͨJavaBeanEJBҵûEJBôֱJavaBeanݿ⣬ݿصĲ

2MVCϵṹ
MVCmodelӦöviewͼcontrollerǿûûӦʽ
MVCϵУģͨΪ"ҵ߼"Ĵ룬ͼʹý棬ӳݵı仯ģͺͼ֮Ḷ̌ûͼͨϢԼѡϢģ
MVCУʾ߼룬ֿ໥пڿά˿Чʡ

3̵߳ŵ㡣
𣺿ɷ
1 ڵ̶߳ 
ӦĲ
߳ȡѭƣһֹ߳̿ͣϵͳĲִֵУҵһ߳ʱֻǸִ̼߳ͣ߳С
2 ڽ̶ԣ(ԴҲԲ)
ҪĿȽСתɱС
̹߳ͬһַռ䣬໥Э
˴֮ͨźס

4EJB
EJBҵJavaBeanṩ˹ҵҵ߼һģ͡
EJBΪ֣Session Bean Entity Bean Message-Driven Bean ֣Session BeanΪ״̬״̬Session Bean,Entity BeanΪEntity Bean ( CMP )  Bean Entity Bean ( BMP )ÿһEJBһԶ̽ӿڡһؽӿںһEJBʵɣԶ̽ӿṩEJBͻõĸӦ÷ؽӿ˴µEJBʵcreateѰEJBʵĲ(finder)ԼhEJBʵremoveEJBṩEJBлڵĹ
5 javaOracleݿ⡢ȡü¼

[b]5javaOracleݿ⡢ȡü¼
..........................
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection( url , username , password );
Statement stmt=conn.createStatement();
String str="select * from [table]";
ResultSet rs=stmt.executeQuery(str);
While(rs.next())
{
........................
}
rs.close();
stmt.close();
conn.close();

6 javaջ
Ĺԭ£
ڶһʱǾͼٶҪǸǸռеĴ洢ԪԱջأͨSystem.gc()գһҪѲõĶ־ΪnullΪѡ


7 javaǷԶ̳Уôʵֶ̳У
javaûж̳Уͨӿڵʽﵽ̳еĿء

8 ص
ص㣺װ̳С̬(Ҫشĸɼ  һص)

9ӿʲôŵ
𣺽ӿŵ㣺
l ӿֻһܶûʵ֣ڽӿڶʱҪǽӿеķʵ֡
l ýӿڿɴﵽʵֶ̳еĿء
l ڲ¶ǰ£¶ı̽ӿڡ
l ǿϵ޹нػƴ(Ϳ)
l ִеһ

10 ArrayList  Vector 
Ҫ˵
l ȫЧʷ
ҪʵͬȫҪVectorArrayListΪArrayListͬȫ⣬ЧҪЩ
l Դ
ߵʱǶԶVectorǰһArrayList50%ӣVectorܽʡԴ

ԤPreprocessor

1. Ԥָ#define һԱ1ж루⣩
#define SECONDS_PER_YEAR (60 * 60 * 24 * 365)UL 
뿴飺 
1). #define ﷨Ļ֪ʶ磺ԷֺŽŵʹãȵȣ 
2). ԤΪ㳣ʽֵˣֱдμһжǼʵʵֵǸûд۵ġ 
3). ʶʽʹһ16λ-ҪõͷL,߱ǵĳ 
4). ıʽõULʾ޷ųͣôһõ㡣סһӡҪ
C++⼯,C++Դ,C++,C++,C++Ծ

2. дһ׼MINؽСһ
#define MIN(A,B) (A<= B ?A: B) 

C\C++⼯ C\C++ Development ΪĿĶģ 

1). ʶ#defineںӦõĻ֪ʶǺҪģΪֱǶ(inline)Ϊ׼Cһ֣ǷǶΨһǶʽϵͳ˵ΪܴﵽҪܣǶ뾭Ǳķ 
2). ֪ʶCеԭʹñܲif-then-elseŻĴ룬˽÷ǺҪġ 
3). ںСĵذѲ 
4). Ҳ⿪ʼۺĸã磺дĴʱᷢʲô£ 
least = MIN(*p++, b);

3. Ԥʶ#errorĿʲô

㲻֪𰸣뿴ο1һĻƺһǺõġֻӲŻCԿαĸ¼ȥҳ 
Ĵ𰸡Ȼ㲻һӣôӦϣԼҪ֪𰸡

ѭInfinite loops

4. ǶʽϵͳоҪõѭôCдѭأ

üѡķǣ 
while(1) { } 
һЩԱϲ· 
for(;;) { } 
ʵַʽΪѣΪ﷨ûȷбﵽô¡һӦ߸ΪҽΪһȥ̽ 
ԭǵĻǣұû뵽Ϊʲôһӡ 
 goto 
Loop: 
... 
goto Loop; 
Ӧķ˵һԳԱҲǺ£һBASIC/FORTRANԱ

Data declarations 

5. ñaĶ 
a) һAn integer 
b) һָָ루A pointer to an integer 
c) һָָĵָ룬ָָָһA pointer to a pointer to an integer 
d) һ10飨An array of 10 integers 
e) һ10ָ飬ָָһģAn array of 10 pointers to integers 
f) һָ10ָ루A pointer to an array of 10 integers 
g) һָָ룬úһͲһA pointer to a function that takes an integer as an argument and returns an integer 
h) һ10ָ飬ָָһúһͲһ An array of ten pointers to functions that take an integer argument and return an integer 


ǣ 
a) int a; // An integer 
b) int *a; // A pointer to an integer 
c) int **a; // A pointer to a pointer to an integer 
d) int a[10]; // An array of 10 integers 
e) int *a[10]; // An array of 10 pointers to integers 
f) int (*a)[10]; // A pointer to an array of 10 integers 
g) int (*a)(int); // A pointer to a function a that takes an integer argument and returns an integer 
h) int (*a[10])(int); // An array of 10 pointers to functions that take an integer argument and return an integer 


ǾмҪһܻش⣬ͬ˵дƪʱΪȷ﷨ȷԣҵȷһ顣 
ǵұԵʱʵ⣨⣩ΪڱԵʱȷ֪Ĵ𰸡Ӧ֪ 
еĴ𰸣ٴ󲿷ִ𰸣ôҲûΪ׼ûΪ׼ôΪʲô׼أ


Static

6. ؼstaticʲô

򵥵ܻشȫCУؼstaticԵã 
1). ں壬һΪ̬ıһùάֵ䡣 
2). ģڣں⣩һΪ̬ıԱģúʣܱģʡһصȫֱ 
3). ģڣһΪ̬ĺֻɱһģڵáǾǣģıطΧʹá 
Ӧȷشһ֣һȷشڶ֣ͬǺٵܶõ֡һӦߵصȱ㣬ΪȻñػݺʹ뷶ΧĺôҪԡ


Const 

7ؼconstʲô⣿ 
ֻҪһ˵constζųҾ֪ںһҵߴ򽻵ȥDan SaksѾȫconst÷ESP(ߣEmbedded Systems Programming)ÿһλӦ÷ǳϤconstʲôͲʲô.
ûжƪ£ֻҪ˵constζšֻͿˡ𰸲ȫĴ𰸣ҽΪһȷĴ𰸡֪ϸĴ𰸣ϸһSaks°ɡӦȷش⣬ҽһӵ⣺ʲô˼

const int a; 
int const a; 
const int *a; 
int * const a; 
int const * a const;

ǰһaһζaһָָ루Ҳǣǲ޸ĵģָԣĸ˼aһָĳָ루Ҳ˵ָָǿ޸ĵģָǲ޸ĵģһζaһָĳָ루Ҳ˵ָָǲ޸ĵģͬʱָҲǲ޸ĵģӦȷشЩ⣬ô͸һӡ˳һ䣬ҲܻʣʹùؼconstҲܺдȷĳôΪʲôҪ˿عؼconstأҲµļɣ 
1). ؼconstΪ˴ǳõϢʵϣһΪΪ˸ûӦĿġܶʱµͻܿѧлϢȻconstĳԱٻµñġ 
2). ͨŻһЩӵϢʹùؼconstҲܲյĴ롣 
3). ʹùؼconstʹȻرЩϣıĲֹ䱻Ĵ޸ġ֮Լbugĳ֡

Volatile 

8. ؼvolatileʲô ͬӡ

һΪvolatileı˵ܻᱻ벻ظı䣬Ͳȥֵˡȷ˵ǣŻõʱÿζСĵ¶ȡֵʹñڼĴıݡvolatileļӣ 
1). 豸ӲĴ磺״̬Ĵ 
2). һжϷӳлʵķԶ(Non-automatic variables) 
3). ߳Ӧбı 
ش𲻳ǲᱻӶġΪCԱǶʽϵͳԱ⡣ǶʽϵͳԱͬӲжϡRTOSȵȴ򽻵ЩҪvolatilevolatileݽѡ 
豻ȷػش⣨ţҽ΢һ£һһǲֱvolatileȫҪԡ 
1). һȿconstvolatile𣿽Ϊʲô 
2). һָvolatile 𣿽Ϊʲô 
3). ĺʲô 
int square(volatile int *ptr) 
{ 
return *ptr * *ptr; 
} 
Ǵ𰸣 
1). ǵġһֻ״̬ĴvolatileΪܱ벻ظı䡣constΪӦͼȥ޸ 
2). ǵġⲢܳһǵһзӳ޸һָһbufferָʱ 
3). δи硣δĿָ*ptrֵָƽǣ*ptrָһvolatileͲĴ룺 
int square(volatile int *ptr) 
{ 
int a,b; 
a = *ptr; 
b = *ptr; 
return a * b; 
} 
*ptrֵܱ벻ظñ䣬abǲͬġδܷƽֵȷĴ£ 
long square(volatile int *ptr) 
{ 
int a; 
a = *ptr; 
return a * a; 
}

λBit manipulation

9. ǶʽϵͳҪûԱĴλһͱaдδ룬һabit 3ڶa bit 3УҪλ䡣

ֻķӦ 
1). ֪֡ñߴûκǶʽϵͳĹ 
2). bit fieldsBit fieldsǱӵCǵĶ֤Ĵڲ֮ͬǲֲģͬʱҲ֤˵ĴǲõġҿInfineonΪϸӵͨоƬдõbit fieldsȫãΪҵıķʽʵbit fieldsġӵ½ԶҪһǶʽļһճʵӲıߡ 
3).  #defines  bit masks һм߿ֲԵķӦñõķѵĽ£ 
#define BIT3 (0x1<<3) 
static int a; 
void set_bit3(void) 
{ 
a |= BIT3; 
} 
void clear_bit3(void) 
{ 
a &= ~BIT3; 
} 
һЩϲΪúֵһͬʱһЩ˵ҲǿԽܵġϣҪ㣺˵|=&=~

ʹ̶ڴλãAccessing fixed memory locations C\C++ Development

10. ǶʽϵͳҪԱȥĳضڴλõص㡣ĳУҪһԵַΪ0x67a9ͱֵΪ0xaa66һANSIдȥһ

һǷ֪Ϊ˷һԵַһǿתtypecastΪһָǺϷġһʵַʽŸ˷ͬͬ͵ƴ£ 
int *ptr; 
ptr = (int *)0x67a9; 
*ptr = 0xaa55;

һϻɬķǣ 
*(int * const)(0x67a9) = 0xaa55;

ʹƷζӽڶַҽʱʹõһַ

жϣInterrupts 

11. жǶʽϵͳҪɲ֣⵼˺ܶ뿪ṩһչñ׼C֧жϡߴʵǣһµĹؼ__interruptĴʹ__interruptؼȥһжϷӳ(ISR)һδġ

__interrupt double compute_area (double radius) 
{ 
double area = PI * radius * radius; 
printf(" Area = %f", area); 
return area; 
}

̫Ĵˣ˲֪Ӻ˵ˣ 
1). ISR ܷһֵ㲻ô㲻ᱻõġ 
2). ISR ܴݲûпһ㣬㱻õĻͬһ 
3). Ĵ/Уһ㶼ǲġЩ/ҪöļĴջЩ/ǲISR㡣⣬ISRӦǶ̶ЧʵģISRǲǵġ 
4). һУprintf()ϵ⡣㶪˵͵ĵ㣬Ҳ̫Ϊġ˵ܵõ㣬ôıǰԽԽˡ

ӣCode examples
12 . ĴʲôΪʲô

void foo(void) 
{ 
unsigned int a = 6; 
int b = -20; 
(a+b > 6) puts("> 6") : puts("<= 6"); 
}

Ƿ񶮵CеԶתԭҷЩ߶üЩΣ޷Ĵǡ>6ԭǵʽдзͺ޷ʱеĲԶתΪ޷͡ -20һǳԸñʽĽ6һӦƵõ޷͵Ƕʽϵͳ˵Ƿ᳣Ҫġ⣬Ҳ͵˵òݹıԵ

13. ĴƬϣ

unsigned int zero = 0; 
unsigned int compzero = 0xFFFF; 
/*1's complement of zero */

һintͲ16λĴΪ˵ĴǲȷġӦд£

unsigned int compzero = ~0;

һܽ¶ӦǷ񶮵ôֳҪԡҵľõǶʽԱǳ׼ȷӲϸںľޣȻPCӲΪһ޷ķա 
׶ΣӦ߻ȫͷɥ˻־ڱصáȻӦ߲ǺܺãôԾˡȻӦòôҾӳ׷⣬ЩǱȽѵģǳӦòЩ⣬ϣ࿴ӦӦķǴ𰸡Σ͵ְɡ


̬ڴ䣨Dynamic memory allocation


14. ܲǶʽôǶʽϵͳдӶѣheapж̬ڴĹ̵ġôǶʽϵͳУ̬ڴܷʲô

ӦᵽڴƬƬռ⣬ĳʱȵȡѾESP־б㷺۹ˣҪ P.J. Plauger, ĽԶԶᵽκνͣлعͷһЩ־ɣӦ߽һٵİȫоóôһСĿĴƬεʲôΪʲô

char *ptr; 
if ((ptr = (char *)malloc(0)) == NULL) 
puts("Got a null pointer"); 
else 
puts("Got a valid pointer"); 

һȤ⡣ҵһͬ²0ֵ˺mallocõһϷָ֮Ҳ뵽⡣Ĵ룬ôǡGot a valid pointerʼһ⣬Ƿ뵽ȷõȷĴ𰸹ȻҪķĻԭҪЩ

Typedef 

15. Typedef CƵһѾڵ͵ͬ֡ҲԤƵ¡磬˼һӣ 
#define dPS struct s * 
typedef struct s * tPS; 

ͼҪdPS  tPS Ϊһָṹsָ롣ַأеĻΪʲô 
һǳ΢⣬κ˴⣨ԭӦϲġǣtypedefá˼ӣ 
dPS p1,p2; 
tPS p3,p4;

һչΪ 
struct s * p1, p2;

Ĵ붨p1Ϊһָṹָp2ΪһʵʵĽṹҲҪġڶȷضp3 p4 ָ롣

ɬ﷨

16. CͬһЩ𾪵Ľṹ,ĽṹǺϷЩʲô 
int a = 5, b = 7, c; 
c = a+++b;

⽫ΪһĽβ಻ţȫϺ﷨ġǱδˮƽߵıʵϻ⣬ԭ򣬱ӦܴкϷ÷ˣĴ뱻ɣ 
c = a++ + b; 
, δкa = 6, b = 7, c = 12 
֪𰸣³ȷ𰸣úá㲻֪𰸣Ҳ⡣ҷô:һڴд񣬴ĿɶԣĿ޸ԵĺõĻ

What will print out? 

main() 
{ 
char *p1=name; 
char *p2; 
p2=(char*)malloc(20); 
memset (p2, 0, 20); 
while(*p2++ = *p1++); 
printf(%sn,p2); 

} 

Answer:empty string. 

What will be printed as the result of the operation below:

main() 
{ 
int x=20,y=35; 
x=y++ + x++; 
y= ++y + ++x; 
printf(%d%dn,x,y); 
} 

Answer : 5794 

What will be printed as the result of the operation below:

main() 
{ 
int x=5; 
printf(%d,%d,%dn,x,x< <2,x>>2); 
}

Answer: 5,20,1 

What will be printed as the result of the operation below:

#define swap(a,b) a=a+b;b=a-b;a=a-b; 
void main()
{ 
int x=5, y=10; 
swap (x,y); 
printf(%d %dn,x,y); 
swap2(x,y); 
printf(%d %dn,x,y); 
} 

int swap2(int a, int b) 
{ 
int temp; 
temp=a; 
b=a; 
a=temp; 
return 0; 

} 

Answer: 10, 5
10, 5 

What will be printed as the result of the operation below:

main()
{ 
char *ptr =  Cisco Systems; 
*ptr++; printf(%sn,ptr); 
ptr++; 
printf(%sn,ptr); 
} 

Answer:Cisco Systems
isco systems 

What will be printed as the result of the operation below:

main()
{ 
char s1[]=Cisco; 
char s2[]= systems; 
printf(%s,s1); 
} 
Answer: Cisco 

What will be printed as the result of the operation below:

main()
{ 
char *p1; 
char *p2; 
p1=(char *)malloc(25); 
p2=(char *)malloc(25); 

strcpy(p1,Cisco); 
strcpy(p2,systems); 
strcat(p1,p2); 

printf(%s,p1); 

} 

Answer: Ciscosystems 

The following variable is available in file1.c, who can access it?:

static int average;

Answer: all the functions in the file1.c can access the variable. 

WHat will be the result of the following code?

#define TRUE 0 // some code 
while(TRUE) 
{ 

// some code 

} 

Answer: This will not go into the loop as TRUE is defined as 0. 

What will be printed as the result of the operation below:

int x; 
int modifyvalue() 
{ 
return(x+=10); 
} 
int changevalue(int x) 
{ 
return(x+=1); 
} 

void main()
{ 
int x=10; 
x++; 
changevalue(x); 
x++; 
modifyvalue(); 
printf("First output:%dn",x); 

x++; 
changevalue(x); 
printf("Second output:%dn",x); 
modifyvalue(); 
printf("Third output:%dn",x); 

} 

Answer: 12 , 13 , 13 

What will be printed as the result of the operation below:

main()
{ 
int x=10, y=15; 
x = x++; 
y = ++y; 
printf(%d %dn,x,y); 
} 

Answer: 11, 16 

What will be printed as the result of the operation below:

main()
{ 
int a=0; 
if(a==0) 
printf(Cisco Systemsn); 
printf(Cisco Systemsn); 
} 

Answer: Two lines with Cisco Systems will be printed. 



ٴθC++⼯

1. ֱʲô[C]
char str1[] = "abc";
char str2[] = "abc";
const char str3[] = "abc"; 
const char str4[] = "abc"; 
const char* str5 = "abc";
const char* str6 = "abc";
cout << boolalpha << ( str1==str2 ) << endl; // ʲô
cout << boolalpha << ( str3==str4 ) << endl; // ʲô
cout << boolalpha << ( str5==str6 ) << endl; // ʲô

13. C++ڽͱ A  BļBʽתΪA[C++е]

a. class B : public A { } // Bм̳AǼӼ̳е
b. class B { operator A( ); } // BʵʽתΪAת
c. class A { A( const B& ); } // Aʵnon-explicitĲΪBĬֵĲ캯
d. A& operator= ( const A& ); // ֵ䲻ڵʽתҲǿһ

12. ´еsizeof÷[C]
void UpperCase( char str[] ) //  str еСдĸתɴдĸ
{
for( size_t i=0; i<sizeof(str)/sizeof(str[0]); ++i )
if( 'a'<=str[i] && str[i]<='z' )
str[i] -= ('a'-'A' );
}
char str[] = "aBcDe";
cout << "strַΪ: " << sizeof(str)/sizeof(str[0]) << endl;
UpperCase( str );
cout << str << endl;

7. ´ʲô⣿[C]
void char2Hex( char c ) // ַ16Ʊʾ
{
char ch = c/0x10 + '0'; if( ch > '9' ) ch += ('A'-'9'-1);
char cl = c%0x10 + '0'; if( cl > '9' ) cl += ('A'-'9'-1);
cout << ch << cl << ' ';
}
char str[] = "I love й";
for( size_t i=0; i<strlen(str); ++i )
char2Hex( str[i] );
cout << endl;

4. ´ʲô⣿[C++]
struct Test
{
Test( int ) {}
Test() {}
void fun() {}
};
void main( void )
{
Test a(1);
a.fun();
Test b();
b.fun();
}

5. ´ʲô⣿[C++]
cout << (true?1:"1") << endl;

8. ´ܹͨΪʲô[C++]
unsigned int const size1 = 2;
char str1[ size1 ];
unsigned int temp = 0;
cin >> temp;
unsigned int const size2 = temp;
char str2[ size2 ];

9. ´е0Ϊʲô[C++]
struct CLS
{
int m_i;
CLS( int i ) : m_i(i) {}
CLS()
{
CLS(0);
}
};
CLS obj;
cout << obj.m_i << endl;

10. C++еĿ࣬ĬϲЩԱ[C++]

class Empty
{
public:
Empty(); // ȱʡ캯
Empty( const Empty& ); // 캯
~Empty(); // 
Empty& operator=( const Empty& ); // ֵ
Empty* operator&(); // ȡַ
const Empty* operator&() const; // ȡַ const
};

3. ֱʲô[C++]
float a = 1.0f;
cout << (int)a << endl;
cout << (int&)a << endl;
cout << boolalpha << ( (int)a == (int&)a ) << endl; // ʲô
float b = 0.0f;
cout << (int)b << endl;
cout << (int&)b << endl;
cout << boolalpha << ( (int)b == (int&)b ) << endl; // ʲô

2. ·arrayķʲô[STL]
vector array;
array.push_back( 1 );
array.push_back( 2 );
array.push_back( 3 ); 

for( vector::size_type i=array.size()-1; i>=0; --i ) // array
{
cout << array[i] << endl;
}

6. ´ʲô⣿[STL]
typedef vector IntArray;
IntArray array;
array.push_back( 1 );
array.push_back( 2 );
array.push_back( 2 );
array.push_back( 3 );
// ɾarrayе2
for( IntArray::iterator itor=array.begin(); itor!=array.end(); ++itor )
{
if( 2 == *itor ) array.erase( itor );
}

11. дһڴ֮Ŀ[Ƿȫ]

 
void* mymemcpy( void *dest, const void *src, size_t count )
{
char* pdest = static_cast<char*>( dest );
const char* psrc = static_cast<const char*>( src );
if( pdest>psrc && pdest<psrc+cout ) ܿǵ
{
for( size_t i=count-1; i!=-1; --i )
pdest[i] = psrc[i];
}
else
{
for( size_t i=0; i<count; ++i )
pdest[i] = psrc[i];
}
return dest;
}
int main( void )
{
char str[] = "0123456789";
mymemcpy( str+1, str+0, 9 );
cout << str << endl;

system( "Pause" );
return 0;
}

29.дһһַ,ʮɵһַ,Ĺǰѽӵַתʮ.ʮַ.
30.дһһֳַ֣ǰ벿ְASCII򣬺벿ֲ䣬ַмַ䣬ٽǰֽȻ󽫸ַ
ַADZDDJKJFIEJHGI
31.Ҵ
Void test1()
{
char string[10];
char* str1="0123456789";
strcpy(string, str1);
}


Void test2()
{
char string[10], str1[10];
for(I=0; I<10;I++)
{
str1[i] ='a';
}
strcpy(string, str1);
}

Void test3(char* str1)
{
char string[10];
if(strlen(str1)<=10)
{
strcpy(string, str1);
}
}


32. Ҵ
#define MAX_SRM 256

DSN get_SRM_no()
{
static int SRM_no;
int I;
for(I=0;I{
SRM_no %= MAX_SRM;
if(MY_SRM.state==IDLE)
{
break;
}
}
if(I>=MAX_SRM)
return (NULL_SRM);
else
return SRM_no;
}


33. дн

int sum(int a)
{
auto int c=0;
static int b=3;
c+=1;
b+=2;
return(a+b+C);
}

void main()
{
int I;
int a=2;
for(I=0;I<5;I++)
{
printf("%d,", sum(a));
}
}

34. 

int func(int a)
{
int b;
switch(a)
{
case 1: 30;
case 2: 20;
case 3: 16;
default: 0
}
return b;
}
func(1)=?

35:
int a[3];
a[0]=0; a[1]=1; a[2]=2;
int *p, *q;
p=a;
q=&a[2];
a[q-p]=?

36. 
 int **a[3][4], ռеڴռΪ_____
37.
дһҪʱ룬ʱһ롣2004123123ʱ5959룬2005110ʱ00롣
38.дһжһint͵Ƿ2ݣǷԱʾ2^Xʽѭ
ֻ֪õƣдһ££
int IsTwoPow(int s)
{
if(s==1)return FALSE;
s=s>>1;
if(s>1)IsTwoPow(s);
return (s==1)?TRUE:FALSE;//˼һƺôأ
}

39 ABһѲ򣨹100򣬹£
(1)AãȻһһνã
2ÿֻ124
3˭һ˭ʧߣ
AB˭ʧߣджϲ衣
40.֪飬۰ңԪֵΨһ
ԭǣBinary_Seach(int array[], int iValue, int iCount)
array飬۰ҵķҵiValueֵҵ10iCountԪظ
41.ͳһֵַַĴ
42.100λϵĳļӷҪݽṹͼӷʵ֣
43.µģ"CASTCASTSATATATASA"Huffman롣
44.int (* (*f)(int, int))(int)ʾʲô壿
45.x=x+1x+=1x++ΪЧ򡣲˵Ϊʲô
46.׺ʽ A-(B+C/D)*Eĺ׺ʽʲô
47.struct S1
{
char c;
int i;
};
sizeof(S1) = ?

class X{
public:
X();
virtual ~X();
void myMemberFunc();
static void myStaticFunc();
virtual void myVirtualFunc();
private:
int i;
char * pstr;
char a;
}
sizeof(X) = ?
48.ҳַַ,"abractyeyt","dgdsaeactyey"ӴΪ"actyet"
49.һٸ,и,ҳ֮Ĳ.
50.дһʵֿ. Ϊһļ
㷨 
Algorithm Partition 
Input: sequence a0, ..., an-1 with n elements 
Output: permutation of the sequence such that all elements a0, ..., aj are less than or equal to all
elements ai, ..., an-1 (i > j) 
Method: 

choose the element in the middle of the sequence as comparison element x 
let i = 0 and j = n-1 
while ij 

search the first element ai which is greater than or equal to x 
search the last element aj which is less than or equal to x 
if ij 

exchange ai and aj 
let i = i+1 and j = j-1 
After partitioning the sequence, Quicksort treats the two parts recursively by the same procedure.
The recursion ends whenever a part consists of one element only. 
51.дһ㷨ⵥǷڻ(whether there is a loop in a link list),
Ҫ㷨Ӷ(Algorithm's complexityO(n)) ֻʹóռ(space is O(c)). 
ע⣬ֻ֪һָͷָ롣ĳǲģһֵĵطҲǲģпͷпм䡣ҪǼ, ƻĽṹ.
52.кѾͨ˵
bool Sort_Array(ArrayType * Pinputarray, ArrayType * Poutarray);
úڴֽܰΪ100MֽڵArrayType͵ArrayTypeһ
Ԥͣϸ޹ؽҪPinputarrayPoutarrayֱΪǰָָ롣
cԵαһ㷨ĺд뵽
룺ǰĴļΪchar * pinoutfilename Ϊ÷ֺŷָArrayType͵Ԫأװ4100Mֽڵ顣
Ĵļchar * poutoutfilename
53.Чʵķ28춼
54.
1.תַ ( )
A.'\091' B.'\\'
C.'\0' D.'\''

2.ʵζָβΣʵδβε ( )
A.ĳ B.һԪصֵ
C.Ԫصֵ D.һԪصĵַ

3.ָ뺬ָ ( )
A.ֵ B.ַ
C.洢 D.

5.ĳļжľ̬ȫֱ(ƾ̬ⲿ) ( )
A.ֻĳ B.ļ
C.ļ D.
55.
1. η:a*x*x+b*x+c
int Quadratic( double a,double b,double c,double& x1,double& x2);
ֵĸ

2. Լ
DWORD Divisor( DWORD dwFirst, DWORD dwSecond );
ֵԼ

3. ؿ㷨Բ
double PI( DOWRD dwCount/*Դ*/ )
ֵPI

4. ޷˷Ϊ32bitΪ64bit
ʾ32bitֽΪ16bit
void Multiply( DWORD dwFirst, DWORD dwSecond, DWORD& dwHigh, DWORD& dwLower );

5. (С)
ڵ㶨Ϊ
struct Node{
int nValue;
struct Node* pNext;
};
һڵpNext = NULL.
Node* SortChain( Node* pHead );
ֵͷ


25.<<,>>,|,&ʵһWORD(2ֽ)ĸߵλ!!
26.ҪP1,P2,P3,P4ڴ,СԶ,ĸĴСҪһ,!
27.һA,CдһʵֶԸAн,,ҪҪAΪ.(ð)
28.Ҵ
#include <string.h>
#include <stdio.h>
class Base
{
private:
char * name;
public:
Base(char * className)
{
name = new char[strlen(className)];
strcpy(name, className);
}
~Base()
{
delete name;
}
char * copyName()
{
char newname [256];
strcpy(newname, name);
return newname;
}
char * getName()
{
return name;
}
static void print(Base base)
{
printf("name: %s\n" , base.name);
}
};
class Subclass : public Base
{
public:
Subclass(char * className) : Base(className)
{
}
};
int main()
{
Base * pBase = new Subclass("test");
Base::print(*pBase);
printf("name: %s\n", pBase->getName());
printf("new name: %s\n", pBase->copyName());
return 0;
}


1. ֱʲô[C]
char str1[] = "abc";
char str2[] = "abc";
const char str3[] = "abc"; 
const char str4[] = "abc"; 
const char* str5 = "abc";
const char* str6 = "abc";
cout << boolalpha << ( str1==str2 ) << endl; // ʲô
cout << boolalpha << ( str3==str4 ) << endl; // ʲô
cout << boolalpha << ( str5==str6 ) << endl; // ʲô

³http://www.netfetch.cn/
2. C++ڽͱ A  BļBʽתΪA[C++е]

a. class B : public A { } // Bм̳AǼӼ̳е
b. class B { operator A( ); } // BʵʽתΪAת
c. class A { A( const B& ); } // Aʵnon-explicitĲΪBĬֵĲ캯
d. A& operator= ( const A& ); // ֵ䲻ڵʽתҲǿһ

3. ´еsizeof÷[C]
void UpperCase( char str[] ) //  str еСдĸתɴдĸ
{
for( size_t i=0; i<sizeof(str)/sizeof(str[0]); ++i )
if( 'a'<=str[i] && str[i]<='z' )
str[i] -= ('a'-'A' );
}
char str[] = "aBcDe";
cout << "strַΪ: " << sizeof(str)/sizeof(str[0]) << endl;
UpperCase( str );
cout << str << endl;

4. ´ʲô⣿[C]
void char2Hex( char c ) // ַ16Ʊʾ
{
char ch = c/0x10 + '0'; if( ch > '9' ) ch += ('A'-'9'-1);
char cl = c%0x10 + '0'; if( cl > '9' ) cl += ('A'-'9'-1);
cout << ch << cl << ' ';
}
char str[] = "I love й";
for( size_t i=0; i<strlen(str); ++i )
char2Hex( str[i] );
cout << endl;

5. ´ʲô⣿[C++]
struct Test
{
Test( int ) {}
Test() {}
void fun() {}
};
void main( void )
{
Test a(1);
a.fun();
Test b();
b.fun();
}

6. ´ʲô⣿[C++]
cout << (true?1:"1") << endl;

7. ´ܹͨΪʲô[C++]
unsigned int const size1 = 2;
char str1[ size1 ];
unsigned int temp = 0;
cin >> temp;
unsigned int const size2 = temp;
char str2[ size2 ];

8. ´е0Ϊʲô[C++]
struct CLS
{
int m_i;
CLS( int i ) : m_i(i) {}
CLS()
{
CLS(0);
}
};
CLS obj;
cout << obj.m_i << endl;

9. C++еĿ࣬ĬϲЩԱ[C++]

class Empty
{
public:
Empty(); // ȱʡ캯
Empty( const Empty& ); // 캯
~Empty(); // 
Empty& operator=( const Empty& ); // ֵ
Empty* operator&(); // ȡַ
const Empty* operator&() const; // ȡַ const
};

10. ֱʲô[C++]
float a = 1.0f;
cout << (int)a << endl;
cout << (int&)a << endl;
cout << boolalpha << ( (int)a == (int&)a ) << endl; // ʲô
float b = 0.0f;
cout << (int)b << endl;
cout << (int&)b << endl;
cout << boolalpha << ( (int)b == (int&)b ) << endl; // ʲô

11. ·arrayķʲô[STL]
vector array;
array.push_back( 1 );
array.push_back( 2 );
array.push_back( 3 );
for( vector::size_type i=array.size()-1; i>=0; --i ) // array
{
cout << array[i] << endl;
}

12. ´ʲô⣿[STL]
typedef vector IntArray;
IntArray array;
array.push_back( 1 );
array.push_back( 2 );
array.push_back( 2 );
array.push_back( 3 );
// ɾarrayе2
for( IntArray::iterator itor=array.begin(); itor!=array.end(); ++itor )
{
if( 2 == *itor ) array.erase( itor );
}

13. дһڴ֮Ŀ[Ƿȫ]

void* mymemcpy( void *dest, const void *src, size_t count )
{
char* pdest = static_cast<char*>( dest );
const char* psrc = static_cast<const char*>( src );
if( pdest>psrc && pdest<psrc+cout ) ܿǵ
{
for( size_t i=count-1; i!=-1; --i )
pdest[i] = psrc[i];
}
else
{
for( size_t i=0; i<count; ++i )
pdest[i] = psrc[i];
}
return dest;
}
int main( void )
{
char str[] = "0123456789";
mymemcpy( str+1, str+0, 9 );
cout << str << endl;

system( "Pause" );
return 0;
}


ڿC++/CԱĻ̼ܡC++/C﷨漰ݽṹ㷨Լµ﷨ԳɼܷӳıԼC++/C̶ȣܷӳ
ʱ90ӡ뿼⣬ӡ


һдBOOL , float, ָ 롰ֵȽϵ if 䡣10֣

ʾֵ0, 0.0 , FALSEߡָ롱 int  n 롰ֵȽϵ if Ϊ

if ( n == 0 )
if ( n != 0 )
Դơ

д BOOL flag 롰ֵȽϵ if 䣺
д float x 롰ֵȽϵ if 䣺
д char *p 롰ֵȽϵ if 䣺

ΪWindows NTµ32λC++sizeofֵ10֣
char str[] = Hello ;
char *p = str ;
int n = 10;

sizeof (str ) = 
sizeof ( p ) = 
sizeof ( n ) =
void Func ( char str[100])
{

sizeof( str ) = 
}

void *p = malloc( 100 );

sizeof ( p ) =

⣨25֣
1ͷļе ifndef/define/endif ʲôã
2#include  #include filename.h ʲô
3const ʲô;˵֣
4C++ еñ CĺΪʲôҪ extern C
5forѭȱ
// һ
for (i=0; i++;)
{
if (condition)
DoSomething();
else
DoOtherthing();
}
// ڶ

if (condition)
{
for (i=0; i++;)
DoSomething();
}
else
{
for (i=0; i++;)
DoOtherthing();
}

ŵ㣺
ȱ㣺
ŵ㣺
ȱ㣺

ġйڴ˼⣨20֣
void GetMemory(char *p)
{
p = (char *)malloc(100);
}

void Test(void) 
{
char *str = NULL;
GetMemory(str); 
strcpy(str, "hello world");
printf(str);
}


TestʲôĽ


char *GetMemory(void)
{ 
char p[] = "hello world";
return p;
}

void Test(void)
{
char *str = NULL;
str = GetMemory(); 
printf(str);
}


TestʲôĽ

Void GetMemory2(char **p, int num)
{
*p = (char *)malloc(num);
}

void Test(void)
{
char *str = NULL;
GetMemory(&str, 100);
strcpy(str, "hello"); 
printf(str); 
}

TestʲôĽ


void Test(void)
{
char *str = (char *) malloc(100);
strcpy(str, hello);
free(str); 
if(str != NULL)
{
strcpy(str, world); 
printf(str);
}
}

TestʲôĽ



塢дstrcpy10֣
֪strcpyԭ
char *strcpy(char *strDest, const char *strSrc);
strDestĿַstrSrcԴַ
1C++/Cַ⺯д strcpy
2strcpyܰstrSrcݸƵstrDestΪʲôҪchar * ͵ķֵ

дStringĹ캯͸ֵ25֣
֪StringԭΪ
class String
{
public:
String(const char *str = NULL); // ͨ캯
String(const String &other); // 캯
~ String(void); // 
String & operate =(const String &other); // ֵ

private:
char *m_data; // ڱַ
};

дString4

³http://www.netfetch.cn/
³깤http://www.netfetch.cn/
¼C C++/CĴֱ׼
һдBOOL , float, ָ 롰ֵȽϵ if 䡣10֣

д BOOL flag 롰ֵȽϵ if 䡣3֣

׼𰸣
if ( flag )
if ( !flag )
д񣬲÷֡

if (flag == TRUE) 
if (flag == 1 ) 
if (flag == FALSE) 
if (flag == 0) 

д float x 롰ֵȽϵ if 䡣4֣

׼ʾ

const float EPSINON = 0.00001;
if ((x >= - EPSINON) && (x <= EPSINON)
ɽá==򡰣=ֱȽϣӦ跨תɡ>=<=ʽ

Ǵд÷֡

if (x == 0.0) 
if (x != 0.0) 



д char *p 롰ֵȽϵ if 䡣3֣

׼𰸣

if (p == NULL)
if (p != NULL)
д񣬲÷֡

if (p == 0) 
if (p != 0) 

if (p) 
if (!) 

ΪWindows NTµ32λC++sizeofֵ10֣
char str[] = Hello ;
char *p = str ;
int n = 10;

sizeof (str ) = 6 2֣ 
sizeof ( p ) = 4 2֣
sizeof ( n ) = 4 2֣
void Func ( char str[100])
{

sizeof( str ) = 4 2֣
}

void *p = malloc( 100 );

sizeof ( p ) = 4 2֣

⣨25֣
1ͷļе ifndef/define/endif ʲôã5֣
𣺷ֹͷļظá

2#include  #include filename.h ʲô𣿣5֣

ΪC\C++

Q1:ֱ𻮻OSI߲ṹͼTCP/IPṹͼ 
: Q2:ϸĽһIPЭĶ壬ĸ棬Ҫʲôã 
: TCPUDPأ 
: ܵ˵ǰĿǱȽϼ򵥵ģ 
: Q3:ʽ·ֱʵԭʲôֱĸʵ 
: ֵģ 
: Q4:C++Cstructʲô 
: Q5:뽲һ麯÷ã 
: Q6:ȫֱ;ֲʲôʵôʵֵģϵͳͱ 
: ô֪ģ 
: Q7:һЩĴĿ˾ʵʲôĿҪѰַ 
: һЩ֪ʶǵˡ 
: Q8:8086ǶξϵͳôʵֵģһЩӲ 
: ֪ʶҼȲˡ 

: һ㽨μӻΪзԵͬѧҪ׼һص֪ʶҪ 
: ǿCݽṹģӲģ磬΢ԭ 

c 

1һѧϢǣѧţԱϢһЩѧϢһ һage, ЩɾѧageѧϢ

 
i nclude "stdio.h"
i nclude "conio.h"

struct stu{
char name[20];
char sex;
int no;
int age;
struct stu * next;
}*linklist;
struct stu *creatlist(int n)
{
int i;
//hΪͷ㣬pΪǰһ㣬sΪǰ
struct stu *h,*p,*s;
h = (struct stu *)malloc(sizeof(struct stu));
h->next = NULL;
p=h;
for(i=0;i<n;i++)
{ 
s = (struct stu *)malloc(sizeof(struct stu));
p->next = s;
printf("Please input the information of the student: name sex no age \n");
scanf("%s %c %d %d",s->name,&s->sex,&s->no,&s->age);
s->next = NULL;
p = s;
}
printf("Create successful!");
return(h);
}
void deletelist(struct stu *s,int a)
{
struct stu *p;
while(s->age!=a)
{
p = s;
s = s->next;
}
if(s==NULL)
printf("The record is not exist.");
else
{
p->next = s->next;
printf("Delete successful!");
}
}
void display(struct stu *s)
{
s = s->next;
while(s!=NULL)
{
printf("%s %c %d %d\n",s->name,s->sex,s->no,s->age);
s = s->next;
}
}
int main()
{
struct stu *s;
int n,age;
printf("Please input the length of seqlist:\n");
scanf("%d",&n);
s = creatlist(n);
display(s);
printf("Please input the age:\n");
scanf("%d",&age);
deletelist(s,age);
display(s);
return 0;
}

2ʵһһַеַСдתΪд

 
i nclude "stdio.h"
i nclude "conio.h"

void uppers(char *s,char *us)
{
for(;*s!='\0';s++,us++)
{
if(*s>='a'&&*s<='z')
*us = *s-32;
else
*us = *s;
}
*us = '\0';
}
int main()
{
char *s,*us;
char ss[20];
printf("Please input a string:\n");
scanf("%s",ss);
s = ss;
uppers(s,us);
printf("The result is:\n%s\n",us);
getch();
}
