Why did the output is 01? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why did the output is 01?

How did n becomes 1? Explain the process please int main(){ int n=printf("0"); printf("%d",n);

28th Jan 2021, 10:17 AM
Hrutik Bhalerao
Hrutik Bhalerao - avatar
3 Answers
+ 12
printf() returns the number of characters inserted into the output stream, which may serve as a useful tool for error detection: https://en.cppreference.com/w/c/io/fprintf
28th Jan 2021, 10:20 AM
Shadow
Shadow - avatar
+ 1
printf returns the number of characters successfully written or a negative number if it fails
28th Jan 2021, 10:22 AM
Angelo
Angelo - avatar
+ 1
First printf will print normally 0 then it will assign to n after that next printf will return total numbers of characters which u have written under double quotes with whitespaces if u will give space or u will write any chars like special symbols @ ,_,!...... It will also be count Int n= printf("hello"); Here total chars are 5 and in printf u use %d so it will print integer values if u will write %x then it will print hex values.
28th Jan 2021, 1:35 PM
A S Raghuvanshi
A S Raghuvanshi - avatar