2011-07-29 08:17:18Morris
[問題] 指標
#include<stdio.h>
#include<stdlib.h>
typedef struct AVLNode {
int v;
short h;
struct AVLNode *p, *lc, *rc;
}AVLNode;
main() {
AVLNode *A, *B, *C, *D;
AVLNode **F;
A = (AVLNode*)malloc(sizeof(AVLNode));
B = (AVLNode*)malloc(sizeof(AVLNode));
C = (AVLNode*)malloc(sizeof(AVLNode));
D = (AVLNode*)malloc(sizeof(AVLNode));
A->v = 2, B->v = 1, C->v = 3, D->v = 0;
A->p = D, A->lc = B, A->rc = C;
printf("A: 指向%p 本身%p\n",A,&A);
printf("B: 指向%p 本身%p\n",B,&B);
printf("C: 指向%p 本身%p\n",C,&C);
printf("D: 指向%p 本身%p\n\n",D,&D);
printf("F: F:%p *F:%p &F:%p\n",F,*F,&F);
*F = A->p;
printf("F: F:%p *F:%p &F:%p\n",F,*F,&F);
A->p = B;
printf("F: F:%p *F:%p &F:%p\n",F,*F,&F);
printf("A: 指向%p 本身%p\n",A,&A);
printf("B: 指向%p 本身%p\n",B,&B);
printf("C: 指向%p 本身%p\n",C,&C);
printf("D: 指向%p 本身%p\n",D,&D);
printf("%d\n", (*F)->v);
system("pause");
return 0;
}
1. *F = A->p, 輸出 0, F = &(A->p), 輸出 1, 這到底怎麼回事呢 ?
#include<stdio.h>
#include<stdlib.h>
int main()
{
int arr[7];
printf("%p %p %p\n",arr,&arr,&arr[0]);
printf("sizeof arr : %d\n",sizeof(arr));
int *parr = (int*)malloc(7*sizeof(int));
printf("%p %p %p\n",parr,&parr,&parr[0]);
printf("sizeof arr : %d\n",sizeof(parr[0]));
system("pause");
}
2. 陣列跟指標陣列, 指標陣列記憶體較大, 他的結構到底是長怎樣呢 ?
#include<stdlib.h>
typedef struct AVLNode {
int v;
short h;
struct AVLNode *p, *lc, *rc;
}AVLNode;
main() {
AVLNode *A, *B, *C, *D;
AVLNode **F;
A = (AVLNode*)malloc(sizeof(AVLNode));
B = (AVLNode*)malloc(sizeof(AVLNode));
C = (AVLNode*)malloc(sizeof(AVLNode));
D = (AVLNode*)malloc(sizeof(AVLNode));
A->v = 2, B->v = 1, C->v = 3, D->v = 0;
A->p = D, A->lc = B, A->rc = C;
printf("A: 指向%p 本身%p\n",A,&A);
printf("B: 指向%p 本身%p\n",B,&B);
printf("C: 指向%p 本身%p\n",C,&C);
printf("D: 指向%p 本身%p\n\n",D,&D);
printf("F: F:%p *F:%p &F:%p\n",F,*F,&F);
*F = A->p;
printf("F: F:%p *F:%p &F:%p\n",F,*F,&F);
A->p = B;
printf("F: F:%p *F:%p &F:%p\n",F,*F,&F);
printf("A: 指向%p 本身%p\n",A,&A);
printf("B: 指向%p 本身%p\n",B,&B);
printf("C: 指向%p 本身%p\n",C,&C);
printf("D: 指向%p 本身%p\n",D,&D);
printf("%d\n", (*F)->v);
system("pause");
return 0;
}
1. *F = A->p, 輸出 0, F = &(A->p), 輸出 1, 這到底怎麼回事呢 ?
#include<stdio.h>
#include<stdlib.h>
int main()
{
int arr[7];
printf("%p %p %p\n",arr,&arr,&arr[0]);
printf("sizeof arr : %d\n",sizeof(arr));
int *parr = (int*)malloc(7*sizeof(int));
printf("%p %p %p\n",parr,&parr,&parr[0]);
printf("sizeof arr : %d\n",sizeof(parr[0]));
system("pause");
}
2. 陣列跟指標陣列, 指標陣列記憶體較大, 他的結構到底是長怎樣呢 ?
上一篇:Hash table %& 結論
下一篇:[分析] ZJ 排序大車拼