2017-11-01から1ヶ月間の記事一覧

連結リストのデータにポインタを使うのはいけないのか

さっきまでCで連結リストを実装していた。 その際、 typedef struct { Data *data; Node *next; } LinkedList; というように実装していた。 そしてうまく動作せずgdbでデバッグしたりしてたんだけど、いくらやってもうまくいかない。 しかも、ググっても連結…

C言語のポインタがやっぱりよくわかってなかったんだけどこの記事を書いてるうちにその部分はわかりました! わーい!

C言語の簡単なプログラムを作って構造体とポインタの挙動を調べているんだけど、やっぱりよくわからないところが出てきた。 まず、こう書いてみる。 #include <stdio.h> #include "test.h" #include <string.h> #include <stdlib.h> int zero = 0; typedef struct{ int *x; } X; typedef s</stdlib.h></string.h></stdio.h>…

C言語の構造体のメンバにポインタ変数を使った時の挙動がよくわからない

#include <stdio.h> #include <stdlib.h> #include "point.h" int main() { Point hoge; hoge = point_init(0,0); printf("%d %d\n", *(hoge.x), *(hoge.y)); return 0; } #include <stdio.h> #include "point.h" Point point_init(int s, int t) { Point p; p.x = &s; p.y = &t; int i =</stdio.h></stdlib.h></stdio.h>…