Last active
October 30, 2016 14:39
-
-
Save ksoda/f47776e25f98474ab7dc52c1a699b0af to your computer and use it in GitHub Desktop.
C lang samples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdbool.h> | |
typedef int (*Operator)(int a, int b); | |
int add(int a, int b) { | |
return(a + b); | |
} | |
int mult(int a, int b) { | |
return(a * b); | |
} | |
int main(void) { | |
int a, b, c; | |
Operator op; | |
a = 2, b = 3; | |
op = false ? &add : &mult; | |
c = (op)(a, b); | |
printf("Answer is %d\n", c); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
struct Point { | |
int x, y; | |
}; | |
struct Size { | |
int width, height; | |
}; | |
struct Rectangle { | |
struct Point point; | |
struct Size size; | |
}; | |
int main(void) { | |
struct Rectangle rect = { | |
.point = { | |
.x = 20, | |
.y = 50 | |
}, | |
.size = { | |
.width = 300, | |
.height = 400 | |
} | |
}; | |
printf( | |
"(%d, %d)\n(%d, %d)\n", | |
rect.point.x, rect.point.y, | |
rect.size.width, rect.size.height | |
); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment