嗨,我正在尝试创建交换函数,以交换结构的前两个元素。有人可以告诉我如何使这项工作。
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) 嗨,有人可以请你解释下面的循环如何打印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)