#define MAX_SIZE 20
#include <stdio.h>
#include <stdlib.h>
typedef struct _TagA
{
int m_num;
}_tagA, *p_tagA;
int main()
{
p_tagA obj_001, obj_002;
obj_001 = (p_tagA)calloc(MAX_SIZE, sizeof(_tagA));
if(obj_001 == NULL)
{
printf("メモリ確保に失敗しました \n");
return -1;
}
else
printf("メモリ確保成功 \n");
obj_002 = obj_001;
for(int i=0; i<MAX_SIZE; ++i)
{
obj_002[i].m_num = i;
}
for(int i=0; i<MAX_SIZE; ++i)
{
printf("%d \n", obj_002[i].m_num);
}
// 動的確保したメモリの解放
free(obj_001);
return 0;
}
I2RlZmluZSBNQVhfU0laRSAgICAgICAgMjAKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCnR5cGVkZWYgc3RydWN0IF9UYWdBCnsKICAgICAgICBpbnQgbV9udW07CiAgICAgICAgCn1fdGFnQSwgKnBfdGFnQTsKCmludCBtYWluKCkKewogICAgICAgIHBfdGFnQSBvYmpfMDAxLCBvYmpfMDAyOwogICAgICAgIAogICAgICAgIG9ial8wMDEgPSAocF90YWdBKWNhbGxvYyhNQVhfU0laRSwgc2l6ZW9mKF90YWdBKSk7CiAgICAgICAgaWYob2JqXzAwMSA9PSBOVUxMKQogICAgICAgIHsKICAgICAgICAgICAgICAgIHByaW50Zigi44Oh44Oi44Oq56K65L+d44Gr5aSx5pWX44GX44G+44GX44GfIFxuIik7CiAgICAgICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICAgICAgICAgIHByaW50Zigi44Oh44Oi44Oq56K65L+d5oiQ5YqfIFxuIik7CiAgICAgICAgCiAgICAgICAgb2JqXzAwMiA9IG9ial8wMDE7CiAgICAgICAgZm9yKGludCBpPTA7IGk8TUFYX1NJWkU7ICsraSkKICAgICAgICB7CiAgICAgICAgICAgICAgICBvYmpfMDAyW2ldLm1fbnVtID0gaTsKICAgICAgICB9CiAgICAgICAgZm9yKGludCBpPTA7IGk8TUFYX1NJWkU7ICsraSkKICAgICAgICB7CiAgICAgICAgICAgICAgICBwcmludGYoIiVkIFxuIiwgb2JqXzAwMltpXS5tX251bSk7CiAgICAgICAgfQogICAgICAgIAovLyAgICAgIOWLleeahOeiuuS/neOBl+OBn+ODoeODouODquOBruino+aUvgogICAgICAgIGZyZWUob2JqXzAwMSk7CiAgICAgICAgcmV0dXJuIDA7Cn0=