Dividing Integers (& Casting Precedance)
כ"ו תשרי תשס"ז - October 17, 2006Quiz:
What does the following code print:
int i,j;
float k;
i = 5;
j = 2;
k = i/j;
printf("%f\n",k);
Quiz:
What does the following code print:
int i,j;
float k;
i = 5;
j = 2;
k = i/j;
printf("%f\n",k);
Sometimes, you'll have a scenario with two variables, and you need to use one of them based on a simple test. Rather than a long and awkward if / else statement, C allows the use of the ? : form. It is perfectly acceptable to write:
int i,j,k,l;
...
i = (j > 5? k : l)
which will set i to k if j is greater than 5, and l otherwise.
Another common use is [sf]?printf statements:
printf("The test %s\n",(status == OK) ? "passed" : "failed");
However, one can't use it to handle selective assignments. The following code is illegal:
int i,j,k;
...
((i>5) ? j : k) = 5;
This cannot be used to choose whether j or k is set to 5.
There is, however a way this can be done. Using pointer, we can select which one to deference:
*((i>5) ? &j : &k) = 5;
This will work.
Yesterday, we went to the Kite Festival in Pnei Kedem. Overlooking (in the distance) the Dead Sea, Pnei Kedem is a small (about 20 families, IIRC) yishuv adjacent to Metzad, in Gush Etzion (our "friends" at Piece Now have a beautiful picture of Pnei Kedem... who said they don't do any good?). Every year (for the past few years, at least), they have a Kite Festival on Chol Hamoed Sukkos. On the summit of a large hill (mountain?) in the Judean Hills, they have the perfect climate for kite flying
(more...)
We've moved servers again! The DNS propogation is not yet complete, so if you get weird errors, try accessing http://64.21.48.171/
I think, however, that I have the proper .htaccess file to handle all of those automatically, though.
I'm still with site5.com, and I'm going to be posting a review of their service and the upgrade process soon.