- When declaring a variable , We should assign it to 0 ;
for example:
double x;
for(int i=0; i<100; i++)
x+=certainfunction(i);
The preceding code won't work because x hasn't assigned to any. Sometimes I forget this assignment, so the result is an error "Local variable is not assigned".
- Type conversation
double certainfunction(int x)
{
return 1/(3*x);
}
This code will excutate but the expected result will be wrong, because of 1/(3*x) =0 for x=2, 3,5, .....
To make this code work properly, we must cast the return result as follow:
return (double)(1/(3*x));
Subscribe to:
Post Comments
(
Atom
)
0 comments:
Post a Comment