Unary.c

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oscardiz
    New Member
    • Sep 2006
    • 2

    #1

    Unary.c

    printf("\n%d %d", a--, --b);

    This is supposed to be ok, but it gives me this compiler error=

    Parse error before string constant.
    conflicting types for built-in function 'printf'
    /* unary.c*/
    /* Demonstrate unary operator prefix and postfix modes */

    #include <stdio.h>

    int a, b;

    main(0
    {
    /* set a and b both equal to 5 */

    a = b = 5;

    /* Print them, decrementing each time. /*
    /* Use prefix mode for b, postfix mode for a */

    printf("\n%d %d", a--, --b);
    printf("\n%d %d", a--, --b);
    printf("\n%d %d", a--, --b);
    printf("\n%d %d", a--, --b);
    printf("\n%d %d", a--, --b);

    return 0;

    }
  • tyreld
    New Member
    • Sep 2006
    • 144

    #2
    Originally posted by oscardiz
    printf("\n%d %d", a--, --b);

    This is supposed to be ok, but it gives me this compiler error=

    Parse error before string constant.
    conflicting types for built-in function 'printf'
    /* unary.c*/
    /* Demonstrate unary operator prefix and postfix modes */

    #include <stdio.h>

    int a, b;

    main(0
    {
    /* set a and b both equal to 5 */

    a = b = 5;

    /* Print them, decrementing each time. /*
    /* Use prefix mode for b, postfix mode for a */

    printf("\n%d %d", a--, --b);
    printf("\n%d %d", a--, --b);
    printf("\n%d %d", a--, --b);
    printf("\n%d %d", a--, --b);
    printf("\n%d %d", a--, --b);

    return 0;

    }

    This code works fine for me except for the typo "main(0" which I assume should be "main()". Are you sure you had the #include <stdio.h> in your file when you tried to compile this? The compiler error looks like what you would get if you forgot to include the standard IO library.

    Comment

    • oscardiz
      New Member
      • Sep 2006
      • 2

      #3
      Thankyou
      Yes typo error.
      Yes I use #include.
      Coulod it be the compiler?

      Comment

      • koder
        New Member
        • Sep 2006
        • 23

        #4
        #include <stdio.h>

        int a, b;

        main(0
        {
        /* set a and b both equal to 5 */

        a = b = 5;

        /* Print them, decrementing each time. /*
        /* Use prefix mode for b, postfix mode for a */

        printf("\n%d %d", a--, --b);
        printf("\n%d %d", a--, --b);
        printf("\n%d %d", a--, --b);
        printf("\n%d %d", a--, --b);
        printf("\n%d %d", a--, --b);

        return 0;

        }

        the code works fine for me too,except main(0)...could be a typo ? :-)

        Comment

        • nikhilraj
          New Member
          • Sep 2006
          • 11

          #5
          nt a, b;

          main()
          {
          /* set a and b both equal to 5 */

          a = b = 5;

          /* Print them, decrementing each time. /*
          /* Use prefix mode for b, postfix mode for a */

          printf("\n%d %d", a--, --b);
          printf("\n%d %d", a--, --b);
          printf("\n%d %d", a--, --b);
          printf("\n%d %d", a--, --b);
          printf("\n%d %d", a--, --b);

          return 0;

          }
          this code worked perfectly for me if we cahnge the main(0) to main() then it works all right

          Comment

          Working...