Thread: Pelles C and DEV C++ Giving Different Output For Same Code!

  1. #1
    Registered User
    Join Date
    Dec 2011
    Location
    India
    Posts
    35

    Pelles C and DEV C++ Giving Different Output For Same Code!

    When i Compile nd Run the given code
    Pelles C gives the output as 18
    While
    DEV C+ + gives th output as 19(some times it gives it as 18!!)

    Why is this happening?

    And what is the right answer?

    Code:
    #include<stdio.h>
    #include<conio.h>
    int main()
       {
           int i=4,x;
              x=++i + ++i + ++i;
           printf("%d",x);
     _getch();
           return 0;
       }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    The right answer is to learn how to write correct code.
    Expressions

    It's a regular question (like yesterday)
    undefined behaviour.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    That is because line 6 contains undefined behavior. See this link.

    Jim

  4. #4
    Registered User joybanerjee39's Avatar
    Join Date
    Oct 2011
    Location
    kolkata
    Posts
    106
    and don't use <conio.h> , getch().
    use getchar()

  5. #5
    Registered User
    Join Date
    Dec 2011
    Location
    India
    Posts
    35
    Thanks Salem...the 'Expressions' link was quite useful!

    Quote Originally Posted by Salem View Post
    The right answer is to learn how to write correct code.
    Expressions

    It's a regular question (like yesterday)
    undefined behaviour.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. output for array of pointers is not giving correct values
    By nkrao123@gmail. in forum C Programming
    Replies: 8
    Last Post: 09-03-2011, 07:40 AM
  2. Switching from MinGW to Pelles C, code breaks
    By Hear.Me.ROAR in forum C Programming
    Replies: 4
    Last Post: 08-11-2011, 11:21 AM
  3. Replies: 4
    Last Post: 07-07-2011, 02:33 AM
  4. output screen isn't giving proper result
    By time4f5 in forum C Programming
    Replies: 11
    Last Post: 03-22-2011, 01:34 AM
  5. structure giving weird output
    By bluetxxth in forum C Programming
    Replies: 7
    Last Post: 02-14-2010, 11:44 PM