@sandeep u mean whenever printf will demand for %f then it will print 2.0.....is it random behavior or always going to happen ??
anyone else having better idea regarding 1st and 2nd problem... On Mon, Jul 11, 2011 at 9:51 AM, Sandeep Jain <[email protected]> wrote: > TurboC has many flaws, one of the simplest examples would be > char *p; > scanf("%s", p); > > In gcc/g++ this will surely lead to segmentation fault as memory has not > been allocated. Whereas in TC it will execute fine in most of the cases. > Infact this will crash when your code is really large. > > As for input, 2 will automatically be treated as 2.0 when scanf demands a > floating value. However, if you enter characters in place of numbers or vice > versa. You may experience weird behavior. > > > > > Regards, > Sandeep Jain > > > > > On Mon, Jul 11, 2011 at 9:37 AM, nicks <[email protected]> wrote: > >> @sandeep,kamakshii....thanks both...your replies were really helpful....i >> understood my fault in 3,4,5...they are clea now......but i am still stuck >> with problem 1 and 2 >> >> @sandeep....what if i am using turbo C...though i am using gcc on terminal >> in my linux system..... >> moreover acc. t K&R "printf uses it's first argument to decide how many >> arguments follow and what their types are. it will get confused,and you will >> get wrong answers,if there are not enough arguments or if they are the wrong >> type" >> it's fine it will give the wrong answer then it's only the value we >> provide in input ??? >> >> >> @kamakshii...can explain your point related to macro in detail.....is it >> related to linking or something which is done after creating object file... >> >> On Mon, Jul 11, 2011 at 1:37 AM, Kamakshii Aggarwal < >> [email protected]> wrote: >> >>> probelm 5:It must be giving runtime error not segmentation fault coz it >>> is an infinite recursion.... >>> >>> >>> On Mon, Jul 11, 2011 at 1:09 AM, Kamakshii Aggarwal < >>> [email protected]> wrote: >>> >>>> for the first question...it will take #ifdef getchar to be '1' only when >>>> it is defined as a MACRO in your program..if u dont define macro it will >>>> not >>>> take it into consideration even if it is defined in header file. >>>> >>>> On Mon, Jul 11, 2011 at 12:38 AM, nicks <[email protected]>wrote: >>>> >>>>> Someone please help me in understanding the following output - >>>>> >>>>> Problem *1>.* >>>>> #include<stdio.h> >>>>> #ifdef getchar //this expression is evaluated to zero.....why >>>>> is so happening ??........getchar is defined as macro in stdio.h.....i >>>>> mean >>>>> else part shouldn't be executed which is happening >>>>> #undef getchar >>>>> #else >>>>> #define getchar scanf("%c",&ch); >>>>> #endif >>>>> main() >>>>> { >>>>> char ch; >>>>> int c; >>>>> c=getchar; >>>>> printf("%d",c); >>>>> } >>>>> >>>>> *OUTPUT- 1* >>>>> * >>>>> * >>>>> * >>>>> * >>>>> *2>.* >>>>> #include<stdio.h> >>>>> void main() >>>>> { >>>>> long x; >>>>> float t; >>>>> scanf("%f",&t); >>>>> printf("%d\n",t); >>>>> x=90; >>>>> printf("%ld\n",x); >>>>> { >>>>> x=1; >>>>> printf("%f\n",x); >>>>> { >>>>> x=30; >>>>> printf("%f\n",x); >>>>> } >>>>> printf("%f\n",x); >>>>> } >>>>> x==9; >>>>> printf("%f\n",x); >>>>> } >>>>> >>>>> *OUTPUT(INPUT IS 2) -* >>>>> *2* >>>>> *0* >>>>> *90* >>>>> *2.000000* >>>>> *2.000000* >>>>> *2.000000* >>>>> *2.000000* >>>>> * >>>>> * >>>>> In this problem i failed to Understand why t is printed as 0 (though >>>>> float is converted to integer by truncation of the fractional part) >>>>> and how the value of t is transferred to x....looks very strange to me >>>>> !! >>>>> >>>>> >>>>> *3>.* >>>>> #include<stdio.h> >>>>> main() >>>>> { >>>>> printf("\nACM-CIC"+3); >>>>> printf(4+"\nACM-CIC"); >>>>> >>>>> } >>>>> >>>>> *OUTPUT -* >>>>> *M-CIC-CIC* >>>>> * >>>>> * >>>>> What does +3 and +4 doing and does it matter to use them before the >>>>> format string or after it ?? >>>>> >>>>> *4>.* >>>>> #include<stdio.h> >>>>> main() >>>>> { >>>>> long long i=50; >>>>> i==1000000000000000000000000000000000000000; >>>>> printf("i=%d\n\n%lld",sizeof(i),i); >>>>> //system("pause"); >>>>> } >>>>> >>>>> *OUTPUT -* >>>>> *i=8* >>>>> * >>>>> * >>>>> *50* >>>>> * >>>>> * >>>>> Assigning very large value to i isn't changing it's value.....why is so >>>>> happening ?? >>>>> >>>>> and the last one >>>>> >>>>> *5>.* >>>>> #include<stdio.h> >>>>> main() >>>>> { >>>>> static int i=0; >>>>> if(i<=-1) >>>>> printf("\nBull's Eye"); >>>>> else >>>>> { >>>>> main(); >>>>> _exit(1); >>>>> } >>>>> i++; >>>>> } >>>>> >>>>> *OUTPUT -* >>>>> *segementation fault* >>>>> * >>>>> * >>>>> What's Wrong with the above Code due to which it is giving Runtime >>>>> error....plz help me pointing it out !! >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Algorithm Geeks" group. >>>>> To post to this group, send email to [email protected]. >>>>> To unsubscribe from this group, send email to >>>>> [email protected]. >>>>> For more options, visit this group at >>>>> http://groups.google.com/group/algogeeks?hl=en. >>>>> >>>> >>>> >>>> >>>> -- >>>> Regards, >>>> Kamakshi >>>> [email protected] >>>> >>> >>> >>> >>> -- >>> Regards, >>> Kamakshi >>> [email protected] >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]. >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
