Skip to content

Instantly share code, notes, and snippets.

@ksoda
Last active October 30, 2016 14:39
Show Gist options
  • Save ksoda/f47776e25f98474ab7dc52c1a699b0af to your computer and use it in GitHub Desktop.
Save ksoda/f47776e25f98474ab7dc52c1a699b0af to your computer and use it in GitHub Desktop.
C lang samples
#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;
}
#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