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

Explain with the aid of an example why arrays of structures don’t provide an efficient representation when it comes to adding and deleting records internal to the array.

2657


What is this pointer in c plus plus?

600


What are the 5 data types?

607


Why do we use int main instead of void main in c?

626


What is the heap in c?

647






what is reason of your company position's in india no. 1.

1779


What is difference between scanf and gets?

616


what are the 10 different models of writing an addition program in C language?

1443


Can we access array using pointer in c language?

650


What is the purpose of clrscr () printf () and getch ()?

600


A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.

1256


What is #define in c?

624


The number of measuring units from an arbitarary starting point in a record,area,or control block to some other point a) recording pointer b) offset c) branching d) none

716


Is null always equal to 0(zero)?

589


Is that possible to add pointers to each other?

907