Programming with C

⌘K
  1. Home
  2. Docs
  3. Programming with C
  4. Basics of C Programming
  5. Expressions
  6. Miscellaneous operators

Miscellaneous operators

Other operators in C are,

  • Functional call operator ( )
  • Array subscript operator [ ]
  • Member select operator
    • Direct member access operator .(dot operator)
    • Indirect member access operator (-> arrow operator)
  • Indirection operator (*)
  • Conditional operator (?:)
  • Comma operator
  • Sizeof operator
  • Address of operator (&)

Conditional Operator

  • General form of conditional operator is E1?E2:E3
  • Where E1,E2 and E3 are sub expressions
  • The sub-expression E1 is evaluated first.
  • If it evaluates to a non-zero value (true) then E2 is evaluated and E3 is ignored.
  • If E1 evaluates to zero (i.e., false), then E3 is evaluated and E2 is ignored
?:

Comma Operator

  • Not every instance of comma symbol is a comma operator
  • Comma separating arguments in function call or in declaration / definition statements are termed to be comma separators
  • The comma operator guarantees left to right evaluation
  • In expression E1,E2,E3,…,En are evaluated in left to right order
  • The result and type of evaluation of the overall expression is the value and type of the evaluation of the rightmost sub-expression i.e.En
  • The comma operator has least precedence
,

Size of Operator

  • Sizeof operator is used to determine size in bytes
  • General form:
    • sizeof(expression)
    • sizeof expression
    • sizeof(typename)
  • The type of result of evaluation is int
  • The operand of sizeof operator is not evaluated
sizeof

Address-of Operator

  • Address-of operator must appear toward the left side of its operand
  • Syntax: &operand
  • It cannot be applied to constants, expressions, and to variables stored in register class
&

Example

Illustration of comma operator

#include<stdio.h>
int main()
{
	int a,b;
	a=1,2,3,4,5;
	b=(1,2,3,4,5);
	printf("a=%d,b=%d",a,b);
	return 0;
}

Output

a=1,b=5

Illustration of size of operator

#include<stdio.h>
int main()
{
	int a=1,b,c;
	b=sizeof(++a);
	c=sizeof(2+3);
	printf("a=%d,b=%d,c=%d",a,b,c);
	return 0;
}

Output

a=1,b=2,c=2

Views: 2

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments