作者在 2011-04-08 20:23:05 发布以下内容
如果你得了
100分: 恭喜,你完全掌握了,或许你是这方面的专家,我得拜你为师,我想你一定精通编译方法?
80分左右: 你已经把C语言指针掌握的差不多了,不过还得努力,要有点成绩不容易.
60分左右: 你会使用基本指针,但是你不完全理解指针的实质
低于60分: 你或许是个初学者,指针使你认为C语言简直是折磨人
100分: 恭喜,你完全掌握了,或许你是这方面的专家,我得拜你为师,我想你一定精通编译方法?
80分左右: 你已经把C语言指针掌握的差不多了,不过还得努力,要有点成绩不容易.
60分左右: 你会使用基本指针,但是你不完全理解指针的实质
低于60分: 你或许是个初学者,指针使你认为C语言简直是折磨人
第一题:
main()
{
char *p,*q;
char str[]="Hello,World\n";
q = p = str;
p++;
printf(q);
printf(p);
}
运行结果是什么?Hello,World
ello,World
第二题:
void fun(char* str1, char* str2)
{
static char buffer[21];
strncpy(buffer, str1, 10);
strncat(buffer, str2, 10);
*str1 = *str2;
str1 = buffer;
}
main()
{
char *str1="ABC\n";
char *str2="BCD\n";
fun(str1, str2);
printf(str1);
printf(str2);
}
程序运行结果是__________________
main()
{
char *p,*q;
char str[]="Hello,World\n";
q = p = str;
p++;
printf(q);
printf(p);
}
运行结果是什么?Hello,World
ello,World
第二题:
void fun(char* str1, char* str2)
{
static char buffer[21];
strncpy(buffer, str1, 10);
strncat(buffer, str2, 10);
*str1 = *str2;
str1 = buffer;
}
main()
{
char *str1="ABC\n";
char *str2="BCD\n";
fun(str1, str2);
printf(str1);
printf(str2);
}
程序运行结果是__________________
第三题:
main()
{
short ar[11]={1,2,3,4,5,6,7,8,9,0,11};
short* par=&ar[1];
int i;
for(i=0; i<10; i++)
{
printf("%-5hd%-5hd%-5hd", ar[i], par[i],*(ar+i));
}
}
程序运行结果是__________________
main()
{
short ar[11]={1,2,3,4,5,6,7,8,9,0,11};
short* par=&ar[1];
int i;
for(i=0; i<10; i++)
{
printf("%-5hd%-5hd%-5hd", ar[i], par[i],*(ar+i));
}
}
程序运行结果是__________________
第四题:
main()
{
short *p, *q;
short ar[10]={0};
p = q = ar;
p++;
printf("%5d", p-q);
printf("%5d", (char*)p - (char*)q);
printf("%5d", sizeof(ar)/sizeof(*ar));
}
假设sizeof(short)==2
程序运行结果是__________________
main()
{
short *p, *q;
short ar[10]={0};
p = q = ar;
p++;
printf("%5d", p-q);
printf("%5d", (char*)p - (char*)q);
printf("%5d", sizeof(ar)/sizeof(*ar));
}
假设sizeof(short)==2
程序运行结果是__________________
第五题:
int sub(int a, int b)
{
return a-b;
}
int sub(int a, int b)
{
return a-b;
}
main()
{
typedef int (*SUB)(int, int);
SUB psub=sub;
/* psub++; */
printf("%d", psub(10,(10,5)));
}
{
typedef int (*SUB)(int, int);
SUB psub=sub;
/* psub++; */
printf("%d", psub(10,(10,5)));
}
程序运行结果是__________________, 如果将中间注释掉的语句加上, 编译为什么会报错?
第六题:
main()
{
char* pstrar[3];
int i;
for(i=1; i<3; i++)
{
pstrar[i]=" ";
}
strcpy(pstrar[1], "你好");
/* strcpy(pstrar[0], "世界"); */
printf(pstrar[2]);
}
假设编译器设置字符串常量为可读写,则程序结果是_____________
为什么说注释掉的程序语句是不正确的?
main()
{
char* pstrar[3];
int i;
for(i=1; i<3; i++)
{
pstrar[i]=" ";
}
strcpy(pstrar[1], "你好");
/* strcpy(pstrar[0], "世界"); */
printf(pstrar[2]);
}
假设编译器设置字符串常量为可读写,则程序结果是_____________
为什么说注释掉的程序语句是不正确的?
第七题:
main()
{
char *p1,*p2;
{
char* pchar;
char charar[] = "你好,世界";
pchar = "Hello,World!";
p1 = pchar;
p2 = charar;
}
printf(p1);
printf(p2);
}
说出此程序的错误之处?
main()
{
char *p1,*p2;
{
char* pchar;
char charar[] = "你好,世界";
pchar = "Hello,World!";
p1 = pchar;
p2 = charar;
}
printf(p1);
printf(p2);
}
说出此程序的错误之处?
第八题:
main()
{
int i;
char **p;
int msg[16]={0x40, 0x41, -1, 0x00, 0x01, -1, 0x12, -1, 0x20, 0x27, 0x41, 0x35, -1, 0x51, 0x12, 0x04};
char* strar[]={"bejing", "shanghai", "guangzhou", "guangdong", "Tokyo", "American"};
char* (*pstrar)[6];
pstrar = &strar;
p = strar;
main()
{
int i;
char **p;
int msg[16]={0x40, 0x41, -1, 0x00, 0x01, -1, 0x12, -1, 0x20, 0x27, 0x41, 0x35, -1, 0x51, 0x12, 0x04};
char* strar[]={"bejing", "shanghai", "guangzhou", "guangdong", "Tokyo", "American"};
char* (*pstrar)[6];
pstrar = &strar;
p = strar;
for(i=0; i<16; i++)
{
if(msg[i] == -1)
{
putchar(' ');
continue;
}
else if(msg[i]&0xF0 == 0x40)
{
putchar(p[msg[i]>>4][msg[i]&0x0F]);
continue;
}
else if(msg[i]&0xF0 == 0x30)
{
putchar(*(strar[msg[i]>>4]+(msg[i]&0x0F)));
continue;
}
else
{
putchar(*((*pstrar)[msg[i]>>4]+(msg[i]&0x0F)));
}
}
}
此题有故弄玄虚之处,但如理解指针,不难解出.
请问此题的运行结果是____________________
{
if(msg[i] == -1)
{
putchar(' ');
continue;
}
else if(msg[i]&0xF0 == 0x40)
{
putchar(p[msg[i]>>4][msg[i]&0x0F]);
continue;
}
else if(msg[i]&0xF0 == 0x30)
{
putchar(*(strar[msg[i]>>4]+(msg[i]&0x0F)));
continue;
}
else
{
putchar(*((*pstrar)[msg[i]>>4]+(msg[i]&0x0F)));
}
}
}
此题有故弄玄虚之处,但如理解指针,不难解出.
请问此题的运行结果是____________________
第九题:
main()
{
typedef char CA3[2][2][2];
typedef CA3 *PCA3;
typedef char CA2[2][2];
typedef CA2* PCA2[2];
CA3 ca3={'A', '\0', 'B', '\0', 'C', '\0', 'D', '\0'};
PCA3 pca3 = &ca3;
PCA2 pca2={ca3, ca3+1};
{
typedef char CA3[2][2][2];
typedef CA3 *PCA3;
typedef char CA2[2][2];
typedef CA2* PCA2[2];
CA3 ca3={'A', '\0', 'B', '\0', 'C', '\0', 'D', '\0'};
PCA3 pca3 = &ca3;
PCA2 pca2={ca3, ca3+1};
int i=0,j=0;
for(i=0; i<2; i++)
{
printf("\n");
printf("%s\n", (char*)pca3[0][i]);
printf("%s\n", (*(pca2+i))[0][1]);
for(j=0; j<2; j++)
{
putchar(*(*(ca3+i)+j)[0]);
putchar(' ');
}
}
}
求输出的结果是:_____________________
{
printf("\n");
printf("%s\n", (char*)pca3[0][i]);
printf("%s\n", (*(pca2+i))[0][1]);
for(j=0; j<2; j++)
{
putchar(*(*(ca3+i)+j)[0]);
putchar(' ');
}
}
}
求输出的结果是:_____________________
第十题:
/*C++ 题*/
#include
class Display
{
public:
virtual int ShowIt(int num) {printf("%d\n", num); return 0;}
int ShowIt(double num) {printf("%lf\n", num); return 0;}
};
class DisplayEx: public Display
{
public:
int ShowIt(int num) {printf("It is Integer, value is %d\n", num); return 0;}
int ShowIt(const char* str) {printf("%s\n", str); return 0;}
};
{
public:
virtual int ShowIt(int num) {printf("%d\n", num); return 0;}
int ShowIt(double num) {printf("%lf\n", num); return 0;}
};
class DisplayEx: public Display
{
public:
int ShowIt(int num) {printf("It is Integer, value is %d\n", num); return 0;}
int ShowIt(const char* str) {printf("%s\n", str); return 0;}
};
int main()
{
DisplayEx dpex;
Display *p_base=&dpex;
{
DisplayEx dpex;
Display *p_base=&dpex;
p_base->ShowIt(168);
p_base->ShowIt(1.68);
p_base->ShowIt(1.68);
dpex.ShowIt("Hello,World\n");
dpex.ShowIt(1.69);
dpex.Display::ShowIt(1.69);
return 0;
}
dpex.ShowIt(1.69);
dpex.Display::ShowIt(1.69);
return 0;
}
请说出其运行结果___________________
详细叙述c++编译器实现这一过程的方法.
详细叙述c++编译器实现这一过程的方法.