void **(*d) (int &, char **(*)(char *, char **));
int main(void)
{
int a[2] = {1, 2};
int* p = a;
printf("%p\n", p);
printf("%p -> %p\n", p, p++);
}
輸出:
0x7fffc405fd40
0x7fffc405fd44 -> 0x7fffc405fd40
觀察 printf 和 i++ 、 ++i
printf
是由右往左開始執行的
++i
會先將 i
加一後回傳變數 i
i++
則是會先回傳 i
這個變數的值
#include <stdio.h>
int main(){
int i=1;
printf("%d %d %d %d", i++, i, ++i, i);
return 0;
}
輸出:
2 3 3 3
void *memcpy(void *dest, const void *src, size_t n);
int B = 2;
void func(int *p) { p = &B; }
int main() {
int A = 1, C = 3;
int *ptrA = &A;
func(ptrA);
printf("%d\n", *ptrA);
return 0;
}
以上程式碼無法成功改到 *ptr 的值,因為函式是 call-by-value
所以運用 指標的指標 改成
int B = 2;
void func(int **p) { *p = &B; }
int main() {
int A = 1, C = 3;
int *ptrA = &A;
func(&ptrA);
printf("%d\n", *ptrA);
return 0;
}
char *r = malloc(strlen(s) + strlen(t) + 1);
if (!r) exit(1); /* print some error and exit */
strcpy(r, s);
strcat(r, t);
free(r);
r = NULL; /* Try to reset free’d pointers to NULL */
int main() { return (********puts)("Hello"); }
int main() { return (puts)("Hello"); }
char * const p;
const char * p;
char const * p;
const char * const p;
int a = 1; /* a 是 lvalue */
int b = 2; /* b 是 lvalue */
int c = a + b; /* a+b 為 rvalue */
// 原始寫法:
int *(*a[5])(int, char*);
// 轉換1:
typedef int *(*pFun)(int, char*);
pFun a[5];
// 轉換2:
typedef int *Func(int, char*);
Func *a[5];
// 原始寫法:
void (*b[10])(void (*)());
// 轉換為:
typedef void (*pFunParam)(); // 右半部, 函數的參數
typedef void (*pFunx)(pFunParam); // 左半部的函數
pFunx b[10];