| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1128 人关注过本帖
标题:一道c program的国外题。
只看楼主 加入收藏
shaolongguo
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-10-12
收藏
 问题点数:0 回复次数:2 
一道c program的国外题。
(原文)please write a program declaring a variable x as the type int, and use the scanf function to input an integer to initialize the value of x. Then, your grogram will input the following values with specified formats using the printf library function:
 [01] x                   (format: decimal(10进制))
[02] x                    (format: hexadecimal(16进制))
[03] &x                    (format hexadecimal)
[04] (int) (*((int *) x))   (format decimal)
[05] *((double *) (&x))  (format double)
[06] ((double *) (&x)) +1   (format hexadecimal)
[07] ((int *) (&x))  +1    (format hexadecimal)   
[08] ((void *) (&x))  +1    (format hexadecimal)     
[09] ((char *) (&x))  +1    (format hexadecimal)     
[10] ((char **) (&x))  +1    (format hexadecimal)     
[11] ((int **) (&x))  +1    (format hexadecimal)      
please notice that, if you enter certain values for x, your program might crash due to some logic error of the above specificatin. Therefore, you need to identify which one (only one of the eleven ) can cause a problem for your program. When you print out the results, it should look like:
[01]  23456789
[02] ......
[03]

(解释)
如何写这样的program 声明一个变量x 为int型,用scanf这个function去input一个integer去x的值。 然后你的program 将会输出以下的带有特别格式的值用‘printf’libary function。
[01] x                   (format: decimal(10进制))
[02] x                    (format: hexadecimal(16进制))
[03] &x                    (format hexadecimal)
[04] (int) (*((int *) x))   (format decimal)
[05] *((double *) (&x))  (format double)
[06] ((double *) (&x)) +1   (format hexadecimal)
[07] ((int *) (&x))  +1    (format hexadecimal)   
[08] ((void *) (&x))  +1    (format hexadecimal)     
[09] ((char *) (&x))  +1    (format hexadecimal)     
[10] ((char **) (&x))  +1    (format hexadecimal)     
[11] ((int **) (&x))  +1    (format hexadecimal)      
注明:当你输入x的值,你的program 会crash(在操作过程中死机在一些逻辑error上。 你需要知道上面哪个是有问题(只有一个)。
当你print出的结果,看起来象这样:
[01]  23456789
[02] ......
[03]



这样的一道提,请问他是想让我干什么? 我的理解是我做一个简单c program:main()内容为 int x; scanf(“x”.&x); printf("%x",x);然后当我们运行这个program来看他的结果(或显示)。是这样吗? 但是我不明白 他要  (format:decimal)。 请详细讲解。    如果不明白题的话,请说。谢谢
搜索更多相关主题的帖子: program 国外 
2008-10-13 00:14
debroa723
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:23
帖 子:862
专家分:1954
注 册:2008-10-12
收藏
得分:0 
这题是要根据输入的值在输出时输出不同的东西,顺序如下 :
[01]10进制格式输出
[02]16进制格式输出
[03]二进制格式输出
[04] 将x做为int指针,输出该指针指向的内存值,以十进制输出
[05] 将x的地址做为double指针,输出该指针指向的内存值,以二进制输出
[06] 将x的地址做为double指针,以double寻址下的下一个double值,以二进制格式输出
[07] 将x的地址做为int指针,以int寻址下的下一个int值的二进制格式输出
[08] 将x的地址做为void指针,下一个正常寻址长度的内存二进制值输出   
[09] 将x的地址做为char指针,以char寻址下的下一个char值的二进制格式输出     
[10] 将x的地址做为char**指针,该指针的下一个地址的内容所指向的内存的内容, 以二进制输出  
[11] 将x的地址做为int**指针,该指针的下一个地址的内容所指向的内存的内容, 以二进制输出
这道题是考寻址方式的,
2008-10-13 02:58
shaolongguo
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-10-12
收藏
得分:0 
如何以2进制输出。用什么指令?
2008-10-13 05:18
快速回复:一道c program的国外题。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012757 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved