1 / 3

C++ While Loop Game and Function Pointers Example

Learn to implement a game using a while loop in C++, and understand function pointers with hackable examples.

kueng
Télécharger la présentation

C++ While Loop Game and Function Pointers Example

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. “ First, solve the problem. Then, write the code.” 

  2. 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; }

  3. 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); }

More Related