Code:need answ & expl of following question main() { printf("\nab"); printf("\bsi"); printf("\rha"); }
Code:need answ & expl of following question main() { printf("\nab"); printf("\bsi"); printf("\rha"); }
Google printf and read its documentation.
1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
3. Get rid of conio.h and other antiquated DOS crap headers.
4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.
hai
would be the output!
\n is newline-takes cursor to new/next line on console;
\b is backspace-does the same work as the backspace key on keyboard;
\r is carriage return-brings the cursor to beginning of current line on console;
try interpreting the arguments provided to 'printf',u ll understand hw it prints 'hai'.
Still teaching stupid programming tricks in Southern Asia, amirite?
Has nothing to do with real time programming however if you execute this you still get an answer!
Look carefully at the box character - see the numbers?
Now go here
Ascii Table - ASCII character codes and html, octal, hex and decimal chart conversion
Then read your C book for what \b means.
Do you see it now?
Also, you would have gotten a much better answer if you'd posted both code AND output in the same post, instead of the terse "what's this code do" you started with.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.