定义局部变量时的不同输出

时间:2015-08-21 12:54:04

标签: c local-variables

为什么我在DevC ++中将i2的输出变为1,而在其他地方我得到0?

#include <stdio.h> 
int main(void) {
    int i1,i2;
    char c1,c2;
    float f1,f2;
    long l1,l2;
    double d1,d2; 
    printf("\n%d %d",i1,i2);
    printf("\n%c %c",c1,c2);
    printf("\n%d %d",f1,f2);
    printf("\n%l %l",l1,l2);
    printf("\n%lf %lf",d1,d2);
    return 0;
}

2 个答案:

答案 0 :(得分:2)

在打印时,您没有初始化导致Undefined behavior的任何变量。请注意,当您声明

  //Principal panel

   private class PanelPrincipalAnexo extends WebMarkupContainer
   {
    public PanelPrincipalAnexo(String id)
    {
        super(id);

        formUpload = getFormUpload();
        add(formUpload);
        formUpload.add(getDataViewAnexos("anexos"));
    }
  }




  //creating the FormUpload
  private FileUploadForm getFormUpload() {
    return new FileUploadForm("formUpload", new PropertyModel<List<FileUpload>>(this, "uploads"));
  }





  private DataView<ProgramaAnexo> getDataViewAnexos(String id) {

    return new DataView<ProgramaAnexo>(id, new AnexoProvider()) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(Item<ProgramaAnexo> item) {

            item.add(new Label("tipoArquivo"));
            item.add(new Label("nomeAnexo"));
            item.add(new Label("tamanhoArquivoEmMB")); 
            item.add(getButtonRemove(item));

        }
    };
}







 public AjaxSubmitLink getButtonRemove(Item<ProgramaAnexo> item) {
    AjaxSubmitLink button = new AjaxSubmitLink("btnRemoverBem", form) {
        private static final long serialVersionUID = 1L;
        @Override
        public void onSubmit(AjaxRequestTarget target, Form form) {
            actionRemoverKit(target,item);
        }
    };
    return button;
}





 private void actionRemoverKit(AjaxRequestTarget  target,Item<ProgramaAnexo> item) {

    ProgramaAnexo bemRemove=item.getModelObject();
    int cont=0;
    for(ProgramaAnexo bem:list)
    {            
        if(bemRemove.getBem().getId().intValue()==bem.getBem().getId().intValue())
        {  
            listaBensSelecionadosDireito.remove(cont);
            break;
        }
    }        
    target.add(panelPrincipalAnexo);
}




   THE HTML

<table width="98%" class="table table-hover"
                                style="table-layout: fixed;">
                                <thead>
                                    <tr>
                                        <th width="16%"></th>
                                        <th width="16%">Tipo</th>
                                        <th width="29%">Arquivo</th>
                                        <th width="10%">Tamanho</th>
                                        <th width="25%" class="text-left">Ações</th>
                                        <th width="4%"></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr  wicket:id="anexos">
                                        <td width="16%"></td>
                                        <td width="16%"><span wicket:id="tipoArquivo"></span></td>
                                        <td width="29%"><span wicket:id="nomeAnexo"></span></td>
                                        <td width="10%"><span wicket:id="tamanhoArquivoEmMB"></span></td>
                                        <td width="25%" class="text-left">

                                            <button wicket:id="btnExcluirAnexo" 
                                                    title="Excluir" 
                                                    class="btn btn-danger btn-sm"
                                                    id="btnRemoverBem"">
                                                            <i class="fa fa-minus"></i>
                                            </button>
                                        </td>
                                        <td width="4%"></td>
                                    </tr>
                                </tbody>
                            </table>

并保持未初始化状态,它们包含垃圾值。

答案 1 :(得分:2)

尚未初始化或分配值的自动对象具有不确定的值,即未指定的值或陷阱表示。