Skip to content

Instantly share code, notes, and snippets.

@devlights
Last active September 3, 2023 09:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devlights/7b50367bf3d5e47a3f66109b72741e23 to your computer and use it in GitHub Desktop.
Save devlights/7b50367bf3d5e47a3f66109b72741e23 to your computer and use it in GitHub Desktop.
C言語おさらい(自分用)

Run

$ gcc -o app main.c
$ ./app
16975631        16975631        1807    15
15
7
3
1
15
7
3
1
15
7
3
1
#include <stdio.h>
#include <stdlib.h>
void fn(char *a, int len) {
for (int i = 0; i < len; i++) {
printf("%d\n", a[i]);
}
}
int main(void) {
// 1 3 7 15
int i = 0b00000001000000110000011100001111;
int *p1 = &i;
short *p2 = (short *)p1;
char *p3 = (char *)p1;
printf("%d\t%d\t%d\t%d\n", i, *p1, *p2, *p3);
for (int y = 0; y < 4; y++) {
printf("%d\n", *(p3+y));
}
for (int y = 0; y < 4; y++) {
printf("%d\n", p3[y]);
}
fn(p3, 4);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment