直接看代码
#include <stdio.h>
#include<string.h>
int main()
{
//char s[10] = { 98,68,55,'-','x','y' }; // sizeof=10 strlen =6
//char s[10] = "abc%78"; // 从常量区拷贝赋值,sizeof=10 strlen =6
//char s[] = { 'a','b','c','\0' }; // sizeof=4 strlen=3
//char s[] = "abcd%3"; // sizeof=7 strlen=6
printf("sizeof(s)=%d\n", sizeof(s));
printf("strlen(s)=%d\n", strlen(s));
int a[10] = { 31,40,21,23,6,9,25,11,3,8 };
//冒泡排序
int i = 0;
while (i < 9)
{
int j = 0;
while (j < 9-i) // 0...8
{
if (a[j] > a[j + 1])
{
int t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
}
++j;
}
++i;
}
i = 0;
while (i < 10)
printf("%d ", a[i++]);
}