Skip to content

Instantly share code, notes, and snippets.

@ochilab
Last active September 19, 2018 23:41
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 ochilab/1a915353718e0a93d23b to your computer and use it in GitHub Desktop.
Save ochilab/1a915353718e0a93d23b to your computer and use it in GitHub Desktop.
構造体とcallocによる動的生成についてのサンプル(vs2017バージョン)
// 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