How can I get Single byte from 'int' type variable? Can we
alter single bit or multiple bits in int type variable? if so,
How?
Answer Posted / vignesh1988i
we know that integer allocates 2 bytes of memory.
to get a single byte we must type cast the integer to character using pointers.
why because,when we take int i=10;,the binary representation for 10 is 1010 or in 8 bits it can be 0000 1010.
so in memory 2 bytes will be allocated as the whole for int.
let us consider: binary 10 address (2bytes)
0000 65534
0010 65535
in the memory according to the bytes prority the binary numbers will get stored.
so , our task is to take only one byte from int.
int i=10,*j;
j=&i;
printf('%d\n",(char*)j); // type casting of ptr varables
now. in the above ex. and according to the preceeded coding it will print 0 as the output ,which is the output from only one byte of memory location (65534).
any corrections , pl. notify me
thank u
| Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
show how link list can be used to repersent the following polynomial i) 5x+2
Distinguish between actual and formal arguments.
main() { int i = 10; printf(" %d %d %d ", ++i, i++, ++i); }
How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same
What is auto keyword in c?
What is the use of a semicolon (;) at the end of every program statement?
What are the advantages of using Unions?
When c language was developed?
Should I learn c before c++?
Explain what could possibly be the problem if a valid function name such as tolower() is being reported by the c compiler as undefined?
What is difference between static and global variable in c?
What is the function of this pointer?
Explain how do you determine a file’s attributes?
What is getch () for?
Is c still relevant?