write a program to swap bits in a character and return the value
prototype of function
char fun (char a, charb flag c)
where fun returns a char, char a is a the value char b is
the bit to be changed and flag c is the bit value
for eg: x=fun(45,7,0)
since 45 is 0010 0101
and ow x should contain the value 65 (0110 0101)
Answer / abdur rab
#include <stdio.h>
char fun ( char a, char b, int flag )
{
if ( flag ) return ( a |= ( flag << ( (int) b -
1 ) ) );
return ( a &= ~( 1 << ( (int) b - 1 ) ) );
}
int main ( int argc, char* argv [] )
{
char a = 45;
printf ( "\n Before change :%d", (int) a );
printf ( "\n After change :%d", (int) fun ( a,
(char) 7, 1 ) );
return ( 0 );
}
| Is This Answer Correct ? | 1 Yes | 9 No |
What is meant by int main ()?
Why #include is used in c language?
Is there any algorithm to search a string in link list in the minimum time?(please do not suggest the usual method of traversing the link list)
4)What would be the output? main() { int num=425; pf("%d",pf("%d",num)); } a)Comp error b)4425 c)4253 d)3435 e)none
Define function ?Explain about arguments?
2 Answers Geometric Software, Infosys,
What does typeof return in c?
Do you know pointer in c?
How can I allocate arrays or structures bigger than 64K?
Can the curly brackets { } be used to enclose a single line of code?
Can you assign a different address to an array tag?
What are disadvantages of C language.
Meaning of () in c