- # Include <stdio. h>
- Typedef void (* bottle_type) (int I); // we have designed a bottle model here. This bottle is not easy. You can install any starting function address! Let's use it to create a bottle.
- Void vinegar (int I) // vinegar
- {
- Printf ("% d: Now, I am vinegar, not bottle! /N ", I );
- }
- Void soy (int I) // soy sauce
- {
- Printf ("% d: Now, I am soy, not bottle and vinegar! /N ", I );
- }
- Int main ()
- {
- Bottle_type bottle; // a bottle is created based on the bottle_type model.
- Bottle = vinegar; // Add vinegar to the bottle. Will you still call it a bottle? If yes, I don't believe it. If you go to the supermarket to buy vinegar, you will point to the vinegar and say to the vending lady, I want to buy this bottle ^-^! (Actually, the vinegar address is installed in the bottle)
- (* Bottle) (1); // because the bottle contains vinegar, the result is also vinegar.
- Bottle = soy; // It's too sour to add vinegar now! Add soy sauce. Will you still call it a bottle or vinegar? It's called soy sauce (soy address is installed in the bottle)
- (* Bottle) (2); // bottle is soy sauce.
- Return 0;
- }
Liulife @ liulife :~ /Test $ gcc-O test_func_p test_func_p.c
Liulife @ liulife :~ /Test $ ls
Test_func_p test_func_p.c
Liulife @ liulife :~ /Test $./test_func_p
1: Now, I am vinegar, not bottle!
2: Now, I am soy, not bottle and vinegar!