Special Symbols in C

In C programming, special symbols are used to define and execute operations in the program and also These symbols have specific meanings and purposes, and understanding them is essential for writing and understanding C code.

What are the special symbols in C language?

Here are some of the most commonly used special symbols in C additionally along with examples of how they’re used:

  1. Parentheses: ()
  2. Braces: {}
  3. Square brackets: []
  4. Asterisk: *
  5. Ampersand: &
  6. Comma: ,
  7. Semicolon: ;
  8. Dot: .
  9. Arrow: ->

Parentheses: ()

Parentheses are especially used to group expressions and control the order of operations in a statement. For example, to add two numbers and then multiply the result by a third number, you would use parentheses to ensure that the addition is performed first:

int a = 2, b = 3, c = 4;
int result = (a + b) * c; // result = 20

Braces: {}

Braces are especially used to define blocks of code, such as function bodies and loops. For example, to define a function that adds two numbers, you would enclose the function body in braces:

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

Square brackets: []

Square brackets are especially used to define arrays and access elements of an array. For example, to define an array of integers and access its third element, you would use square brackets:

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

Asterisk: *

The asterisk is basically used to define pointers and access the value of a pointer. 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 = #
int value = *ptr; // value = 10

Ampersand: &

The ampersand is basically used to get the address of a variable. For example, to get the address of an integer variable, you would use an ampersand:

int num = 10;
int *ptr = # // ptr points to the address of num

Comma: ,

The comma is basically used to separate expressions in a statement or function call. For example, to define multiple variables in a single statement, you would use commas:

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

Semicolon: ;

The semicolon is basically used to terminate statement. It is also called as statement terminator that indicates the end of one logical entity.

int x = 1; // statement ends with a semicolon
printf("Hello, world!"); // statement ends with a semicolon

Dot: .

The dot symbol is used to access a member of a structure or union, and the example (e.g.) is:

struct Point {
    int x;
    int y;
} p = { 1, 2 };
int xCoordinate = p.x; // period used to access the x member of the structure

Arrow: ->

The Arrow symbol is used to used to access a member of a structure or union through a pointer, and the example (e.g.) is:

struct Point {
    int x;
    int y;
};
struct Point p = { 1, 2 };
struct Point *pPtr = &p;
int xCoordinate = pPtr->x; // arrow used to access the x member of the structure through a pointer

Conclusion on Special Symbols in C

By understanding their meanings and how they’re used, you can write and also read C code more effectively.

Categories C

1 thought on “Special Symbols in C”

Leave a Comment