(1). #include<stdio.h> int main() { printf("The single quote \' is this "); } (2). #include<stdio.h> int main() { printf("The single quote ' is this "); } Questions (a)same output so why we take \' as escape sequence . It does not do anything special?? (b) Why did these characters call "escape sequences" . ? Help plzz
This is pretty simple to explain so here I go... your trying to print to the console "The single quote ' is this " take note that its surrounded by double quotes " ". the ' is a single quote so you do not need to escape it unless it's surrounded by single quotes. printf requires double quotes so there is no need to worry about escaping a single quote unless your enclosing something in between them. Your also not formatting your text for out put so there shouldn't be any way of knowing the out put. printf() takes formatting and text or numbers. it should be like this (1). Code: #include<stdio.h> int main() { printf("%s", "The single quote \' is this "); } (2). Code: #include<stdio.h> int main() { printf("%s","The single quote ' is this "); } %s means string but you can also use %d for decimals, %c for character, and %f for float. Make sure formating is the first parameter to printf() followed by a comma and the out put data. Code: #include<stdio.h> void main() { printf("%s","This is a string \n"); // string printf("%f \n", 12.45); // float printf("%d \n",56778); // decimal char i = scanf("i"); } the above code will print out the values with a newline after each print. That is how you use printf().
one more question :P Why dont we use '&' in the case of strings in function scanf ?? e.g. :- scanf("%s",date); here date is a character arraymeans string. Plz help
using & next to a variable's name passes the value by reference. You don't need to do that if it's already a pointer. Try doing some simple pointer and reference output and see what you get.