0
why i can't use floor founction, language c
#include <stdio.h> #include <math.h> int main(){ int a; double c,e; c=(a+1)/4; e=floor(c); /*this giving me a higher value*/ printf("%.lf",e); return 0; }
4 Respuestas
+ 4
read the error message: "a" is not initialized.
+ 4
Demircan Demirez ,
Assign value for "a" ,
to perform the calculation at ...c=(a+1)/4;
+ 3
Demircan Demirez garbage value is assigned to a var
0
variable a was declared but never initialized. When you declare a variable, a memory object that can accommodate the data type is allocated and EXCEPT you explicitly initialize such variables, whatever is sitting in the memory addresses at that time, the value would be assigned to your variable. Well that's only true for automatic storage variable, other variables like static and register variable are sometimes default to 0 for integers but then, that's implementation defined. In the C/C++ world, such weird and unpredictable behaviour is termed undefined and they are mostly the common bugs.
It can even be a serious problem if a had been a pointer or something, maybe crash your computer