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 context in c?
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.
#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);}
can we execute the program with the object file
What is the difference between i++ and i+1 ?(in terms of memory)
What is the use of header?
Write a program to reverse a given number in c?
What is the return type of sizeof?
Bit swapping
What is a char in c?
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
write a 'c' program to sum the number of integer values