What is this code doing? C/C++ -


can tell recursive function doing. think nothing, returns 0 , program stops.

for string: honolulu\0

int fun(char *string){     if(*string != 'u') return 0;     return 1 + fun(string + 1); } 

it counts number of 'u's @ start of string.

cout << fun("umbrella"); //prints: "1" cout << fun("uumbrella"); //prints: "2" 

note assumes string '\0' terminated. many old c string functions iterate off end of array until finds random '\0' somewhere in memory long keeps getting 'u's.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -