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


Please Help Members By Posting Answers For Below Questions

find the sum of two matrices and WAP for it.

628


What language is lisp written in?

613


Explain how does free() know explain how much memory to release?

569


Write a program to input the price of 1 burger and the number of burgers eaten by a group of friends .print the total amount to be paid by the group?

574


What is the difference between arrays and pointers?

631






what are the advanced features of functions a) function declaration and prototypes b) calling functions by value or by reference c) recursion d) all the above

667


What is the difference between malloc() and calloc()?

613


What does c mean before a date?

585


Explain how can you avoid including a header more than once?

595


Explain the difference between malloc() and calloc() function?

596


What is call by reference in functions?

560


How are 16- and 32-bit numbers stored?

719


struct screen_pos{ int row, col } ;move_right(cursor)struct screen_pos *cursor;{ cursor.col++; } /* This statementhas a syntax error */What is the correct statement a) cursor.col = cursor.col + 1; b) col.cursor++; c) *cursor.col++; d) pointer

762


can anyone please tell about the nested interrupts?

1674


What is the difference between union and structure in c?

569