+ 6

How it Works Please Explain🙏🙏🙏🙏

This program works for me:- main() { if(printf("Prince") && getch()) { } } I don't know how it works, I don't even include the header files, but it works. This program is used to print something without using semicolon. I used Turbo C Compiler. Language : C

14th Apr 2017, 3:27 PM
Prince Saini
Prince Saini - avatar
5 Respostas
+ 3
bool x =false; x= printf("ahhh"); bool y = false; y = getch(); if (x && y) { printf("\ndone");} it turns out that both condition became true. But under the hood of uninitialized bool type is a random nature which in my compiler it is always true by default. I initialized them by false and after which both expressions make their respective variables true. so done printed successfully.
14th Apr 2017, 3:45 PM
Babak
Babak - avatar
+ 3
@Babak But how printf() and getch() functions worked I haven't included the header files
14th Apr 2017, 4:01 PM
Prince Saini
Prince Saini - avatar
+ 3
You have specified that you are using Turbo C Compiler. It automatically includes <stdio.h> and <conio.h> at the time of compilation.
14th Apr 2017, 4:11 PM
à€Šà„‡à€”à„‡à€‚à€Šà„à€° à€źà€čà€Ÿà€œà€š (Devender)
à€Šà„‡à€”à„‡à€‚à€Šà„à€° à€źà€čà€Ÿà€œà€š (Devender) - avatar
+ 3
@Devender Sorry, I'm using Turbo C++ compiler it can also compile c code but it doesn't include header files automatically normally it give an error that printf() need a prototype but in this program it doesn't
14th Apr 2017, 4:27 PM
Prince Saini
Prince Saini - avatar
+ 2
@ Prince Sorry, I revised my code and explanations. I've added conio.h header file to my project (in visual studio) to use getch(), but printf doesn't need any special header file. BTW there's no bool type in C 89/90 but is in C99 (_bool) and I put it just for the sake of explanation.
14th Apr 2017, 4:14 PM
Babak
Babak - avatar