一個例子告訴你指針有多危險

一個例子告訴你指針有多危險

代碼

#include <stdio.h>
int main()
{
	struct st
	{
		int a;
		int b;
	};
	struct st st1;
	st1.a=1;
	st1.b=4;
	int *pa=&(st1.a);
	printf("a=%d,b=%d\n",st1.a,st1.b);
	pa[1]=77;
	printf("a=%d,b=%d\n",st1.a,st1.b);
	return 0;
}

運行結果

a=1,b=4
a=1,b=77
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章