Home » C programming language

Print text in new line without using '\n' in c programming



Since we already learned in previous posts that \n can be used to print the new line, but there are other ways too, to print new line in c programming language.

Using \x0A

0A in hexadecimal (10 in Decimal) is the ASCII value of new line character, we can use \x0A anywhere in the printf() statement to print text in new line.

Consider the program

#include <stdio.h>
int main()
{
	printf("Hello\x0Aworld.\x0A");
	return 0;	
}

Output

Hello
world.

Using %c to print the new line

We can use the %c within the string in printf() statement with the value 0x0A, 10 or '\n'.

Consider the program

#include <stdio.h>
int main()
{
	printf("Hello%cworld.%c",0x0A,0x0A);
	printf("Hello%cworld.%c",10,10);
	printf("Hello%cworld.%c",'\n','\n');
	return 0;
}

Output

Hello
world.
Hello
world.
Hello
world.





Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions


We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.