why 'x' is taking always 1.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amarniit
    New Member
    • Sep 2009
    • 13

    why 'x' is taking always 1.

    #include<stdio. h>
    void main ()
    {
    int x=4,y=78;
    if(x=8 && y>65)
    printf("x=%d");
    else
    printf("Bywe");
    getch();
    }


    here i am always geting the value of x is one........... its never change
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    #2
    Code:
    if(x=8 && y>65)
    x=8 is assignment not condition checking.

    It must be :

    Code:
    if(x==8 && y>65)
    Regards
    Dheeraj Joshi


    Note: Please use code tags during posting the code
    Last edited by Dheeraj Joshi; Dec 2 '09, 12:29 PM. Reason: Added Note

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      You don't provide an argument to the printf() function. It should look like: printf("x=%d", x).

      Comment

      • whodgson
        Contributor
        • Jan 2007
        • 542

        #4
        In fact neither of your printf statements are correct.
        e.g.
        printf("i=%d and x=%f\n",i,x);//Here there are two format specifiers in the format string and two data-field arguements. The number of format specifiers require matching with the data-field arguements.

        Comment

        • amarniit
          New Member
          • Sep 2009
          • 13

          #5
          ya in printf()it is
          printf("x=%d",x );

          Comment

          • sidooh
            New Member
            • Dec 2009
            • 9

            #6
            you should use printf("x=%d",x );

            Comment

            • Banfa
              Recognized Expert Expert
              • Feb 2006
              • 9067

              #7
              Strictly speaking if you wish to see your output immediately it should be

              printf("x=%d\n" ,x);

              without the newline the system is free to buffer the output until a later time.

              Comment

              Working...