40 likes | 149 Vues
“ First, solve the problem. Then, write the code. ” . The Game repetition is accomplished using a while loop(C++). // Play Again // Demonstrates while loops #include < iostream > using namespace std ; int main() { char again = ’y’; while (again == ’y’) {
E N D
The Game repetition is accomplished using a while loop(C++) // Play Again // Demonstrates while loops #include <iostream> using namespace std; int main() { char again = ’y’; while (again == ’y’) { cout << "\n**Played an exciting game**"; cout << "\nDo you want to play again? (y/n): "; cin >> again; } cout << "\nOkay, bye."; return 0; }
Function Pointers - hacking • Usually, pointers are used for variables; however, they can also be used for functions. #include <stdio.h> intfunc_one() { printf("This is function one\n"); return 1; } intfunc_two() { printf("This is function two\n"); return 2; } int main() { int value; int (*function_ptr) (); function_ptr = func_one; printf("function_ptr is 0x%08x\n", function_ptr); value = function_ptr(); printf("value returned was %d\n", value); function_ptr = func_two; printf("function_ptr is 0x%08x\n", function_ptr); value = function_ptr(); printf("value returned was %d\n", value); }