what would be the output of the following program?
main()
{
int k = 123;
char *ptr;
ptr = &k;
printf("%d",*ptr);
}

Answers were Sorted based on User's Feedback



what would be the output of the following program? main() { int k = 123; char *ptr; ptr = &..

Answer / 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

what would be the output of the following program? main() { int k = 123; char *ptr; ptr = &..

Answer / vadivelt

Hi Srsabariselvan,
If you are not very clear on the answer, please avoid to post
it. Because your answer seems to be misguiding the persons
who are very new to this question(probly pointers).

Who said that a pointer has to hold the address of same
datatype????.... a pointer of any datatype can hold the
address of any other data types(only it is enough to have
proper typecasting).

There will not be a compilation error. But most of the time
loss of data may be there(ie., when a bigger size of
datatype is typecasted to smaller eg: int* is typecasted to
char*). Please read the answer #1 for clear understanding.

Still if you are not clear on the concept, Copy the code
and execute it in ur compiler and analys the output.

Is This Answer Correct ?    2 Yes 1 No

what would be the output of the following program? main() { int k = 123; char *ptr; ptr = &..

Answer / srsabariselvan

The program results in compilation error.

NOTE: a pointer can stores the address of same data type.
it can't store the address of another data type.
i.e.,
character pointer can stores the address of character data.
it can't store the address of integer data.

Is This Answer Correct ?    2 Yes 2 No

what would be the output of the following program? main() { int k = 123; char *ptr; ptr = &..

Answer / ankush

i also have a compilation error.....
""Cannot convert 'int_ss*' to 'char*' in function main()""
why its so....???
i want some answer.....
is my compiler wrong....

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

write a c programme for add of two numbers with out use of arthematic operators

2 Answers  


What is maximum size of array in c?

0 Answers  


Explain how can I manipulate strings of multibyte characters?

0 Answers  


main() { int x=10,y=15; x=x++; y=++y; printf("%d %d\n",x,y); } output??

19 Answers   EBS, Ramco, Sangwin, TCS,


write a program to display reverse of a number using for loop?

14 Answers  






What are # preprocessor operator in c?

0 Answers  


What is the difference between arrays and pointers?

0 Answers  


What is the difference between local variable and global variable in c?

0 Answers  


how can i write a program that prints out a box such that whenever i press any key8(coordinate number) on the keyboard, the box moves.

0 Answers  


What is difference between structure and union in c programming?

0 Answers  


There are N egg baskets and the number of eggs in each basket is a known quantity. Two players take turns to remove these eggs from the baskets. On each turn, a player must remove at least one egg, and may remove any number of eggs provided they all belong to the same basket. The player picking the last egg(s) wins the game. If you are allowed to decide who is going to start first, what mathematical function would you use to decide so that you end up on the winning side?

1 Answers   Hathway,


What would happen to X in this expression: X += 15; (assuming the value of X is 5)

0 Answers  


Categories