#include <stdlib.h>
#include <stdio.h>
void retorna_algo(int size, int* destino){
if (size == 1){
*destino = 1;
} else if (size == 3) {
memcpy(destino
, (int[]){1, 2, 3}, 3*sizeof(int)); }
}
int main(void) {
int *ponteiro;
ponteiro
= malloc(sizeof(int)); retorna_algo(1, ponteiro);
printf("%d\n", *ponteiro
); // Escreve "1" - como esperado
ponteiro
= realloc(ponteiro
, sizeof(int)*3); retorna_algo(3, ponteiro);
printf("%d | %d | %d\n", ponteiro
[0], ponteiro
[1], ponteiro
[2]); // Escreve "1 | 0 | 0", basicamente mantendo o valor zerado do malloc e realloc
return 0;
}
I2luY2x1ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8c3RkaW8uaD4KCnZvaWQgcmV0b3JuYV9hbGdvKGludCBzaXplLCBpbnQqIGRlc3Rpbm8pewogIGlmIChzaXplID09IDEpewogICAgKmRlc3Rpbm8gPSAxOwogIH0gZWxzZSBpZiAoc2l6ZSA9PSAzKSB7CiAgICBtZW1jcHkoZGVzdGlubywgKGludFtdKXsxLCAyLCAzfSwgMypzaXplb2YoaW50KSk7CiAgfQp9CgppbnQgbWFpbih2b2lkKSB7CiAgaW50ICpwb250ZWlybzsKCiAgcG9udGVpcm8gPSBtYWxsb2Moc2l6ZW9mKGludCkpOwogIHJldG9ybmFfYWxnbygxLCBwb250ZWlybyk7CiAgcHJpbnRmKCIlZFxuIiwgKnBvbnRlaXJvKTsgLy8gRXNjcmV2ZSAiMSIgLSBjb21vIGVzcGVyYWRvCgogIHBvbnRlaXJvID0gcmVhbGxvYyhwb250ZWlybywgc2l6ZW9mKGludCkqMyk7CiAgcmV0b3JuYV9hbGdvKDMsIHBvbnRlaXJvKTsKCiAgcHJpbnRmKCIlZCB8ICVkIHwgJWRcbiIsIHBvbnRlaXJvWzBdLCBwb250ZWlyb1sxXSwgcG9udGVpcm9bMl0pOwogIC8vIEVzY3JldmUgIjEgfCAwIHwgMCIsIGJhc2ljYW1lbnRlIG1hbnRlbmRvIG8gdmFsb3IgemVyYWRvIGRvIG1hbGxvYyBlIHJlYWxsb2MKCiAgcmV0dXJuIDA7Cn0=