Question

In: Computer Science

In C, is "&" a operator or punctuator? (According to the info found online, I am...

In C, is "&" a operator or punctuator? (According to the info found online, I am still confused)

Solutions

Expert Solution

& is a bit wise operator, where as && is a logical operator

& works on individual bits and perform bit-by-bit operation, where as && works on expressions, if both the operands are non-zero, then the condition becomes true.

For example - if we want to check a variable 'x' value is between 1 and 10 we will do it using the && operator as

if(1<=x && x<=10) ; here there are two expression 1<=x and x<=10 && computes the logical AND operation.

Now coming to & operator , lets understand with an example -

Assume A = 60 and B = 13 in binary format, they will be as follows −

A = 0011 1100 ( this is the binary form of the number 60)

B = 0000 1101 ( this is the binary form of the number 13)

---------------------

A&B = ( it does bit by bit AND operation) if both the bits at the same index is 1 then the resultant bit will be 1 otherwise its always 0

so A&B will result in 0000 1100 which is equivalent to the number 12 in decimal.

so,

int A = 60;

int B = 13;

int C = A&B; will result in 12 being assigned to the variable C

======================================================================

Hope this clarifies all confusion. Let me know for any doubts.


Related Solutions

So I am suppose to write a short essayon this and I found some things online,...
So I am suppose to write a short essayon this and I found some things online, but I am having trouble putting it into my own words. Can I have help with this please and thank you! Macropoland is currently experiencing a recession--consumption and investment are very sluggish, and unemployment is quite high at 9%. Currently, inflation is very low at 0.4% (the historical average rate of inflation is about 2%). The Macropolish President has just hired you as her...
Assume that Animal is a class that has method void info() that prints "I am an...
Assume that Animal is a class that has method void info() that prints "I am an animal". Classes Bird and Reptile both extend class Animal, and both override method info(). Class Bird implements method info to print "I am a bird", and class Reptile implements method info to print "I am a reptile ". Determine the outcome printed by the following lines of code. Animal animal = new Animal(); animal.info(); //OUTCOME: animal = new Reptile() animal.info(); //OUTCOME: animal = new...
I have a urinary analysis that I am working on patient info: 12 yrs old, losing...
I have a urinary analysis that I am working on patient info: 12 yrs old, losing weight, always hungry, getting up twice to use the bathroom Physical exam: respirations: 15/min BP: 125/80mmHg Pulse: 75/min temp:37C BLood values: pH:735 WBC: 8200/mm blood glucose: 260 mg/dL albumin: 4.0g/L Urinalysis pH: 5.0 glucose: 1,00mg/dL ketone: large specifc gravity: 1.006 leukocytes, nitrite, protein: negative color: light yellow, clear Question: why is this patient always hungry if she is eating well? explain anatomy and physiology
I am always found in pairs, sometimes the pair appear as short chains. I am protected...
I am always found in pairs, sometimes the pair appear as short chains. I am protected by a coat that can swell in the presence of specific antiserum. I am not exactly spherical but more lanceolate with sides facing each other being more rounded. I can't survive on simple nutrition and presence of blood boosts my growth. I can lyse blood but only partially. I grow better in a candle jar. As I grow old, I become suicidal. My colonies...
I am taking, environmental geology, business law, algebra I, and info technology concepts and business software....
I am taking, environmental geology, business law, algebra I, and info technology concepts and business software. Do you cover any of these topics?
I am supposed to be looking at the OMIM online database under hypercholesterolemia, and I cannot...
I am supposed to be looking at the OMIM online database under hypercholesterolemia, and I cannot find the answer to this question on their webpage. What is the relationship between the LDL receptor and hepatitis C virus?
Syntax error in C. I am not familiar with C at all and I keep getting...
Syntax error in C. I am not familiar with C at all and I keep getting this one error "c error expected identifier or '(' before } token" Please show me where I made the error. The error is said to be on the very last line, so the very last bracket #include #include #include #include   int main(int argc, char*_argv[]) {     int input;     if (argc < 2)     {         input = promptUserInput();     }     else     {         input = (int)strtol(_argv[1],NULL, 10);     }     printResult(input);...
This is the situation I am a young entrepreneur looking to open a new online business....
This is the situation I am a young entrepreneur looking to open a new online business. 1) Identify your business concept and how you will effectively plan and manage your new business profile in a dynamic on-line environment.   2) How will you manage your intellectual property? Define your required web presence (if applicable).   
I am trying to isolate the proteins found in the blood of Alzheimer's patients with the...
I am trying to isolate the proteins found in the blood of Alzheimer's patients with the hope of finding a biomarker that can potentially indicate the early onset of the disease and was wondering how I could do so? I know centrifugation is an option but how would I go about doing it specifically? -my end goal is to simply isolate the proteins from the blood samples in order to run ITRAQ analysis on them and MS analysis after
How can I compare the weekly performance of 2 stocks online? I am looking for CNI...
How can I compare the weekly performance of 2 stocks online? I am looking for CNI ( canadian national rail) vs CP ( Canadian pacific)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT