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.




Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.