回复 5楼 panrui0512
说下第一个了,第二个因为水平不够,一下没看出来这个程序是干嘛用的
在下面这个语句里面:
char weekday[week_day][name_len]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
因为有前面的宏定义:
#define week_day 7
#define name_len 10
所以你应该理解为:
char weekday[7][10]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
很明显了,这是定义了一个七行十列的字符数组(是个二维数组),等号后面的花括号是对weekday这个char型二维数组的初始化:很明显七行里面,每一行是存的一个字符串,该字符串最大长度不超过10(加上字符串结束标志'\0')。
"Sunday" 你可以理解为{'S','u','n','d','a','y','\0'}每个元素都是个字符,包括最后的'\0'。
也就是在weekday里面weekday[0][0]='S'
weekday[0][1]='u' ...... weekday[0][6]='\0'
然后就轮到"Monday"了,它是以 weekday[1][0]='M'开头的。
这时候 weekday[0][7]到weekday[0][9]没有说初始化为什么,一般是默认为0的。
即:
char weekday[7][10]={
{'S','u','n','d','a','y','\0'
},
{'M','o','n','d','a','y','\0'
},
{'T','u','e','s','d','a','y','\0'
},
{'W','e','d','n','e','s','d','a','y','\0'
},
{'T','h','u','r','s','d','a','y','\0'
},
{'F','r','i','d','a','y','\0'
},
{'S','a','t','u','d','r','a','y','\0'
}
};