我有这样的片段:分配处理的值不同
#include <stdio.h>
#include<conio.h>
void main() {
int x = 10/0;
printf("%d", x);
getch();
}
上述输出是10
。
但是,如果我运行此:
#include<stdio.h>
#include<conio.h>
void main() {
int x = 10/2;
printf("%d", x);
getch();
}
输出是5
。 为什么?
我使用TurboC++
编译器Windows 7
使用DosBox
。
而且,如果我做这样的:
#include<stdio.h>
#include<conio.h>
void main(){
int x=10;
x=x/0; //now it would not compile and gives error
}
你使用什么编译器(和什么版本)? – orlp
惊讶第一个没有抛出一个div异常 – Nick
你的第一个代码清单给了我一个'浮点异常',见下面的锐利齿轮答案。 – brc