Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

what is event driven software and what is procedural driven software?

2508


Explain what are run-time errors?

1037


What are types of structure?

1065


Write a C program on Centralized OLTP, Decentralized OLTP using locking mechanism, Semaphore using locking mechanism, Shared memory, message queues, channel of communication, sockets and a simple program on Saving bank application program using OLTP in IPC?

2625


An expression to whose value an operater is applied a) operand b) variable c) constant d) all of the above

1104


What does c mean?

974


hi, which software companys will take,if d candidate's % is jst 55%?

2047


What is optimization in c?

948


Linked list is a Linear or non linear explain if linear how it working as a non linear data structures

2121


What is a ternary operator in c?

1058


How can I find the modification date and time of a file?

1028


How do you define CONSTANT in C?

1212


Why should I prototype a function?

1120


which is an algorithm for sorting in a growing Lexicographic order

1747


what are enumerations in C

1107