13 Answers
New Answerprintf function returns the number of characters it printed on the console. edit: SIMRAN Try #include <stdio.h> int main() { printf("\n%d", printf("Sololearn")) ; return 0; } output: Sololearn 9 see output that, this first prints Sololearn on console because of printf("Sololearn"), and returns 9 as it printed 9 characters so %d cause to print 9
Thats gonna return Hello5, Hello for the print 5 for the number of characters it printed, As for your question how it counts? Let me demonstrate you by a pseudo code, (Note:This my own understanding) Func printf(string) Int counter ->0; for char x : string { Print_to_stdout(x); counter++; } Return counter; Basically, it breaks the received String into char array, then prints one by one into the Standard Output stream, and every time it does that, it keeps track of number of time it printed through a counter variable
G'day SIMRAN as ANONYMOUS said, output is Hello5. Your code is counting the characters in "Hello" to be 5. Try a different length string & see what happens.
Hello5 //word+no.of letter //as 20(can be either other no.to eg:19,21 or non eg:0) doesn't make any change
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message