Skip to content

Instantly share code, notes, and snippets.

@kira924age
Last active October 15, 2017 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kira924age/3792de74aa476f61d4d168f365b5a850 to your computer and use it in GitHub Desktop.
Save kira924age/3792de74aa476f61d4d168f365b5a850 to your computer and use it in GitHub Desktop.
ポインタのお勉強
#include <stdio.h>
#include <string.h>
void *test(char *s) {
int i;
for (i = 0; i < strlen(s); i++) {
// ポインタが指す値を表示する3通りの方法
printf("%c\n", s[i]);
printf("%c\n", *(&s[0] + i));
printf("%c\n", *(s + i));
// ポインタのアドレスを表示する3通りの方法
printf("%p\n", &s[i]);
printf("%p\n", (&s[0] + i));
printf("%p\n", (s + i));
}
}
int main() {
char str[] = "ABCDE";
printf("%s\n", str);
test(str);
return 0;
}
ABCDE
A
A
A
0x7ffdb320dc90
0x7ffdb320dc90
0x7ffdb320dc90
B
B
B
0x7ffdb320dc91
0x7ffdb320dc91
0x7ffdb320dc91
C
C
C
0x7ffdb320dc92
0x7ffdb320dc92
0x7ffdb320dc92
D
D
D
0x7ffdb320dc93
0x7ffdb320dc93
0x7ffdb320dc93
E
E
E
0x7ffdb320dc94
0x7ffdb320dc94
0x7ffdb320dc94
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment