conditional operators this operator is first checks your given condition, suppose your condition is not true then it will print some values if it is true it will print another value what we had been given in the program.
the syntax for conditional operators;
condition ? expr1 :expr 2;
this the syntax for conditional operators.
now see in this picture we already know that if the condition is true it will print expr1 value, suppose if it is wrong it will print expr 2 value.
now , we will see one program
|
#include<stdio.h>
#include<conio.h>
int
main()
{
int
a=10,b=5 ,conc;
conc=(a>b)?a:b;
printf("conc=%d",conc);
return 0;
}
|
OUTPUT:
in this program
, our condition is (a>b) which means (10>5). then, our condition is true so it prints a value.
these are the special operators.
comma :
comma this operator is used for separating two variable.
example,
int a=10 , a=5;
size of():
size of operator use for finding some data type size, how much of the bytes our data type has occupied.
same program for sizeof();
|
#include<stdio.h>
#include<conio.h>
int
main()
{
int a;
printf("sizeis:%d",sizeof(a));
return 0;
}
|
OUTPUT:
how it print byte 2.now we will see bytes,
bytes means it contains 8 bits values
int-2 bytes
float-4 bytes
char-1 bytes
these are the value of the byte.
pointer operator:
&→ it is used for specifying the address of the variable
*→ specifying the value of the variable
member selection operation:
.and → it is used to access the elements from the structure
bitwise operators which means it mainly manipulates the data at a bit level.it operation only on integer.it cannot apply for float and real numbers.
these are the bitwise operators.it is similar symbols to logical
operators..now we will see, the sample program using bitwise operators. when
we use this operator our operands is automatically change to bit values and
our operations process is completed next it will give output.
|
#include<stdio.h>
#include<conio.h>
int
main()
{
int
a=10.b=5;
int and,or,xor,not,ls,rs;
and=a&b;
or=a|b;
xor=a^b;
not=~b;
ls=a<<b;
rs=a>>b;
printf("and:%d",and);
printf("or:%d",or);
printf("xor:%d",xor);
printf("not:%d",not);
printf("ls:%d",ls);
printf("rs:%d",rs);
return 0;
}
|
output:
|
OUTPUT
|
|
and:0
or:15
xor:15
not:-6
ls: 320
rs:0
|
in this output, our operands values converted to a bit value. then we
already know and , or operator the same way this bitwise operator also
execute.
|
input A
|
input
B
|
XOR
|
NOT
|
|
0
|
0
|
0
|
1
|
|
0
|
1
|
1
|
1
|
|
1
|
0
|
1
|
0
|
|
1
|
1
|
0
|
0
|
this for understanding purpose.
now we will see one example,
a=10,b=5
10→1010(binary value of 10)
5→ 0101 (binary value of 5)
a&b= 1010 & 0101=0000
we already know our both input same it will give 1, suppose if
our values are not equal it will give 0.
No comments:
Post a Comment