sprintf在哪里存储其输出?

CS *_*ent 3 c printf

如果我有以下代码,那么句子在哪里sprintf存储?

它是存储在提供的100个字节malloc中还是存储在其他地方,store指针现在指向新位置?

char *store = malloc(100); 
int num = 77;
sprintf(store, "the number was: %d", num);
Run Code Online (Sandbox Code Playgroud)

Mur*_*nik 5

sprintf不会自己分配内存 - 它只是将输入存储在先前分配的缓冲区中.在您的情况下,这确实是您通过malloc调用分配的缓冲区.