why i can't use floor founction, language c | Sololearn: Learn to code for FREE!
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; }

26th Jun 2024, 11:31 AM
Habip Demircan Demirez
4 odpowiedzi
+ 4
read the error message: "a" is not initialized.
26th Jun 2024, 11:45 AM
Lisa
Lisa - avatar
+ 4
Demircan Demirez , Assign value for "a" , to perform the calculation at ...c=(a+1)/4;
26th Jun 2024, 11:49 AM
Riya
Riya - avatar
+ 3
Demircan Demirez garbage value is assigned to a var
26th Jun 2024, 12:12 PM
Anand[offline]
Anand[offline] - avatar
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
29th Jun 2024, 5:42 PM
RuntimeTerror
RuntimeTerror - avatar