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 context in c?

0 Answers  


You are to write your own versions of strcpy() and strlen (). Call them mystrcpy() and mystrlen(). Write them first as code within main(), not as functions, then, convert them to functions. You will pass two arrays to the function in the case of mystrcpy(), the source and target array.

0 Answers  


#define min((a),(b)) ((a)<(b))?(a):(b) main() { int i=0,a[20],*ptr; ptr=a; while(min(ptr++,&a[9])<&a[8]) i=i+1; printf("i=%d\n",i);}

3 Answers  


can we execute the program with the object file

1 Answers  


What is the difference between i++ and i+1 ?(in terms of memory)

3 Answers   HCL,






What is the use of header?

0 Answers  


Write a program to reverse a given number in c?

0 Answers  


What is the return type of sizeof?

0 Answers  


Bit swapping

2 Answers  


What is a char in c?

0 Answers  


What is the output of the following progarm? #include<stdio.h> main( ) { int x,y=10; x=4; y=fact(x); printf(ā€œ%d\nā€,y); } unsigned int fact(int x) { return(x*fact(x-1)); } A. 24 B. 10 C. 4 D. none

2 Answers  


write a 'c' program to sum the number of integer values

8 Answers  


Categories