C Programs Tutorials | IT Developer
IT Developer

C Programming - C Special Characters



Share with a Friend

C Programming - C Special Characters

C Special Characters

Special characters in C are symbols that have predefined meanings and are used for specific purposes within a program. These characters are part of the syntax of the C language and help in writing, structuring, and controlling the flow of a program.

List of Special Characters in C

Character Description
#

Preprocessor directive symbol

"

Double quotation mark (string literal)

'

Single quotation mark (character literal)

\

Backslash (used for escape sequences)

{ }

Curly braces (block of code)

[ ]

Square brackets (array indexing)

( )

Parentheses (function calls, grouping expressions)

,

Comma (separates items in a list)

;

Semicolon (statement terminator)

:

Colon (used in labels and ternary operator)

.

Dot (access structure members)

->

Arrow operator (access structure members through pointers)

*

Asterisk (pointer declaration or multiplication)

&

Ampersand (address-of operator)

=

Assignment operator

+ -

Plus and minus (arithmetic operators)

!

Logical NOT operator

~

Bitwise NOT operator

?

Ternary conditional operator

\\

Escape sequence for backslash

%

Modulus operator

`  
& &&

Bitwise AND, Logical AND operators

< >

Relational operators (less than, greater than)

/

Division operator

^

Bitwise XOR operator

"

Double quotes (string delimiters)

Usage Examples

  1. Preprocessor Directive (#):

C

#include <stdio.h>

  1. Escape Sequences (\):

C

printf("Hello\nWorld"); // Outputs: Hello (new line) World

  1. Curly Braces ({}):

C

if (x > 0) {

    printf("Positive");

}

  1. Square Brackets ([]):

C

int arr[5] = {1, 2, 3, 4, 5};

  1. Parentheses (()):

C

int sum = (a + b) * c;

  1. Semicolon (;):

C

printf("End of statement");

  1. Ternary Operator (? :):

C

int max = (a > b) ? a : b;

  1. Dot and Arrow Operators (. and ->):

C

struct Point {

    int x, y;

} p1;

p1.x = 10; // Using dot operator

struct Point *ptr = &p1;

ptr->y = 20; // Using arrow operator

  1. Assignment and Arithmetic Operators:

C

int x = 5;

x += 10; // Equivalent to x = x + 10;

Escape Sequences

Escape sequences are special characters prefixed with a backslash (\) and used to represent certain non-printable or control characters.

Escape Sequence Meaning
\n

Newline

\t

Horizontal tab

\b

Backspace

\r

Carriage return

\\

Backslash (\)

\'

Single quote (')

\"

Double quote (")

\0

Null character

Conclusion

Special characters in C play a crucial role in the language's syntax and functionality. Mastering their use allows you to write clear, concise, and functional code. Always be cautious with their usage to avoid syntax errors.