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
Explain what is gets() function?
What are the advantages of using new operator as compared to the function malloc ()?
What the different types of arrays in c?
What is sizeof int in c?
What is quick sort in c?
Explain the difference between structs and unions in c?
Can math operations be performed on a void pointer?
Differentiate between null and void pointers.
Explain heap and queue.
Design a program which assigns values to the array temperature. The program should then display the array with appropriate column and row headings.
write a program to input 10 strings and compare without using strcmp() function. If the character of one string matches with the characters of another string , sort them and make it a single string ??? example:- str1="Aakash" st2="Himanshu" str="Uday" output:- Aakashimanshuday (please post the answer as quickly as possible)
any C program contains only one function, it must be a) void () b) main () c) message () d) abc ()
Explain how do you generate random numbers in c?
What are the types of bitwise operator?
Is a pointer a kind of array?