• C Programming Video Tutorials

Special Characters in C



The C language identifies a character set that comprises English alphabets – upper and lowercase (A to Z as well as "a" to "z"), digits 0 to 9, and certain other symbols called "special characters" with a certain meaning attached to them.

While many of the characters in the special symbol category are defined as operators, certain combinations of characters also have a special meaning attached to them. For example, "\n" is known as the newline character. Such combinations are called escape sequences.

In C language, quotation marks too have a special meaning. Double quotes are used for strings, while characters are enclosed inside single quotes. Read this chapter to learn more about the other special characters used in C programs.

Parentheses ()

Parentheses are especially used to group one or more operands in an expression and control the order of operations in a statement.

A part of the expression embedded inside parentheses has a higher order of precedence.

Example

int a = 2, b = 3, c = 4;
int d = (a + b) * c; 

Braces { }

Braces are especially used to define blocks of code, such as function bodies and loops. They are also used to initialize arrays and struct variables.

Examples

Braces in function definition −

int add(int a, int b){
   int sum = a + b;
   return sum;
}

Braces in array initialization −

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

Braces in struct variable −

struct book {
   char title[10];
   double price;
   int pages;
};
struct book b1;
struct book b1 = {"Learn C", 675.50, 325};

Square Brackets [ ]

Square brackets are used to declare arrays and access elements of an array with the subscript index.

Example

For example, to define an array of integers and access its third element, you would use square brackets −

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

Asterisk (*)

Apart from its use as a multiplication operator, the asterisk symbol (*) is also used to declare a pointer variable and dereference it to obtain the value of the target variable.

Example

For example, to define a pointer to an integer and access the value it points to, you would use an asterisk −

int num = 10;
int *ptr = #
printf("*d", *ptr);

Ampersand (&)

The ampersand (&) symbol is used as the address-of operator. It returns the address of a variable.

Example

For example, to get the address of an integer variable, you would use an ampersand −

int num = 10;
int *ptr = #

Comma (,)

The comma is used as a separator between a statement or a function call.

Example

int a = 1, b = 2, c = 3;

Semicolon (;)

As a primary syntax rule in C, the semicolon indicates the end of a statement in a C program.

Example

printf("Hello, world!");

Dot (.)

The dot symbol (.) is used to access the members of a structure or a union.

Example

struct book b1 = {"Learn C", 675.50, 325};

printf("Title: %s\n", b1.title);
printf("Price: %lf\n", b1.price);
printf("No of Pages: %d\n", b1.pages);

Arrow (→)

The arrow symbol (→) is used to access the members of a structure or a union through a pointer.

Example

struct book b1 = {"Learn C", 675.50, 325};
struct book *strptr;
strptr = &b1;

printf("Title: %s\n", strptr->title);
printf("Price: %lf\n", strptr->price);
printf("No of Pages: %d\n", strptr->pages);
Advertisements