Special Operator, C Programming Assignment Help

Assignment Help: >> Operators >> Special Operator, C Programming

Special Operator

 C supports some special operators such as comma operator, sizeof operator, pointer operators (& and *) and structure member selection operators (. and ->).

The comma operator:

The comma operator can be used to link the related expressions together. The comma operator separates the expressions.

c = (a = 10, b = 20, a + b);

The comma operator is often used for multiple variable initializations and for multiple assignments.

main ( )

{

                int x = 10, y = 20, t;

                t = x, x = y, y = t;

                printf("%d %d", x, y);

}

Comma operator is also used to separate variable names in the variable list in printf() and scanf() statements. We also use the comma operator to separate list of arguments or parameters in functions definitions and function calls.

 

The sizeof( ) operator

It returns the number of bytes the operand occupies in memory. The operand can be a constant, a variable or a data type qualifier.

main ( )

{

                int sum;

                printf("%d", sizeof(sum));

                printf("%d", sizeof(float));

                printf("%d", sizeof(234L));

                printf("%d", sizeof('A'));

}

Result: 2              4              4              1

The sizeof operator is generally used to determine the lengths of entities called arrays and structures when their size are not known to the programmer. It is also used to allocate memory space dynamically during execution of the program.

 

The pointer operators ('&' and '*')

The '&' is the "address of" operator that is used to obtain the address of a variable. We have used this operator in scanf( ) function to specify the addresses of variables in the variable address list. The '&' is also used to assign the address of a variable to a pointer. The '*' is the "value at address" operator and used to access the value of a variable through the pointer that holds the address of this variable.

 

The structure member access/selection operators ('.' and '->')

The "dot" operator is used to access the members of a structure through a structure variable. The "arrow" operator is used to access the member of a structure through a pointer to structure variable.

 

The parenthesis

The different operators have their specific precedence. Their precedence specifies that which operator's operation is to be performed first when various types of operators are involved in an equation. But we can alter the precedence of operators using the parentheses and can specify which part of the equation will be solved first. When there are parentheses within parentheses, the innermost parentheses are to be solved very first ((( ))).

When an equation involves multiple sets of parentheses, they are solved moving from left to right through the equation ( ) ( ) ( ).

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd