1). Print anything in C++ without using semicolon:
Answer:
This is a very common C++ question which sometimes may be asked by any of your friends or given as a challenge to you . But trust me after doing this problem you will say "It was nothing at all."
Here's the code:
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
if(printf("Hello World")){
//and you are done
}
}
Understanding the program:
For doing this question a person must know about the usage and working of the printf and scanf functions.
printf() function not only prints on the screen but also returns the number of characters printed by it on the screen. Now in this case any string inside printf returns a value greater than 0 to the if condition, which makes it true and hence the program prints on the screen without any error and semicolon!!.
2). Printing a semicolon without using the semicolon:
Answer:
This question is almost similar to the above question but here the only knowledge required is of the ascii value of the special characters like semi colon.
As we know the ASCII value of semi colon is 59 hence in the above question, just by replacing the Hello world with { printf("%c",59) }
Thanks for the help
ReplyDeleteGreat piece of handout!!!
ReplyDeleteGreat piece of handout!!!
ReplyDeleteGr8
ReplyDelete