筒子们来测试下C语言的基础水平

昵称很不好取 2011-07-29 12:44:41
加精
1,The output for this program is: (a) 3 (b) 5 (c) 0
#include<setjmp.h>

static jmp_buf buf;

int main() {
volatile int b;
b =3;

if(setjmp(buf)!=0) {
printf("%d ", b);
exit(0);
}
b=5;

longjmp(buf , 1);

return 0;
}


2,The output for this program is: (a) 3 (b) 5 (c) 6 (d) 7
struct node { int a; int b; int c; };
int main() {
struct node s= { 3, 5,6 };
struct node *pt = &s;
printf("%d" , *(int*)pt);

return 0;
}


3,What function of x and n is compute by this code segment?
(a) x^n (b) x*n (c) n^x (d) None of the above
int foo ( int x , int n) {
int val;
val =1;
if (n>0) {
if (n%2 == 1) val = val *x;
val = val * foo(x*x , n/2);
}
return val;
}


4,The output for this program is: (a) 2 2 (b) 2 1 (c) 2 5 (d) None of the above
int main() {
int a[5] = {1,2,3,4,5};
int *ptr = (int*)(&a+1);
printf("%d %d" , *(a+1), *(ptr-1) );
return 0;
}


5,The output for this program is: (a) 8 (b) 9 (c) 7 (d) None of the above
void foo(int [][3] ); 
int main(){
int a [3][3]= { { 1,2,3} , { 4,5,6},{7,8,9}};
foo(a);
printf("%d" , a[2][1]);
return 0;
}

void foo( int b[][3]) {
++ b;
b[1][1] =9;
}


6,The output for this program is: (a) c=3 d=3 (b) c=5 d=3 (c) c=3 d=5 (d) c=5 d=5
int main() { 
int a, b,c, d;
a=3;
b=5;
c=a,b;
d=(a,b);
printf("c=%d" ,c);
printf("d=%d" ,d);
return 0;
}


7,The output for this program is:(a) 2 3 5 6 (b) 2 3 4 5 (c) 4 5 0 0 (d) None of the above
int main() { 
int a[][3] = { 1,2,3 ,4,5,6};
int (*ptr)[3] =a;
printf("%d %d " ,(*ptr)[1], (*ptr)[2] );
++ptr;
printf("%d %d" ,(*ptr)[1], (*ptr)[2] );
return 0;
}


8,Which of the above three functions are likely to cause problem with pointers
(a) Only f3 (b) Only f1 and f3 (c) Only f1 and f2 (d) f1 , f2 ,f3
int *f1(void) { 
int x =10;
return(&x);
}
int *f2(void) {
int*ptr;
*ptr =10;
return ptr;
}
int *f3(void) {
int *ptr;
ptr=(int*) malloc(sizeof(int));
return ptr;
}


9,The output for this program is: (a) i=4 j=2 (b) i=3 j=2 (c) i=3 j=4 (d) i=3 j=6
int main() { 
int i=3;
int j;
j = sizeof(++i+ ++i);
printf("i=%d j=%d", i ,j);
return 0;
}


10,The output for this program is: (a) 5 5 5 5 (b) 3 5 3 5 (c) 5 3 5 3 (d) 3 3 3 3
void f1(int *, int); 
void f2(int *, int);
void(*p[2]) ( int *, int);

int main() {
int a;
int b;
p[0] = f1;
p[1] = f2;
a=3;
b=5;
p[0](&a , b);
printf("%d\t %d\t" , a ,b);
p[1](&a , b);
printf("%d\t %d\t" , a ,b);
return 0;
}

void f1( int* p , int q) {
int tmp;
tmp =*p;
*p = q;
q= tmp;
}
void f2( int* p , int q) {
int tmp;
tmp =*p;
*p = q;
q= tmp;
}


11,The output for this program is: (a) 0 1 2 0 (b) 0 1 2 1 (c) 1 2 0 1 (d) 0 2 1 1
void e(int ); 
int main() {
int a;
a=3;
e(a);
return 0;
}

void e(int n) {
if(n>0) {
e(--n);
printf("%d" , n);
e(--n);
}
}


12,type of tmp is
(a) Pointer to function of having two arguments that is pointer to float
(b) int
(c) Pointer to function having two argument that is pointer to float and return int
(d) None of the above
typedef int (*test) ( float * , float*) 
test tmp;


13,The output for this program is: (a) 5 (b) 6 (c) 9 (d) None of the above
int main() { 
char *p;
char buf[10] ={ 1,2,3,4,5,6,9,8};
p = &((buf+1)[5]);
printf("%d" , *p);
return 0;
}


14,The output for this program is: (a) ab (b) cd (c) ef (d) gh
Void f(char**);
int main() {
char * argv[] = { "ab" ,"cd" , "ef" ,"gh", "ij" ,"kl" };
f( argv );

return 0;
}
void f( char **p ) {
char* t;
t= (p+= sizeof(int))[-1];
printf( "%s" , t);
}


15,The output for this program is: (a) 7 (b) 6 (c) 5 (d) 3
#include<stdarg.h> 
int ripple ( int , ...);
int main(){
int num;
num = ripple ( 3, 5,7);
printf( " %d" , num);
return 0;
}

int ripple (int n, ...) {
int i , j;
int k;
va_list p;
k= 0;
j = 1;
va_start( p , n);
for (; j<n; ++j) {
i = va_arg( p , int);
for (; i; i &=i-1 )
++k;
}
return k;
}


16, The value of j at the end of the execution of the this program is:
(a) 10 (b) 15 (c) 6 (d) 7
int counter (int i) { 
static int count =0;
count = count +i;
return (count );
}
int main() {
int i , j;
for (i=0; i <=5; i++)
j = counter(i);
return 0;
}
...全文
21157 349 打赏 收藏 转发到动态 举报
写回复
用AI写文章
349 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenhonglin000 2013-04-20
  • 打赏
  • 举报
回复
第1、6、15三题不会。
Safety_杜 2013-04-02
  • 打赏
  • 举报
回复
学c有小一段时间了,俺也过来测试测试,嘿嘿,
丨Barneyx 2013-03-04
  • 打赏
  • 举报
回复
好久都没有上CSDN上和大家讨论了,都觉的自己都是世外之人了 !
不学無术 2013-01-06
  • 打赏
  • 举报
回复
引用 52 楼 shmiluwabi666 的回复:
f2是返回了常量的地址,这个常量是不能修改的
这个可以修改 #include <stdio.h> int *f1(void) { int*ptr; *ptr =10; return ptr; } char *f2(void) { char *ptr; ptr = "tao"; return ptr; } int main(void) { int *p = f1(); *p = 12; printf("%d\n",*p); char *str = f2(); *str = 'h'; printf("%s\n",str); return 0; } 运行到f2()的时候发生段错误 数值常量 和 字符串常量 难道存放的地方不一样?
happyjw 2012-11-15
  • 打赏
  • 举报
回复
mark一下
14号选手 2012-11-13
  • 打赏
  • 举报
回复
引用 340 楼 Justme0 的回复:
引用 13 楼 zhao4zhong1 的回复:不要迷信书、考题、老师、回帖; 要迷信CPU、编译器、调试器、运行结果。 赵兄: 请问第二题, “结构体变量的地址”和“该结构体首成员的地址” 是否相同要看编译器是吧? 谢谢!
应该是要看你的计算机是大端序模式还是小端序模式
14号选手 2012-11-13
  • 打赏
  • 举报
回复
引用 楼主 thefirstz 的回复:
本帖最后由 thefirstz 于 2011-07-29 20:53:26 编辑 1,The output for this program is: (a) 3 (b) 5 (c) 0 C/C++ code?123456789101112131415161718#include<setjmp.h> static jmp_buf buf; ……
第一题中slmp函数和ljmp函数难道是汇编中的页面跳转语句和长跳转语句?
静革 justme0.com 2012-03-02
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 zhao4zhong1 的回复:]

不要迷信书、考题、老师、回帖;
要迷信CPU、编译器、调试器、运行结果。
[/Quote]


赵兄:
请问第二题, “结构体变量的地址”和“该结构体首成员的地址” 是否相同要看编译器是吧?
谢谢!
xiangle111 2012-02-24
  • 打赏
  • 举报
回复
把程序调试以下不就行了
l369294289 2011-11-27
  • 打赏
  • 举报
回复
大多是递归调用,多维数组与指针。不是太难。
l369294289 2011-11-27
  • 打赏
  • 举报
回复
char buf[10] ={ 1,2,3,4,5,6,9,8};
p = &((buf+1)[5]);
这一句不怎么理解,求解释~
fcjxxl 2011-11-03
  • 打赏
  • 举报
回复
[Quote=引用 308 楼 wuliaoxuebiancheng 的回复:]
引用 201 楼 iamsheldon 的回复:

水王。。。。。 大哥假如你的程序有问题 你还迷信吗
假如你的编译器有问题 你还迷信吗
假如你的CPU 有问题你还迷信吗?
。。。。。。。。。。。。。。。。。
什么都不要迷信,做人要有自己的思想


引用 13 楼 zhao4zhong1 的回复:

不要迷信书、考题、老师、回帖;
要迷信CPU、编译器、调试器、运行结果。
……
[/Quote]
+1
mijuewnpu 2011-09-06
  • 打赏
  • 举报
回复
有两道题俩面的函数没见过,要加油了!!
Roy_Smiling 2011-09-06
  • 打赏
  • 举报
回复
其实我是来打酱油的
mijuewnpu 2011-09-06
  • 打赏
  • 举报
回复
悲剧啊,第一个当时就没有看懂啊 !
luckygxboy 2011-09-06
  • 打赏
  • 举报
回复
mark
lileiLOVExida 2011-09-06
  • 打赏
  • 举报
回复
这个你理解错了,在标准C中,&a生成一个“T型数”的指针,指向整个数组。在ANSI之前的C中,&a中的&通常会引起一个警告,它通常被忽略。所有的C编译器中,对数组的简单引用(不包括&操作符),生成一个T型的指针类型的指针,所指向数组的第一个成员。
在本题中:int *ptr = (int*)(&a+1);是关键,因为用了&a,所以ptr的值是数组的首地址加上(整个数组的长度)×(类型所占的空间),即在这里它加了20(5×4);如果将它改为int *ptr = (int*)(a+1);则它的结果就是2,1了。 你去看看 数组的指针 和 数组首地址的指针 就会明白了。它们加1造成的结果是很不一样的。[Quote=引用 48 楼 et214721856 的回复:]

引用 46 楼 et214721856 的回复:
引用 14 楼 matrixcl 的回复:

喜欢按着顺序一题一题解决,发现到了第四题,无法理解。。。

4. &amp;a的类型是 int * [5], 因此(&amp;a+1)的和&amp;(a[5])是一样的。

看不大懂。

如果说&a就是int * [5],(&a+1)的和&am……
[/Quote]
lvjing_CSDN 2011-09-01
  • 打赏
  • 举报
回复
标记下
YUQB 2011-09-01
  • 打赏
  • 举报
回复
来喽。。。
CCSOY 2011-09-01
  • 打赏
  • 举报
回复
mark
加载更多回复(311)

69,336

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧