小编Eth*_*tch的帖子

在c中交换两个结构

嗨,我正在尝试创建交换函数,以交换结构的前两个元素。有人可以告诉我如何使这项工作。

void swap(struct StudentRecord *A, struct StudentRecord *B){
    struct StudentRecord *temp = *A;
    *A = *B;
    *B = *temp;
}


struct StudentRecord *pSRecord[numrecords];

for(int i = 0; i < numrecords; i++) {

pSRecord[i] = &SRecords[i];

}

printf("%p \n", pSRecord[0]);
printf("%p \n", pSRecord[1]);

swap(&pSRecord[0], &pSRecord[1]);

printf("%p \n", pSRecord[0]);
printf("%p \n", pSRecord[1]);
Run Code Online (Sandbox Code Playgroud)

c swap struct pointers

0
推荐指数
1
解决办法
5833
查看次数

嵌套for循环的说明

嗨,有人可以请你解释下面的循环如何打印45.我想我不太明白这些嵌套循环是如何工作的:

#include <stdio.h>

int main() {
    int x, y, n;
    n = 0;
    for (x = 0; x < 10; x++)
        for (y = 0; y < x; y++)
            n++;

    printf("%d\n", n);
}
Run Code Online (Sandbox Code Playgroud)

c for-loop

0
推荐指数
1
解决办法
65
查看次数

标签 统计

c ×2

for-loop ×1

pointers ×1

struct ×1

swap ×1