关于c语言定义变量

about the place of defining variable in c program!

一直以来的学习中关于变量的定义都是在使用之前,也就是说使用之前定义了都没问题,但是最近练习中却发现事实并非如此。

such as the example  following:

#include <stdio.h>

struct date
{
    int month;
    int day;
    int year;
}date1;
struct date date2;
struct student
{
    char num[11];
    char name[11];
    char sex;
    struct date birthday;
}qjl[3]={{"20041102215","qujl1",'M',8,23,1985},
         {"20041102215","qujl2",'F',8,23,1985},
         {"20041102215","qujl3",'M',8,23,1985}
         };
main()
{
    struct date date4;
    struct student *p;                 //●
    date4.month=6;
    date4.day=10;
    date4.year=3005;
    /*date4={6,10,3006};*/       /*错误赋值方法*/
    printf("%d-%d-%d/n",date4.year,date4.month,date4.day);

    printf("NO.           NAME       SEX /n");
    for(p=qjl;p<qjl+3;p++)
        printf("%-19s   %-11s%-2c/n",p->num,p->name,p->sex);
    getch();

in the example ,when i define    struct  student *p;  in the head of the program,it's true ,but when i define it   between        the sentence  printf("NO.               NAME              SEX/n");and  the for cyclic ,it will be false.

I don't know the reason  of this instance,mybe  i  will know it   later.

if  you pass by my blog ,and you know the reason,please tell me!Thank you forver!

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值