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 a structure in c language. how to initialise a structure in c?
How do you determine the length of a string value that was stored in a variable?
Not all reserved words are written in lowercase. TRUE or FALSE?
main() { printf("\n %d %d %d",sizeof('3'),sizeof("3"),sizeof(3)); } wat is the o/p and how?
What do you mean by a sequential access file?
if p is a string contained in a string?
what is the advantage of software development
Define Spanning-Tree Protocol (STP)
What is use of #include in c?
What oops means?
Can you define which header file to include at compile time?
What is const and volatile in c?