01_嵌入式高级C语言阶段考核题目验证
This commit is contained in:
parent
4e10a4d84d
commit
e73b06afa5
|
@ -0,0 +1,25 @@
|
|||
#include <stdio.h>
|
||||
|
||||
// 这种方式只能交换指针指向的值,不能交换指针本身,而且无法改变实参的值
|
||||
void swap(int *piA, int *piB)
|
||||
{
|
||||
printf("first iA-p: %p, iB-p: %p\n iA: %d,iB: %d\n", piA, piB, *piA, *piB);
|
||||
|
||||
int *piC;
|
||||
piC = piA;
|
||||
piA = piB;
|
||||
piB = piC;
|
||||
printf("after iA-p: %p, iB-p: %p\n iA: %d,iB: %d\n", piA, piB, *piA, *piB);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int iA = 100, iB = 200;
|
||||
printf("main first iA-p: %p, iB-p: %p\n iA: %d,iB: %d\n", &iA, &iB, iA, iB);
|
||||
|
||||
int *piA = &iA, *piB = &iB;
|
||||
swap(piA, piB);
|
||||
printf("main after iA-p: %p, iB-p: %p\n iA: %d,iB: %d\n", &iA, &iB, iA, iB);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
#include <stdio.h>
|
||||
|
||||
// 会交换实参的值
|
||||
void swap(int *piA, int *piB)
|
||||
{
|
||||
// printf("first iA-p: %p, iB-p: %p\n iA: %d,iB: %d\n", piA, piB, *piA, *piB);
|
||||
|
||||
int piC;
|
||||
piC = *piA;
|
||||
*piA = *piB;
|
||||
*piB = piC;
|
||||
// printf("after iA-p: %p, iB-p: %p\n iA: %d,iB: %d\n", piA, piB, *piA, *piB);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int iA = 100, iB = 200;
|
||||
printf("first iA-p: %p, iB-p: %p\n iA: %d,iB: %d\n", &iA, &iB, iA, iB);
|
||||
|
||||
int *piA = &iA, *piB = &iB;
|
||||
swap(piA, piB);
|
||||
printf("after iA-p: %p, iB-p: %p\n iA: %d,iB: %d\n", &iA, &iB, iA, iB);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#define ADD(x, y) (x + y) /*加*/
|
||||
#define SUB(x, y) (x) - (y) /*减*/
|
||||
#define MUL(x, y) (x * y) /*乘*/
|
||||
|
||||
int main()
|
||||
{
|
||||
unsigned int uiA;
|
||||
uiA = MUL(ADD(9, 2), SUB(6, 3)); // ((9+2)*(6)-(3)) = 63
|
||||
printf("uiA = %d\n", uiA);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int i;
|
||||
int sum = 1;
|
||||
for (i = 1; i <= 10; i++)
|
||||
{
|
||||
sum += i; // 加完之后才判断是否为5,因此sum会加上5
|
||||
if (i == 5)
|
||||
continue;
|
||||
// printf("i = %d, sum=%d\n", i, sum);
|
||||
}
|
||||
printf("sum=%d\n", sum);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
unsigned int uiCount = 0;
|
||||
for (; uiCount <= 10; uiCount++)
|
||||
{
|
||||
printf("uiCount=%u\n", uiCount);
|
||||
|
||||
if (uiCount == 5)
|
||||
{
|
||||
break;
|
||||
}
|
||||
// printf("uiCount=%u\n", uiCount);
|
||||
}
|
||||
// printf("uiCount=%u\n", uiCount);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
void func(char aver[100])
|
||||
{
|
||||
char str[] = "hello world";
|
||||
char *p = str;
|
||||
char n = 10;
|
||||
void *p1 = malloc(100);
|
||||
printf("size1=[%d]\n", sizeof(str));
|
||||
printf("size2=[%d]\n", sizeof(p));
|
||||
printf("size3=[%d]\n", sizeof(n));
|
||||
printf("size4=[%d]\n", sizeof(aver));
|
||||
printf("size5=[%d]\n", sizeof(p1));
|
||||
}
|
||||
int main()
|
||||
{
|
||||
char str[100];
|
||||
func(str);
|
||||
}
|
Loading…
Reference in New Issue