+ 2

Explain use of /n

23rd Jun 2018, 7:41 AM
Sameer Kulkarni
Sameer Kulkarni - avatar
7 Respuestas
+ 4
/n means division by n \n is used to put a new line character in a string, because you cannot write s="One Two"; you write s="One\nTwo"; One and Two will be on separate lines
23rd Jun 2018, 8:15 AM
michal
+ 4
cout<<"I like"; cout<<"C++"; //output: I likeC++ With \n cout<<"I like\n"; cout<<"C++"; //output: I like C++
23rd Jun 2018, 1:30 PM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 4
You have 3 conditions or answers.Though Example 1 & 3 are valid but ex 2 if n is some variable then as not specified properly. So if you mean /n then it should be either a continuation(where n is some variable) to some macro to next line or it can also means divide. 1. example of divide:- int n=7,a=6; int c=a/n; printf("%d",c); Output :- 0. 2. example of macro:- #define me(n) printf("hi");/n main() { me(7); } Output:- hi. But if you mean \n then it means escape sequence of new line or linefeed.The "\" acts as an escape character and along with action variable like n it forms an escape sequence.We have many other escape sequences in C. It converts to (CTRL)0x00d (Linefeed)0x00a which is hex values of ascii extended and it converts or assumes a control char of ascii(CTRL) +(Linefeed) (EAX register) to give new line feed.So you have a new line. 3.Example:- main(){ char n[5]="bye"; printf("Hi \n%s",n,"\nbye); } Output:- hi bye. So callout "bye" is in new line feed.Not two bye!!!
23rd Jun 2018, 2:43 PM
D-Key
D-Key - avatar
0
When using a print function, most langages ask for a specific character to stand for newline. While simply pressing ENTER inside your string might work with high level languages such as Python (you can use pressing ENTER inside triple quotes strings) it will give an error with most languages. The same thing happens with tab. That specific character is \n (and \t for tab). Ex in C: printf("Hello world\nand you."); will output Hello World and you.
24th Jun 2018, 8:22 PM
Alex Wolf
Alex Wolf - avatar
0
/n new line
25th Jun 2018, 11:54 AM
sonaal
sonaal - avatar
0
Actually it's \n not /n. It adds a new line for example print("You are \n Here") output = You are Here
30th Jun 2018, 2:46 PM
Shruti Negi
Shruti Negi - avatar
0
add a new line at the end of a string for example
4th Jul 2018, 11:31 AM
Neo
Neo - avatar