Special character

Special character

Special character

Special character are characters that have a special meaning in C++. These characters are used to represent things like newlines, tabs, and other non-printable characters. Here are some of the most commonly used special characters in C++:

  1. \n: This represents a newline character. It is used to move the cursor to the beginning of the next line.
  2. \t: This represents a tab character. It is used to move the cursor to the next tab stop.
  3. \\: This represents a backslash character. It is used to escape special characters that have a different meaning in C++, such as double quotes and single quotes.
  4. \”: This represents a double quote character. It is used to include double quotes within a string that is enclosed in double quotes.
  5. \’: This represents a single quote character. It is used to include single quotes within a string that is enclosed in single quotes.
  6. \r: This represents a carriage return character. It is used to move the cursor to the beginning of the current line.
  7. \b: This represents a backspace character. It is used to move the cursor back one space.

Here is an example of using some of these special characters in a C++ program:

				
					#include<iostream>

int main() {

    std::cout <<"Hello\tworld!\n";

    std::cout << "This is a backslash: \\";

    std::cout << "This is a double quote: \"";

    std::cout << "This is a single quote: \'\n";

    std::cout << "This is a carriage return: \r";

    std::cout << "This is a backspace: abc\bdef\n";

    return 0;

}
				
			
Join To Get Our Newsletter
Spread the love