+ 11

cout << printf; // output: 1

Why do I get a 1 as output if I cout a function name?

28th Apr 2019, 5:47 PM
HonFu
HonFu - avatar
7 Respostas
+ 11
~ swim ~ If printf returns the no of chars then can we write like this int charsCount = printf("Hello"); OR char arr[] = "Hello"; int charsCount = printf("%s", arr); Which piece of code is valid or invalid?
28th Apr 2019, 7:16 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 10
Alright, thank you for answering :)
28th Apr 2019, 7:21 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 7
How about: int arr[printf("Weird sizing")]; That gonna work? 😁 So basically if I cout a function name I get the answer: "Yep, this function does exist." Thanks, ~ swim ~!
28th Apr 2019, 7:47 PM
HonFu
HonFu - avatar
+ 6
~ swim ~ i thought the return value of printf function is 1
28th Apr 2019, 6:46 PM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 6
Yeah, Jay, that's the usual return value. I knew about that before; I didn't know you can bool a function though.
28th Apr 2019, 9:54 PM
HonFu
HonFu - avatar
+ 5
~ swim ~ I think you meant nAutAxH AhmAd and not *AsterisK* in one of your comments above. They both have darkish avatars and nearly fooled me too.
29th Apr 2019, 1:06 AM
Sonic
Sonic - avatar
0
When you write any function name without the parentheses it gives you the address of that function, since printf exists the adress is more than 0 which returns true.
30th Apr 2019, 3:17 PM
Kotra25
Kotra25 - avatar