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 Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

string reverse using recursion

1803


What is the difference between the expression “++a” and “a++”?

642


Explain two-dimensional array.

619


How can you access memory located at a certain address?

659


Are pointers integers in c?

603






What is the difference between ++a and a++?

685


What is pointer and structure in c?

558


What are the functions to open and close the file in c language?

588


What is a stream?

639


Do pointers store the address of value or the actual value of a variable?

602


Are comments included during the compilation stage and placed in the EXE file as well?

663


Can we declare a function inside a function in c?

574


Who invented b language?

905


what are non standard function in c

1425


List a few unconditional control statement in c.

555