a4.3 & a4.4

This commit is contained in:
Luca Conte 2023-11-07 23:02:49 +01:00
parent f71cd26460
commit 9624e8543f
2 changed files with 45 additions and 0 deletions

31
a4.3/tauschen.c Normal file
View File

@ -0,0 +1,31 @@
#include <stdio.h>
void tausche_intPtr(int** a, int** b) {
int* tmp = *a;
*a = *b;
*b = tmp;
}
void tausche_int(int* a, int* b) {
int tmp = *a;
*a = *b;
*b = tmp;
}
int main(void) {
int i = 1;
int j = 2;
printf("i = %d, j = %d\n", i, j);
tausche_int(&i, &j);
printf("i = %d, j = %d\n", i, j);
int* a = &i;
int* b = &j;
printf("*a = %d, *b = %d\n", *a, *b);
tausche_intPtr(&a, &b);
printf("*a = %d, *b = %d\n", *a, *b);
return 0;
}

14
a4.4/array.c Normal file
View File

@ -0,0 +1,14 @@
#include <stdio.h>
int main(void) {
int a[] = { 1, 5, 19, -4, 3 };
int* p;
int i;
p = a;
for (i=1; i<5; i++) {
if (a[i] > *p) {
p = &a[i];
}
}
printf("Maximum: %d\n", *p );
return 0;
}