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 |
Explain what does the function toupper() do?
Is it fine to write void main () or main () in c?
The % symbol has a special use in a printf statement. Explain how would you place this character as part of the output on the screen?
without a terminator how can we print a message in a printf () function.
What is the difference between local variable and global variable in c?
What is the difference between specifying a constant variable like with constant keyword and #define it? i.e what is the difference between CONSTANT FLOAT A=1.25 and #define A 1.25
#include<stdio.h> int main() { int i=2; int j=++i + ++i + i++; printf("%d\n",i); printf("%d\n",j); }
We can draw a box in cprogram by using only one printf();& without using graphic.h header file?
Why cd or dvd are round why not square.
can i know the source code for reversing a linked list with out using a temporary variable?
Describe the order of precedence with regards to operators in C.
What is structure in c language?