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.





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.