가능한 중복을 제공합니다
What is the behavior of integer division in C?부문은 항상 0
내가 1과 0 사이에해야하는데 답변과 나눗셈 계산을,
float a = 1;
float b = 2;
float c = a/b; //variable divide by variable gives 0.5 as it should
float d = 1/2; //number divide by number gives 0
float e = 4/2;
NSLog(@"%f %f %f %f %f", a,b,c, d, e);
: 항상 0
이 시도 반환
나는 콘솔에서이 얻을 :
2013년 1월 17일 14 : 24 : 17.512 MyProject를 [1798을 : C07] 1.000000 2.000000 0.500000 0.000000 0.500000
내가 무슨 일이 일어나고 있는지 전혀 모른다 에.
보기 [이 (http://stackoverflow.com/q/3602827/1402846),이 (http://stackoverflow.com/q/2976011/1402846), [this] (http://stackoverflow.com/q/2345902/1402846), [this] (http://stackoverflow.com/q/4197841/1402846), [this] (http : // stackoverflow. com/q/8459351/1402846). – Pang
당신은 1.f/2, 1.0/2, 1/2.0000f, 1/(float) 2 ... 기본적으로 2 개의 int가 될 수 있습니다. –
이봐, 잠깐만 ... 어떻게'0.500000' 'e'는'4/2'입니까? '2.000000'이어야합니다. – Pang