Last active
October 15, 2017 21:46
-
-
Save kira924age/3792de74aa476f61d4d168f365b5a850 to your computer and use it in GitHub Desktop.
ポインタのお勉強
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 <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; | |
} |
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
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