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)



write a program to swap bits in a character and return the value prototype of function char fun (c..

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

Post New Answer

More C Interview Questions

What is the use of function overloading in C?

0 Answers   Ittiam Systems,


What are structure types in C?

0 Answers  


Can we initialize extern variable in c?

0 Answers  


how to print 212 as Twohundreds twelve plz provide me ans soon

1 Answers  


write a c program to calculate the income tax of the employees in an organization where the conditions are given as. (I.T. = 0 if income <100000 I.T = 10% if income _< 200000 it = 20% if income >_ 200000)

7 Answers   Consultancy, DBU, FD, JK Associates, Kobe, Satyam,






what is the diference between pointer to the function and function to the pointer?

2 Answers   Infosys,


why Language C is plateform dependent

3 Answers   Siemens, Wipro,


What is pointer to pointer in c?

0 Answers  


What is void main ()?

0 Answers  


What is pass by reference in functions?

0 Answers  


Write a code to remove duplicates in a string.

0 Answers   Expedia,


52.write a “Hello World” program in “c” without using a semicolon? 53.Give a method to count the number of ones in a 32 bit number? 54.write a program that print itself even if the source file is deleted? 55.Given an unsigned integer, find if the number is power of 2?

25 Answers   Datamatics, Solartis, TCS, ThinkBox, Trine,


Categories