Commit dd08af23 authored by Paffenholz, Andreas's avatar Paffenholz, Andreas

programs ch 10

parent 3986048c
/*************************************
* Beispielprogramm zur Vorlesung
* Einfuehrung in die Programmierung I
* Andreas Paffenholz
* TU Darmstadt, Wintersemester 2020/21
* (c) 2020-
*
* Zeiger auf Zeigervariablen
*
* Uebersetzen mit
* gcc allocate_input_zeiger.c -o allocate_input_zeiger
* Aufruf mit
* ./allocate_input_zeiger 2 4 10
**************************************/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
int n = argc-1;
int** a = malloc(n*sizeof(int *));
for(int i = 0; i < n; ++i ) {
a[i] = (int *)malloc(sizeof(int));
*a[i] = atoi(argv[i+1]);
}
for(int i = 0; i < n; ++i ) {
printf("%d ",*a[i]);
}
printf("\n");
for ( int i = 0; i < n; ++i ) {
free(a[i]);
}
free(a);
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment