~cpp static int func(int a, int b) { ... }
~cpp #include <stdio.h> #include <stdarg.h> int sum(int n, ...) { int sum = 0; va_list list; va_start(list, n); for(int i = 0 ; i < n ; i++) sum += va_arg(list, int); va_end(list); return sum; } void main() { int s = sum(5, 10, 20, 30, 40, 50); printf("s = %d\n", s); }
~cpp int func(int a, int b = 10, int c = 30);
~cpp int abs(int v) { if(v < 0) return -v; else return v; } double abs(double v) { if(v < 0.0) return -v; else return v; } float abs(float v) { if(v < 0.0F) return -v; else return v; }
~cpp #include <stdio.h> template<typename T> T abs(T v) { if(v < 0) return -v; else return v; } void main() { int a = abs(-10); printf("%d\n", a); }
~cpp #include <stdio.h> template<typename T> T abs(T v) { if(v < 0) return -v; else return v; } void main() { double a = abs<double>(-10); printf("%f\n", a); }
~cpp #include <stdio.h> template<class T> void print(T a) { printf("not supported\n"); } template<> void print<const char *>(const char *a) { printf("%s\n", a); } template<> void print<int>(int a) { printf("%d\n", a); } void main() { print("adfgasg"); print(121); print(0.23); }
~cpp #define toupper(a) ((a) >= 'a' && ((a) <= 'z') ? ((a)-('a'-'A')):(a)) vs. inline char toupper( char a ) { return ((a >= 'a' && a <= 'z') ? a-('a'-'A') : a ); }
~cpp extern "C" void func(int a, int b); extern "C" { void func(int a, int b); }
~cpp int (*fp)(int, int, int);