i havent learn boolean now~ T_T..
i wan to buy a book and learn now..~.. blek..`
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!}
The book says the o.p is A. Can someone please explain why that's the o.p? I'm completely confusedCode:flota a = 0.7; if(a < 0.7) printf("A"); else printf("B");![]()
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 */
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.
if i wan to know more about thing kind of stuff , wat kind of reference u guys suggest? any suggestion ?
K&R is a good resource. The ANSI standard is another (not user-friendly) option.
The program prints ACode:char p[] = "%d\n"; p[1] = 'c'; printf(p,65);
can someone please explain the logic in this one?
65 is the ascii code for A.
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++; }
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks