COMMA AND CONDITIONAL OPERATOR :
1)comma operator( , ):
The comma operator is used to separate two are more expressions.
For Example :
a=2,b=4,c=a+b;
program :
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
printf("Addition=%d \n subtraction=%d",2+3,5+4);
getch();
}
OUTPUT:
Addition=5
subtraction= 1
2)conditional operator (?)(Ternary operator):
The conditional operator contains a condition followed by two statements or values.If the condition is true the first statement is executed otherwise the second statement.
It is also called as ternary operator...
SYNTAX :
condition ? (expression 1) : (expression 2) ;
program :
#include<stdio.h>
#include<conio.h>
main()
{
clrscr():
printf("Result=%d",2==3?4:5);
getch();
}
OUTPUT:
Result=5
1)comma operator( , ):
The comma operator is used to separate two are more expressions.
For Example :
a=2,b=4,c=a+b;
program :
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
printf("Addition=%d \n subtraction=%d",2+3,5+4);
getch();
}
OUTPUT:
Addition=5
subtraction= 1
2)conditional operator (?)(Ternary operator):
The conditional operator contains a condition followed by two statements or values.If the condition is true the first statement is executed otherwise the second statement.
It is also called as ternary operator...
SYNTAX :
condition ? (expression 1) : (expression 2) ;
program :
#include<stdio.h>
#include<conio.h>
main()
{
clrscr():
printf("Result=%d",2==3?4:5);
getch();
}
OUTPUT:
Result=5