现定义如下数据结构
struct mystruct{
          char a;
          int  b;
          long c;
    };
能不能定义一个指针变量p,使得*p=a,*p+1=b,*p+2=c .......

解决方案 »

  1.   

    不可以,因为每个元素占用内存不对
    可以这样
    struct mystruct{
              char a;
    char p1[3];
              int  b;
              long c;
        };
    补三个
    因为sizoef(char )=1
    sizeof(int)=4=sizeof(long)
    所以补一些就可以了
    然后long *p=(long *)(struct对象)
      

  2.   

    #define  char unsigned int 
    #define  long unsigned int 
    struct mystruct{
              char a;
              int  b;
              long c;
        };