what would be the output of the following program?
main()
{
int k = 123;
char *ptr;
ptr = &k;
printf("%d",*ptr);
}
Answer Posted / vadivelt
Output would be 123.
Since, the character pointer can hold the values
0 - 255(if it is unsigned) or -128 to 127 (if it is signed), we
will get value of k as result.
But if the k value is k > 255 and the pointer is unsigned,
or if the k value is k > -129 and k < 128 and the pointer
is signed then only lower 1 byte of k would be the result.
Remaining data will be lost.
| Is This Answer Correct ? | 4 Yes | 0 No |
Post New Answer View All Answers
What is cohesion and coupling in c?
Explain what is #line used for?
When should the register modifier be used? Does it really help?
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn't too pleased and asked me to give a solution which didn't need the array ].
What is bubble sort technique in c?
How can I write data files which can be read on other machines with different word size, byte order, or floating point formats?
What do the functions atoi(), itoa() and gcvt() do?
Explain the array representation of a binary tree in C.
Explain about C function prototype?
What is the use of a conditional inclusion statement in C?
Describe the header file and its usage in c programming?
Do you know the difference between exit() and _exit() function in c?
Hai what is the different types of versions and their differences
Is c high or low level?
What 'lex' does?