注册 登录
编程论坛 VC++/MFC

为什么一个参数能储存 另外一个不能

huaijuliu 发布于 2012-03-24 07:22, 354 次点击
各位大侠 打扰了 有一个简单的程序 两个参数输出 为什么只有nx能输出 而hx输出为零呢 ?可直接运行得结果,请各位帮忙,感谢。
程序代码:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef struct
{      
    double hx;   
    int nx;   
} Level;

typedef struct
{   
  Level *Lk;
} Stack;


void initialize(Stack *V, int nx0)
{   
    Level *L;           
    V->Lk=(Level *)calloc(1,sizeof(Level));   
    L=V->Lk+1;
    L->hx=nx0/2;        
    L->nx=nx0;            
    printf("\n level: nx=%d hx=%f",L->nx,L->hx);            
         
}

void init_p(Stack *V, int c)
{   
    Level *L;   
    L=V->Lk+c;
    printf("\nnx is %d",L->nx);
    printf("\nhx is %d\n",L->hx);   
}

void main()
{   
    Stack V;   
    initialize(&V,5);   
    init_p(&V,1);   
}

3 回复
#2
huaijuliu2012-03-24 07:23
另外我hx已经定义成double型了 那么5/2应该等于2.5 为什么它是2呢
#3
huaijuliu2012-04-02 01:31
这个问题小弟至今未得解决 还需继续寻求帮助 谢谢大家
#4
huaijuliu2012-04-16 21:37
继续求教 感谢大家关注
1