+ 3
In c without semicolon why any text is print ??
We all are knowing in c or c++ we can print hello world without semicolon by using if switch and while .But I want to know why it will print what is the reason behind it. Answer me
5 Antworten
+ 6
Thanks for the clarification ~ swim ~ . I guess my comment is more applicable to just C then. However, in C++ as well, integer values are implicitly cast to bool without a problem.
+ 4
~ swim ~ what I meant was, even though int printf(const char *format, ...); returns an integer, C/C++ has no issue using the result within an if condition whereas a more strongly typed language would have had a syntax error.
+ 3
~ swim ~ when the question was posted as "In C without semicolon....", I thought that there was an implicit subtext to the question saying "while it is not possible to do this easily in some other langiages." That's just how I interpreted the question and why I referred to other languages. If the question author did not imply this, then I apologise for my misinterpretation.
However, the way I interpreted it, I always thought that the weak typing and implicit type casting features of C is what made it possible to use such tricks to perform output in an imperative language that demanded semi-colon statement terminators.
So while I managed to perform output withou using a ; in C I wasn't easily able to do it in Java and C# which also demand semi-colon statement separators. But perhaps someone more cluey can show me how.
https://code.sololearn.com/chSf12Hiz5ov/?ref=app
https://code.sololearn.com/c7PTL20PPhXM/?ref=app
https://code.sololearn.com/c7VjNav65znm/?ref=app
+ 2
Also, in C/C++ there is no explicit boolean type and if statements can use integer values without a syntax error, which are returned by functions like printf().