CMPT 125 Lecture 5: L5 P2
Document Summary
And of conditions: if (cond1 && cond2) do_something(); else do_something_else() Runs cond2 only if cond1 is satisfied. Or of conditions: while (cond1 || cond2) do_something(); Checks first if cond1 is satisfied (i. e. , cond1 !=0) Runs cond2 only if cond1 is not satisfied. So far we have seen only variables defined inside functions. The scope of the variables is limited only to the function. It is possible to define a global variable that is visible everywhere. It is also possible to define a static variable that will "remember its value in different calls of the function. #include void test_static_count() { static int count = 0; // initialized only once! // do something count++; printf("count = %d\n", count); int main(void) { test_static_count(); // prints count = 1 test_static_count(); // prints count = 2 test_static_count(); // prints count = 3. #define creates a constant that can be use globally.