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

program for reversing a selected line word by word when multiple lines are given without using strrev

0 Answers   IBM,


What is a #include preprocessor?

0 Answers  


What is the modulus operator?

0 Answers  


What is pointer and structure in c?

0 Answers  


What is adt in c programming?

0 Answers  






what is difference between array of characters and string

18 Answers   Accenture, Nest,


logic for x=y^n

1 Answers   Delphi,


suppose we use switch statement and we intilize years name using enum statement like(jan,feb,mar,------dec) we take integer value as an input .question is that the month which we analyz is from 0 to 11 bt if i enter 12 than how he again starts from begning and print jan

1 Answers  


the factorial of non-negative integer n is written n! and is defined as follows: n!=n*(n-1)*(n-2)........1(for values of n greater than or equal to 1 and n!=1(for n=0) Perform the following 1.write a c program that reads a non-negative integer and computes and prints its factorial. 2. write a C program that estimates the value of the mathematical constant e by using the formula: e=1+1/!+1/2!+1/3!+.... 3. write a c program the computes the value ex by using the formula ex=1+x/1!+xsquare/2!+xcube/3!+....

2 Answers   Ignou,


Suppose we have a table name EMP as below. We want to perform a operation in which, I want to change name ‘SMITH’ from as ‘SMITH JAIN’. Also I want to change the name of the column from ENAME to E_NAME. EMPNO ENAME JOB MGR HIREDATE SAL 7369 SMITH Coder 7902 17-DEC-80 800 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 7521 WARD SALESMAN 7698 22-FEB-81 1250

0 Answers  


Describe wild pointers in c?

0 Answers  


What is ponter?

0 Answers   TCS,


Categories