1、2.1.3
#include <stdio.h> #include <stdlib.h> char* getcharBuffer() { return "6969,3p3p"; } void changeto4p(char* buffer) { while (*buffer) { if (*buffer == '3') *buffer = '4'; buffer ++; } } void main() { printf("%s\n", "Any key continue ..."); getchar(); char *str = getcharBuffer(); changeto4p(str); printf("%s", str); }
2、2.1.5
#include <stdio.h> #include <string.h> struct inner { char arr[10]; }; class MyCls { private: char* str; inner inobj; public: void set(char* input) { str = input; strcpy(inobj.arr, str); } int output() { printf(str); return 1; } void hold() { getchar(); } }; void foo1() { MyCls *pcls = new MyCls(); void *rawptr = pcls; pcls->set("abcd"); pcls->output(); pcls->hold(); } void foo2() { printf("in foo2\n"); foo1(); } void foo3() { printf("in foo3\n"); foo2(); } void main() { foo3(); }
3、
4、
5、