Unable to see how string is printed?

Feb 23, 2021 at 8:15am
Unable to see how string is printed after the printf in the before line.

#include <iostream>
using namespace std;

int main() {
// your code goes here
char st[] = "CODING";
printf("While printing ");
printf(", the value returned by printf() is : %d", printf("%s", st)
return 0;
}

The output is:
While printing CODING, the value returned by printf() is : 6
Last edited on Feb 23, 2021 at 8:22am
Feb 23, 2021 at 9:24am
You wrote this
1
2
3
printf("While printing ");
n =  printf("%s", st);
printf(", the value returned by printf() is : %d", n );


That is, you evaluated the result (and the side effect of seeing something) by calling printf("%s", st) before calling the final printf function to print the result.
Feb 23, 2021 at 9:58am
Sorry, never saw such for long time. It is now visible that the contained printf () is printing earlier.
Topic archived. No new replies allowed.