cclass1201結構_指標

 avatar
user_3763047219
c_cpp
3 years ago
754 B
6
Indexable
struct student {
	char name[20];
	int id;
	char phone[11];
	float grade[4];
	int birth_year, birth_month, birth_day;
};

	int main() {
	int i = 5;
	int* iptr = &i;
	printf("%d\n", *iptr);

	struct student john = { "John Smith",12345,"0935456789",
						   {4.0,3.9,3.8,3.6},2000,1,1 };
	struct student* ptr = &john;//john是一般變數 名字表示數字 前面要加&
	printf("%d\t%d\n", sizeof(john), sizeof(ptr));//john是64bytes ptr是指到john第一個位址
	// int array[10];
	// int *aptr = array;名字就表示位址
	strcpy(ptr->name, "Joe Smith");
	printf("%s\n", ptr->name);
	//printf("%d\n", (*ptr).id);
	printf("%d\n", ptr->id);
	ptr->grade[2] = 3.8;
	(*ptr).grade[2] = 3.8;
	printf("%f\n", ptr->grade[2]);
}   
Editor is loading...