Technologies

C

C Language Special Operator
(adsbygoogle = window.adsbygoogle || []).push({});
# Special Operators :

# Comma Operator :

**Applications :**
# SizeOf Operator :

# Member Selection Operator :

(adsbygoogle = window.adsbygoogle || []).push({});
(adsbygoogle = window.adsbygoogle || []).push({});

CLanguage

Friday, 31 Mar 2017

389

0

0

C Supprots the following three types of special operators.

- Comma Operator
- SizeOf Operator
- Member Selection Operator

comma is a binary operator whereas sizeof is a unary operator.

comma operators generally used in loops.

A sizeof operator is normally used to determine the lengths of arrays and structures.

The comma operator (,) can be used to link the related expressions together. A comma-linked list of expressions are evaluated left to right and the value of right most expression is the value of the combined expression.

Syntax : exp m = (exp 1, exp 2, .... exp n)

The comma operator has the lowest priority among all the operators available in C.

Comma operator follows right to left associativity.

Comma operator is a binary operator.

**Example : value = (x = 10, y = 5, x + y );**

First assigns the value 10 to x, then assigns 5 to y, and finally assigns 15(i.e, 10 + 5) to value. Since comma operator has the lowest precedence of all operators, the pair of parentheses are necessary.

In for loops : for(n = 1, m = 10, n <= m; n++, m++)

In while loops : while( c = getchar(), != '10')

Exchanging values : t = x, x = y, y = t;

In while loops : while( c = getchar(), != '10')

Exchanging values : t = x, x = y, y = t;

The SizeOf is a compile time operator and when used with an operand, it returns the number of bytes that the operand occupies. The operand may be a variable, a contant or a data type qualifier.

Syntax : sizeOf(opeand)

**Examples : **

1. y = sizeOf(int); Here value of y will be 2 bytes.

2. z = sizeOf(a); Here value of z depends on data type of a

2. z = sizeOf(a); Here value of z depends on data type of a

A sizeOf operator is normally used to determine the lengths of arrays and structures, when their sizes are not known to the programmer. It is also used to allocate memory space dynamically to variables during execution of a program.

These operators are used to access members of structures and unions. They are represented by dot(.) and arrow().

**Examples : **

1. var.member1; /* when var is a structure variable */

2. var member2; /* when var is a pointer to structure variable */

2. var member2; /* when var is a pointer to structure variable */

Post Article

Upload Youtube Video

CLanguage

Friday, 31 Mar 2017

389

0

0

Popular Post

- Write an algorithm and draw the flowchart to find the largest number among the three numbers?
- Write an algorithm an draw flowchart to find factorial of a number?
- Write an algorithm and draw the flowchart to find whether a given number is even or odd?
- Write an algorithm and draw the flowchart to Swap two integers?
- Write an algorithm an draw the flowchart to compute the average of the three numbers?
- Write an algorithm and draw the flowchart to find the largest number amoug two numbers?
- write a c program to swap two numbers
- How to write a algorithm?
- What is mean by Operator Precedence and Associativity in C Language?
- C Languages Relational Operators

All contents are copyright of their authors