+ 6
What's the output of code ?
#include <stdio.h> int main() { int x =20; x=printf("Hello"); printf("%d",x); return 0; }
13 Réponses
+ 6
printf 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
+ 4
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
+ 1
HungryTradie
Can you please explain about it briefly ? How it's counting the characters 😅
+ 1
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
0
Hello5
- 1
Yes jayakrishna, you are right
- 1
Ouput is Hello5
- 1
Hello5 the string length is 5 so it'll print 5 rather than 20
- 2
Hello5
- 2
Hello5
- 2
It outputs hello5
- 2
Output hello 5