1

I am relatively new to C.

Was solving a question and was hit with this line of code.

So why is x printing the size of the string? How exactly does printf work?

#include <stdio.h>
int main()
{
    int x;
    x = printf("stackoverflow");
    printf("Value of x:%d\n", x);
    return 0;
}

Output:

13

1 Answers1

1

return type of printf is int and it returns the number of characters it printed. So in your case it is returning length of the string.