| arrays/pointer-types-1.c - Illustration af pointervariable af forskellige typer - giver compileringsfejl. | Lektion 9 - slide 9 : 30 Program 1 |
#include <stdio.h>
#include <stddef.h>
int main(void){
int *i, j = 1;
char *c, h = 'a';
double *d, e = 2.0;
void *f;
i = &e; /* Error: i cannot point to a double */
c = &h; /* OK */
d = &j; /* Error: d cannot point to an int */
f = &j; /* OK. f is a generic pointer */
printf("%d, %c, %f, %d\n", *i,
*c,
*d,
*f /* Error: dereferencing */
); /* pointer to void */
}