1   1  /  1  页   跳转

哪里出错了/

哪里出错了/

#include "stdio.h"
#include "conio.h"
void main()
{
    char a[4]="我";
    printf("%c\n",a[4]);
    getch();
}

为什么结果输出的不是"我"而是"?"
如果编写错误,那要怎样才能输出"我"?
最后编辑2006-10-03 09:13:22
分享到:
gototop
 

#include "stdio.h"
改成#include "conio.h"
void main()
{
char a[4]="我";
printf("%s\n",a);
getch();
}
就行了

问一下%s是什么意思
gototop
 

#include<stdio.h>
void main()
{
  char a='我';
  printf("请输入已定义的字符\n");
  fflush(stdin);
  a=getchar;
  putchar(a);
}
gototop
 

?
gototop
 

char a[4]="我";
printf("%c\n",a[4]);
数组越界了吧,一共四个,从零开始哪有a[4]啊
gototop
 

char a[4]时,只有
a[0]到a[3]
gototop
 

由于a[4]这个空间是没有经过定义的.比方说和int a;时,a的值不一定是0;没有经过定义的char[4],因编译器的不同而被初始化为不同的字符,在VC++6.0中会被初始化为'?'
gototop
 

%s是字符串的格式控制符
gototop
 
1   1  /  1  页   跳转
页面顶部
Powered by Discuz!NT