+ 1

What will be the output of the program in c language

void main() { int x = 25; printf("%d", printf("%d", x)); }

8th Dec 2016, 5:50 AM
Casy
Casy - avatar
2 ответов
0
I've got the error it says typeprefixerror redecleration of printf...so i think you are overloading printf () which is globally defined in stdio if you want to do it like that then you have to define the function which is your own user defined function having like this #include <iostream> #include <string> #include <stdio.h> using namespace std; int printf(string x,int y){ return y; } int main() { printf("%d",printf("%d",5) ); return 0; } Output No Output
8th Dec 2016, 6:26 AM
Vipul Walia
Vipul Walia - avatar
0
I compiled and run it on online C compiler. And the output is 252 Not a whole number, but 25 2 ,without space between. And the reason is, when you call printf("%d", printf("%d", x)); there is not written only a value of x (25), but too a returned value of inner printf function. And the function returns "number of characters written ". So lenght, of 25, tha's 2. But this returned value is not printed usually this way, sometimes for checking of correct output
8th Dec 2016, 10:01 AM
Petr Hatina
Petr Hatina - avatar