> For the complete documentation index, see [llms.txt](https://labspc.gitbook.io/cnippets/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://labspc.gitbook.io/cnippets/chap5.-zhi-zhen-yu-shu-zu/5.2-zhi-zhen-yu-han-shu-can-shu.md).

# 5.2 指针与函数参数

在 4.1 节中有有个交换两变量值的例子：

```c
// 交换两个变量的值

#include <stdio.h>

// 引入中间变量e，用于交换变量c d 的值
void Swap(int c, int d) {
    int e=0;
    e = c;
    c = d;
    d = e;
    // printf("%d %d", c, d);
}

int main(void) {
    int a = 0, b = 0;
    scanf("%d %d", &a, &b);
    printf("a=%d b=%d\n", a, b); //交换前测试

    Swap(a, b);
    printf("a=%d b=%d\n", a, b);

    return 0;

}
```

这是 SOL 1 方法，为什么没有实现呢？c 语言是传值调用，这里并没有改变值，要传指针才行。

指针作为函数参数：

```c
#include <stdio.h>
//指针作为函数参数
void decompose(double x, long *int_part, double *frac_part)
{
    *int_part = (long)x;
    *frac_part = x - *int_part;
}

    double x = 3.14159265358979323846;
    long int_part;
    double frac_part;

int main()
{
    // 调用函数
    decompose(x, &int_part, &frac_part);
    // 输出结果
    printf("整数部分: %ld\n", int_part);
    printf("小数部分: %f\n", frac_part);

    return 0;
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://labspc.gitbook.io/cnippets/chap5.-zhi-zhen-yu-shu-zu/5.2-zhi-zhen-yu-han-shu-can-shu.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
