ใช้ #define macro ภายในฟังก์ชันเพื่อเปลี่ยนพฤติกรรมของ printf() ทั้งโปรแกรม
ตัวอย่าง
#include <stdio.h>
void changePrintf() {
#define printf(x, y) printf(x, 50);
}
int main() {
int x = 40;
changePrintf();
printf("%d\n", x); // พิมพ์ 50 แทน 40
x = 60;
printf("%d", x); // พิมพ์ 50 แทน 60
return 0;
}
ผลลัพธ์
50 50
หมายเหตุ: เทคนิคนี้ใช้ Preprocessor Macro แทนที่ printf ทุกครั้งหลังจากเรียก changePrintf()