+ 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
5 Réponses
+ 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.
+ 3
@Babak
But how printf() and getch() functions worked
I haven't included the header files
+ 3
You have specified that you are using Turbo C Compiler. It automatically includes <stdio.h> and <conio.h> at the time of compilation.
+ 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
+ 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.