Operator in C

Operator in C

Operator in C:-

Operator in C :- 1) Precedence and associativity of an operator only implemented if it is represented in INFIX notation.

Precedence decides which operation will be performed first.

Associativity decides the order of evaluation ( left to right or right to left) if more than one operator enjoy the same precedence.

The operator which requires three operands that are called ternary operator.

? : is a conditional ternary operator.

Associativity of a comma ( , ) operator is left to right.

# is a string forming operator that convert a non-string data to  string and used only in preprocessor directives.

There is no operator in C to calculate the rise of a number.

Bitwise operators only work in integral type but do not work in float type.

Return value of relational and logical operators is 0 or 1.

x++, Here Microprocessor does both read and write operation.

 

1st highest precedence:-

()

[]                                                Left to Right

.

->

2nd highest precedence:-

++

!                                                  Right to Left

*

Size of()

Type

3rd highest precedence:-

*

/                                                Left to Right

%

4th highest precedence:-

+

–                                                Left to Right

5th highest precedence:-

>>

<<                                                Left to Right

6th highest precedence:-

>

<

>=                                                Left to Right

<=

7th highest precedence:-

==

!=                                                Left to Right

8th highest precedence:-

Bitwise  &

9th highest precedence:-

^                                                Left to Right

10th highest precedence:-

|                                                Left to Right

11th highest precedence:-

||                                                Left to Right

12th highest precedence:-

&& (Logical AND)                  Left to Right

13th highest precedence:-

? (conditional)                         Right to Left

14th highest precedence:-

+=

-=

/=

*=

>>=                                             Right to Left

<<=

&=

^=

|=

=

15th highest precedence:-

,                                                     Left to Right

 

It has no precedence and n

# string forming

## merging

 

Type of OperatorSymbolic representation
Arithmetic operators+, -, *, /, %
Relational operators>, <, ==, >=, <=, !=
Logical operators&&, ||, !=
Increment and decrement operator++ and —
Assignment operator=
Bitwise operator&, |, ^, >>, <<, ~
Comma operator,
Conditional operator?:

 

 

Example:-

SLNOQuestionsOutput
1
 main()

{

int x;

int a=5;

x= 30 || –a;

printf(“%d”,a);

}

5
2
main()

{

int a=5,b=5,c=5;

if(a==b==c)

printf(“delhi  challo”);

else

printf(“do or die”);

}

do or die
3
main()

{

int a=8,x;

x=++a + ++a + ++a;

printf(“%d %d”,x,a);

}

31    11
4main()

{

int k=1==8>3;

printf(“%d”,k);

}

1
5 main()

{

int i=-1, j=-1, k=0,  l=2, m;

m = i++ && j++ && k++ || l++;

printf(“%d%d%d%d%d”,i, j, k, l, m);

}

0 0 1 3 1
6int main()

{

int x = 10, y = 20;

if(!(!x) && x)

printf(“x = %d\n”, x);

else

printf(“y = %d\n”, y);

return 0;

}

 

X=10
7main()

{

int y,x=10;

y = x++ <<2 <=5;

printf(“%d”,y);

}

0
8main()

{

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

int i=1;

int k=5*x[–i] + 5*9+(8/i);

printf(“%d”,k);

}

Divide by zero (floating point exception)

 

Also Read:- What is C

Also Read:- Datatype in C

 

basicittopic

basicittopic

A Computer Science Study for IT students and people of IT community

Leave a Reply