Closed Thread
Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21

Thread: Confused about expression evaluation

  1. #11
    R3.RyozKidz Guest

    Re: Confused about expression evaluation

    i havent learn boolean now~ T_T..
    i wan to buy a book and learn now..~.. blek..`

  2. CODECALL Circuit advertisement

     
  3. #12
    dcs
    dcs is offline Guru
    Join Date
    Mar 2008
    Posts
    775
    Rep Power
    23

  4. #13
    n00bcoder is offline Newbie
    Join Date
    Oct 2009
    Posts
    8
    Rep Power
    0

    Re: Confused about expression evaluation

    another one of my n00b questions : { I have this book which I'm trying to do exercises from and some of the questions I have no clue about!}


    Code:
    flota a = 0.7;
    if(a < 0.7)
      printf("A");
    else
      printf("B");
    The book says the o.p is A. Can someone please explain why that's the o.p? I'm completely confused

  5. #14
    dcs
    dcs is offline Guru
    Join Date
    Mar 2008
    Posts
    775
    Rep Power
    23

    Re: Confused about expression evaluation

    Loss of precision and data types.
    Code:
    #include<stdio.h>
    
    int main()
    {
       float a = 0.7;
       /*
        * The value 0.7 a double; when 'a' is initialized, it loses precision when
        * being stored as a float. This is done silently.
        * 
        * In the comparison below, the float value 'a' is compared to the double
        * value 0.7. In the process 'a' is promoted to a double, but it doesn't gain
        * back any precision already lost in the initialization.
        */
       if ( a < 0.7 )
       {
          puts("A"); /* the answer I get */
       }
       else
       {
          puts("B");
       }
       /*
        * If we make the comparison of 'a' with the float value 0.7, both will have
        * lost the same amount of precision and the expected answer is what we get.
        */
       if ( a < 0.7F )
       {
          puts("C");
       }
       else
       {
          puts("D"); /* the answer I get */
       }
       return 0;
    }
    
    /* my output
    A
    D
    */

  6. #15
    n00bcoder is offline Newbie
    Join Date
    Oct 2009
    Posts
    8
    Rep Power
    0

    Re: Confused about expression evaluation

    thanks a lot

    btw, is there any specific "must read" book/website where a lot of such things are very clearly mentioned or taken up as examples etc. so that I don't have to come across such problems only in tests?

    BTW, I'm currently referring to Kernighan&Ritchie.

  7. #16
    R3.RyozKidz Guest

    Re: Confused about expression evaluation

    if i wan to know more about thing kind of stuff , wat kind of reference u guys suggest? any suggestion ?

  8. #17
    Join Date
    Jul 2006
    Posts
    16,478
    Blog Entries
    75
    Rep Power
    143

    Re: Confused about expression evaluation

    K&R is a good resource. The ANSI standard is another (not user-friendly) option.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  9. #18
    n00bcoder is offline Newbie
    Join Date
    Oct 2009
    Posts
    8
    Rep Power
    0

    Re: Confused about expression evaluation

    Code:
    char p[] = "%d\n";
    p[1] = 'c';
    printf(p,65);
    The program prints A

    can someone please explain the logic in this one?

  10. #19
    Join Date
    Jul 2006
    Posts
    16,478
    Blog Entries
    75
    Rep Power
    143

    Re: Confused about expression evaluation

    65 is the ascii code for A.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  11. #20
    n00bcoder is offline Newbie
    Join Date
    Oct 2009
    Posts
    8
    Rep Power
    0

    Re: Confused about expression evaluation

    please take time to explain the logic of the program. I just can't seem to figure it out myself


    Code:
    char *x = "Alice";  // this means that x is a char pointer which points to the starting location of string "Alice"
    n = strlen(x); 
    *x = x[n]; // but what is this? x was a pointer so what does this statement mean? 
    for(i = 0; i<=n;i++)
    {
      printf("%s", x);
      x++;
    }

Closed Thread
Page 2 of 3 FirstFirst 123 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Expression Evaluation:Urgent help needed
    By avm08 in forum C# Programming
    Replies: 4
    Last Post: 12-01-2010, 02:39 PM
  2. if expression
    By Bertan in forum C and C++
    Replies: 1
    Last Post: 10-20-2010, 10:50 AM
  3. postfix evaluation
    By mayra in forum C and C++
    Replies: 7
    Last Post: 07-13-2010, 11:07 PM
  4. Expression is not a method.
    By Sniped Sniper in forum Visual Basic Programming
    Replies: 2
    Last Post: 04-23-2009, 02:06 PM
  5. c# regular expression
    By moonrise in forum C# Programming
    Replies: 3
    Last Post: 05-22-2006, 02:54 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts