actually i tried a program like this

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a=8,b=3;
    a|=b;
    printf("%d",a);
    return 0;
}

i dont understand what happens here a|=b;
i have used || this which is used for or but i dont understand wat happens above

The || operator is the "logical or" operator. the | operator is the "bitwise OR" operator. The |= operator combines the bitwise OR operator and the assignment operator. Thus the code above is equivalent to the code below.

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a=8,b=3;
    int c = (a | b);
    printf("%d",c);
    return 0;
}

So it boils down to what does a | b do? First, write 8 and 3 in base 2. We have 8 pairs of bits. If either of them are 1, the result is a 1. Otherwise it is a 0.

EDIT -- For some reason, I am posting text and the editor thinks it is malformed code. I can't seem to post my textual write-up of bitwise operation and get the editor to understand that I am not posting code that needs to be parsed. Anyway, google for tutorials of "C Bitwise OR operator".

http://en.wikipedia.org/wiki/Bitwise_operation#OR

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.