Last active
September 19, 2018 23:41
-
-
Save ochilab/1a915353718e0a93d23b to your computer and use it in GitHub Desktop.
構造体とcallocによる動的生成についてのサンプル(vs2017バージョン)
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
// ConsoleApplication1.cpp : アプリケーションのエントリ ポイントを定義します。 | |
// | |
#include "stdafx.h" | |
#include <stdlib.h> | |
// 構造体Nodeの定義 | |
typedef struct _node { | |
int id; //idを保存 | |
const char* name; //名前を保存 | |
_node* next; //自身と同じ型を参照するためのポインタ | |
}Node; | |
Node* mallocNode() { | |
//領域を動的に生成 | |
Node *node = (Node*)calloc(1, sizeof(Node)); | |
return node; | |
} | |
int main() | |
{ | |
Node node1; | |
Node *node2 = mallocNode(); | |
getchar(); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment