---
title: "指针的高效"
author: "wandering192"
date: "2010-09-13T23:52:33Z"
tags: ["F#"]
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2010-09-13T23:52:33Z"
id: 762530
url: "https://wandering192.iteye.com/blog/762530"
---

```
#include <stdio.h>

struct student {
	char name[200];
	int age;
};

//传递的是指针，内存里只取出四个字节的空间存放变量pst
//pst存放的是地址，通过引用可改变实参的值
//这是效率高的做法
void f(struct student *pst) {
	pst->age = 000;
	//printf("name: %s \n age: " , pst->name, pst->age);
}

//如此传递参数，传递的是整个结构体，在内存会取出一个与实参同样大小的新空间存放pst
//因此函数无法改变实参的值
//这是效率比较低的
void f2(struct student pst) {
	pst.age = 000;
}

int main(void) {
	struct student st = {"stu1", 20};
	struct student * p;
	p = &st;
	printf("%d \n", p->age);
	f2(st);
	printf("%d \n", p->age);
	f(p);
	printf("%d", p->age);
}

```