feat: update structure
This commit is contained in:
31
cs2106/labs/lab1/part1/lab1p1a.c
Normal file
31
cs2106/labs/lab1/part1/lab1p1a.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int (*fptr)(int);
|
||||
|
||||
int func(int x) {
|
||||
return 2 * x;
|
||||
}
|
||||
|
||||
|
||||
int y = 10;
|
||||
|
||||
int *(*pfptr)();
|
||||
|
||||
int *func2() {
|
||||
return &y;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Calling func with value 6: %d\n", func(6));
|
||||
printf("Now setting fptr to point to func.\n");
|
||||
fptr = func;
|
||||
printf("Caling fptr with value 6: %d\n", fptr(6));
|
||||
|
||||
printf("\nNow caling func2 which returns the address of global variable y: %p\n", func2());
|
||||
printf("Pointing pfptr to func2.\n");
|
||||
pfptr = func2;
|
||||
printf("Now calling fpfptr: %p\n", pfptr());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user