本帖最后由 liu01230 于 2015-5-11 23:05 编辑  
- #import <Foundation/Foundation.h>
 
 - @interface Students : NSObject
 
 - {
 
 -     @public
 
 -     char *name;
 
 -     double score;
 
 -     int age;
 
 - }
 
 - - (void)eat;
 
 - - (void)study;
 
 - @end
 
  
- @implementation Students
 
 - - (void)eat
 
 - {
 
 -     NSLog(@"名字为%s的人在吃饭", name);
 
 - }
 
 - - (void)study
 
 - {
 
 -     NSLog(@"名字为%s的人的学习成绩为%.1f。", name, score);
 
 - }
 
 - @end
 
  
- int main()
 
 - {
 
 -     Students *s = [Students new];
 
 -     s->name = "张三";
 
 -     s->age = 18;
 
 -     s->score = 89.5;
 
 -     
 
 -     [s eat];
 
 -     [s study];
 
 - }
 
 
  复制代码 为什么输出的是: 
名字的人在吃饭 
名字为的人的学习成绩为89.5。 
 
当把name的值改为英文字符的时候输出就正常了,这是为什么? 
 |   
        
 
    
    
    
     
 
 |