0

Explain why gives output %%d

#include<iostream> using namespace std; int main(){ int a=10; printf("%%%%%%d"+1); return 0; }

22nd Jun 2021, 10:59 AM
Abhishek Bairwa
Abhishek Bairwa - avatar
2 odpowiedzi
+ 2
Abhishek Bairwa because first two %% output as %, then next two %% output as %, third one similary, and finally d... % is the character used to escape variable placeholder, so to output % you need to escape it ;)
22nd Jun 2021, 11:07 AM
visph
visph - avatar
+ 1
Are you sure it shows %%d? Running in the code playground shows me %%{random large number}, which is an output I will expect, so I will instead explain the output I get. "%%%%%%d"+1 becomes "%%%%%d". The number of % becomes 5 because the +1. %% outputs % in literal So %%%% outputs %%. And the final %d, because you didn't give any parameter for it. It outputs random number which I think is a garbage number, but I can't ensure about that.
22nd Jun 2021, 11:37 AM
你知道規則,我也是
你知道規則,我也是 - avatar