1. Home >
  2. Apps >
  3. Groups >

What's the output of this C program?

Question asked by bhulaxmi in #Coffee Room on Aug 7, 2013
bhulaxmi
bhulaxmi 路 Aug 7, 2013
Rank E2 - BEGINNER
main()
{
int *ptr=(int*)malloc(sizeof(int));
*ptr=4;
printf("%d",(*ptr)+++*ptr++); Posted in: #Coffee Room
Kaustubh Katdare
Kaustubh Katdare 路 Aug 7, 2013
Rank A1 - PRO
I added a better title to the question. I think you're asking about the output of this program, right? Why not just run it and check for yourself?
rahul69
rahul69 路 Aug 10, 2013
Rank B2 - LEADER
bhulaxmi
main()
{
int *ptr=(int*)malloc(sizeof(int));
*ptr=4;
printf("%d",(*ptr)+++*ptr++);
It will print 8,
After the printf statement is executed, the pointer ptr had move to next address, and the value at earlier address is incremented (ie, becomes 5), if u still got any doubts, plz do share 馃榾
Nayan Goenka
Nayan Goenka 路 Aug 10, 2013
Rank B1 - LEADER
I think this program will generate output 10. Still working on it. Will give a definite output once I execute it on my side. But I guess you already know that this function is not just complete program. It needs prototypes or header files to run.
Divisha Madupalli
Divisha Madupalli 路 Feb 12, 2020
Rank C2 - EXPERT

The output is 9. After the print statement is executed, the pointer ptr had moved to the next address, and the value at earlier address is incremented then it is again done it becomes to the next one and it goes on.

bill yorke
bill yorke 路 Feb 13, 2020
Rank C2 - EXPERT

Ok, your code would certainly give the compilation syntax error simply because I'm never announced. Seeing this error as normal casual typing error;

p5eE-1581617287966.jpg

You must log-in or sign-up to reply to this post.

Click to Log-In or Sign-Up