C Functions Question:
Download Job Interview Questions and Answers PDF
Do you know what are bitwise shift operators in C Programming?
Answer:
The bitwise operators are used for shifting the bits of the first operand left or right. The number of shifts is specified by the second operator.
Expression << or >> number of shifts
Ex:
number<<3;/* number is an operand - shifts 3 bits towards left*/
number>>2; /* number is an operand – shifts 2 bits towards right*/
The variable number must be an integer value.
For leftward shifts, the right bits those are vacated are set to 0. For rightward shifts, the left bits those are vacated are filled with 0’s based on the type of the first operand after conversion.
If the value of ‘number’ is 5, the first statement in the above example results 40 and stored in the variable ‘number’.
If the value of ‘number’ is 5, the second statement in the above example results 0 (zero) and stored in the variable ‘number’.
Expression << or >> number of shifts
Ex:
number<<3;/* number is an operand - shifts 3 bits towards left*/
number>>2; /* number is an operand – shifts 2 bits towards right*/
The variable number must be an integer value.
For leftward shifts, the right bits those are vacated are set to 0. For rightward shifts, the left bits those are vacated are filled with 0’s based on the type of the first operand after conversion.
If the value of ‘number’ is 5, the first statement in the above example results 40 and stored in the variable ‘number’.
If the value of ‘number’ is 5, the second statement in the above example results 0 (zero) and stored in the variable ‘number’.
Download C Functions Interview Questions And Answers
PDF
Previous Question | Next Question |
Explain the advantages of using macro in C Language? | Tell me the use of bit field in C Language? |