main()
{
unsigned int k = 987 , i = 0;
char trans[10];
do {
trans[i++] =(char) (k%16 > 9 ? k%16 - 10 + 'a' : '\0' );
} while(k /= 16);
printf("%s\n", trans);
}

Answers were Sorted based on User's Feedback



main() { unsigned int k = 987 , i = 0; char trans[10]; do { trans[i++] =(char) (k%16 > 9 ? k..

Answer / ashok kumar

answer is : bd
Explanation:
trans[i++]= (char) (k%16>9?k%16-10+'a':'');// 1.(char) is typecasting it convert decimal value into character. 2. k=987%16 is greater than 9 means first condition run else second condition as of this k%16 remainder is 11 so it is greater than 9, then first condition will run.
3. 11-10+'a' = 1+'a' = 1+97 is ascii value for a = 98 is ascii value for b so it print.
4. check while condition k=k/16 = 61, so its true value again it will run do the same process but second time the k value will be 61 because it changes in while condition then after second time condition fail you will get bd is answer
while(k/=16);
printf("%s",trans);

Is This Answer Correct ?    16 Yes 0 No

main() { unsigned int k = 987 , i = 0; char trans[10]; do { trans[i++] =(char) (k%16 > 9 ? k..

Answer / deepthisivan

bd

Is This Answer Correct ?    13 Yes 0 No

main() { unsigned int k = 987 , i = 0; char trans[10]; do { trans[i++] =(char) (k%16 > 9 ? k..

Answer / lakshman

first case k=987, i=0.
trans[i++]=(char)(k%16>9?k%16-10+'a':''); means
trans [0]=char(987%16(=61)>9)condition is true so k%16-10+'a' value is print. that value is equal to 61-10|+(ascii value of a, that is equal to 97) so finally we get 98 and that is equal to b,
second case k=61, i=1 this will gives d
third case k=3, i=2 this gives null character.
the final answer is bd

Is This Answer Correct ?    1 Yes 0 No

main() { unsigned int k = 987 , i = 0; char trans[10]; do { trans[i++] =(char) (k%16 > 9 ? k..

Answer / dishank

deepthisivan can u plz elaborate.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

Write a simple program to find the size of different basic data types in C.

3 Answers  


who will call your main function in c under linux?

2 Answers  


get any number as input except 1 and the output will be 1.without using operators,expressions,array,structure.don't print 1 in printf statement

3 Answers  


What are unions in c?

0 Answers  


Explain continue keyword in c

0 Answers  






How can I call a function with an argument list built up at run time?

0 Answers  


what are the stoge class in C and tel the scope and life time of it?

2 Answers   Tech Mahindra,


How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?

0 Answers  


what is the self-referential structure?

1 Answers  


How many types of functions are there in c?

0 Answers  


How to write a multi-statement macro?

0 Answers  


how to convert an char array to decimal array

4 Answers  


Categories