无法理解下面的C语言程序的输出 [英] Can't understand output of following C language program

查看:108
本文介绍了无法理解下面的C语言程序的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白下面的C程序的输出,任何想法?

I can't understand output of following C program, any idea ?

#include<stdio.h>

#include<conio.h>

void main()

{
  int a=5,b=6,c=11;

  clrscr();

  printf("%d %d %d");

  getch();
}

本程序的输出是:

11 6 5

我不明白为什么上面的程序给我们的printf我从未宣布过它的价值必须打印扭转变量值......那么,有没有任何理论,如果我们没有宣布哪个变量必须打印,然后我们得到相反的价值那我们在数据类型上述声明的变量...

I can't understand why above program give us reverse variable values in printf I never declared which value have to print...So is there is any theory that if we no declared which variable have to print then we get reverse value of variables that we above declared in data type...

推荐答案

这是未定义的行为,你不应该期待一个特定的输出(或它的解释),除非你在乎实施的具体细节。

This is undefined behavior, and you should not expect a particular output (or an explanation of it), unless you care about implementation specific details.

什么可能是打印的是(随机的,即非predictable)包含在应该持有一些参数堆栈位置或寄存器值的垃圾

What might be printed is the (random; i.e. "unpredictable") garbage value contained in some stack locations or registers supposed to hold the arguments.

顺便说一句,一些编译器(即 GCC 的gcc -Wall 调用)会给你​​一些警告。尽量避免它们(通过纠正源$ C ​​$ C)。

BTW, some compilers (i.e. GCC when invoked with gcc -Wall) would give you some warning. Try hard to avoid them (by correcting the source code).

这篇关于无法理解下面的C语言程序的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆