Relational operator, Conditional operator, Comma operator and Sizeof operator in C program | Coding classpoint

4.Relational Operator 


It is use to compared value of two expressions depending on their relation. Expression that contain relational operator is called relational expression. Here the value is assign according to true or false value. 

a.(a>=b) || (b>20) 

b.(b>a) && (e>b) 

c. 0(b!=7)

5. Conditional Operator

It sometimes called as ternary operator. Since it required three expressions as operand and it is represented as (? , :).

SYNTAX

exp1 ? exp2 :exp3 
Here exp1 is first evaluated. It is true then value return will be exp2 . If false then exp3. 

EXAMPLE 

void main() 
{
 int a=10, b=2 
 int s= (a>b) ? a:b; 
 printf(“value is:%d”); 
 } 

Output: Value is:10

6. Comma Operator

Comma operator is use to permit different expression to be appear in a situation where only one expression would be used. All the expression are separator by comma and are evaluated from left to right. 

EXAMPLE 

int i, j, k, l; 
for(i=1,j=2;i<=5;j<=10;i++;j++)

7. Sizeof Operator

Size of operator is a Unary operator, which gives size of operand in terms of byte that occupied in the memory. An operand may be variable, constant or data type qualifier. 

Generally it is used make portable program(program that can be run on different machine) . It determines the length of entities, arrays and structures when their size are not known to the programmer. It is also use to allocate size of memory dynamically during execution of the program.

EXAMPLE 

main( ) 
int sum; float f; 
printf( "%d%d" ,size of(f), size of (sum) ); 
printf("%d%d", size of(235 L), size of(A)); 

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.