Chinaunix首页 | 论坛 | 博客
  • 博客访问: 383956
  • 博文数量: 55
  • 博客积分: 1907
  • 博客等级: 上尉
  • 技术积分: 869
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-04 19:30
文章分类

全部博文(55)

文章存档

2011年(32)

2010年(23)

分类: C/C++

2010-12-04 11:44:56

/*
 * 编写一个数组的声明,把数组的某些特定位置初始化为特定的值。这个数组的名字
 * 应该叫 char_value, 它包含 3*6*4*5 个无符号字符。下面的表达式中列出的这些
 * 位置该用相应的值进行静态初始化。
 * 
 * -------------|---------------|---------------
 * 位置     值  | 位置      值  |  位置      值   
 * -------------|----------------- -------------
 * 1,2,2,3 'A' | 1,1,1,1 ' ' |  1,3,2,2 0xf3
 * 2,4,3,2 '3' | 1,4,2,3  '\n' |  2,2,3,1 '\121'
 * 2,4,3,3  3  | 2,5,3,4 125 |  1,2,3,4 'x' 
 * 2,1,1,2 0320 | 2,2,2,2  '\'' |  2,2,1,1 '0' 
 * -------------|---------------|-----------------
 * 那些在上面的表中未提到的位置应该被初始二进制0( 不是字符'0' ).注意:应该
 * 使用静态初始化,在你的解决方案中不应该存在任何可执行代码!尽管并非解决方案的一部分,
 * 你很可能想编写一个程序,通过打印数组的值来验证它的初始化。由于某些值并不是可打印
 * 的字符,所以请把这些字符用整型的形式打印出来( 用八进制或者十六进制输出会更方便一些 )。
 * 注意:用两种方法解决这个问题,一次在初始化列表中使用嵌套的花括号,另一次则不适用,这样
 * 你就能深刻地理解嵌套花括号的作用。
 */
/*
 * The key to this is that the initialization be done statically, not with assignment
 * statements. This means that the array must be in static memory, enen though the problem
 * did not specifically state than.
 *  Also, the problem purposely avoids specifying any locations that have a zero for any
 * subscript. This simply tests whether the student remmembers that subscripts begin to zero.
 *  The solution below exploits incomplete initialization to avoid having to enter each
 * value explicitly.
 */
 

unsigned char    char_values[3][6][4][5]=
{    
    {/* 0 */    
        {/* 0,0 */
            { 0 },
        }
    },
    
    {/* 1 */
        {/* 1,0 */
            { 0 }
        },
        {/* 1,1 */
            { 0 },
            { 0, ' ' }
        },
        {/* 1,2 */
            { 0 },
            { 0 },
            { 0, 0, 0, 'A' },
            { 0, 0, 0, 0, 'X' }
        },
        {/* 1,3*/
            { 0 },
            { 0 },
            { 0, 0, 0363 }
        },
        {/* 1,4 */
            { 0 },
            { 0 },
            { 0, 0, 0, '\n' }
        }
    },
    
    {/* 2 */
        {/* 2,0 */
            { 0 }
        },
        {/* 2,1 */
            { 0 },
            { 0, 0, 0320 }
        },
        {/* 2,2 */
            { 0 },
            { 0, '0' },
            { 0, 0, '\'' },
            { 0, '\121' }
        },
        {/* 2,3 */
            { 0 }
        },
        {/* 2,4 */
            { 0 },
            { 0 },
            { 0 },
            { 0, 0, '3', 3 }
        },
        {/* 2,x */
            { 0 },
            { 0 },
            { 0 },
            { 0, 0, 0, 0, '}' }
        }
    },
};

 

 

 

 

 

 

 

 

 


 

阅读(1370) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~