一道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)。 请详细讲解。 如果不明白题的话,请说。谢谢