1.指针运算
注意 ,每个例子不只是一个题目,可能有多个,用
//....................................来分开的
# include <iostream>
# include <stdio.h>
using namespace std;
enum string
{
x1,x2,x3=10,x4,x5,
}X;
int main()
{
//测试1
cout << x1 << x5<<endl;
unsigned char *p1;
unsigned long *p2;
p1 = (unsigned char *)0x801000;
p2 = (unsigned long *)0x801000;
printf("%p\n",p1+5);
printf("%p\n",p2+5);
char * t [] = { "abccc","daa","caa"};
char **bb = t;
cout << t[1] <<endl;
cout << sizeof(t)<<endl;
//....................................
int a[5] = {1,2,3,4,5};
cout << *( (int *)(&a+1)-2) <<endl;
int i=0;
int j=1;
long *p = NULL;
char *c = NULL;
if(j++ && i++)
p++,c++;
if(i++ || j++)
p++,c++;
cout << i <<" " << j << " " << *p << " " << (long *)c <<endl;
//....................................
int i =1;
int c = (i++) + (i++) + (i++);
cout << c <<" "<< i<<endl;
return 0;
}
2.
# include <iostream>
# include <stdio.h>
using namespace std;
void foo(int k)
{
char tmp[100];
//sprintf(tmp,"%d",k);
printf("%d\n",tmp);
foo(k-1);
}
int main()
{
int i= 0;
int x= 0;
int y= 0;
printf("%d %d %d %d\n",x--,++y,i++,i++);
char tmp[20]="hello\0\t\\\\world";
cout<<tmp<<endl;
cout << sizeof(tmp) << " " <<strlen(tmp)<<" "<< tmp<<endl;
//....................................
char arr[100] = "hello world";
int *v = (int *)arr;
v[0] = 0X61626364;
v[1] = 0X41424344;
v[2] = 0X31323334;
v[3] = 0;
cout<<arr<<endl;
//....................................
foo(3);
return 0;
}