What's the output of this C program?

bhulaxmi

bhulaxmi

@bhulaxmi-0IeKhk Oct 22, 2024
main()
{
int *ptr=(int*)malloc(sizeof(int));
*ptr=4;
printf("%d",(*ptr)+++*ptr++);

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Kaustubh Katdare

    Kaustubh Katdare

    @thebigk Aug 6, 2013

    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

    @rahul69-97fAOs Aug 10, 2013

    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

    @nayan-Dhpt4N Aug 10, 2013

    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.