Different working of cout and printf while both do the same work | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Different working of cout and printf while both do the same work

we use format specifiers like %d, %c etc in printf but we don't use them in cout. why??

25th Aug 2017, 2:54 AM
Gunjan yadav
Gunjan yadav - avatar
3 Answers
+ 12
"printf" returns an integer value (equal to the number of characters printed) while "cout" does not return anything And. cout << "y = " << 7; is not atomic. printf("%s = %d", "y", 7); is atomic. cout performs typechecking, printf doesn't. There's no iostream equivalent of "% d"
25th Aug 2017, 3:14 AM
P R
P R - avatar
+ 10
u r welcomed @Manual
25th Aug 2017, 3:45 AM
P R
P R - avatar
+ 7
Thanks @PR I did not know printf() could do that. I will give it a shot later!
25th Aug 2017, 3:32 AM
Manual
Manual - avatar