What happens when the following code executes? int main() {
What happens when the following code executes?
#include <stdio.h>
int main() {
char buffer[50];
int n = sprintf(buffer, "Hello, World!");
printf("%d %s", n, buffer);
return 0;
}
Show answerHide answer
Correct answer: (D) Prints '13 Hello, World!'
Explanation
sprintf writes "Hello, World!" into buffer and returns the number of characters written, which is 13 (5 + comma + space + 5 + !). printf then prints "13 Hello, World!".