[algogeeks] Re: C output

2012-07-03 Thread shiv narayan
6/5=1, in integer division, how come you can think it as 2? On Tuesday, 3 July 2012 13:22:07 UTC+5:30, rahul sharma wrote: #includestdio.h #includeconio.h int main() { int i; i=5; i=++i/i++; printf(%d,i); getch(); } Why o/p is 1 and not 2?? what happened for

Re: [algogeeks] Re: c output

2011-09-21 Thread sukran dhawan
IT is not the case ... I already said acc to ANSI c result is undefined !! not 0 by dault On Wed, Sep 21, 2011 at 6:50 PM, kartik sachan kartik.sac...@gmail.comwrote: ans in both cases is zero i think if return is written and nthg specified value is given it will return by default

Re: [algogeeks] Re: c output

2011-09-21 Thread kartik sachan
@sukran if it is undefined in ansi c so it can return any value??? at complilaton.but all time it is giving me same value -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com.

Re: [algogeeks] Re: c output

2011-09-21 Thread sukran dhawan
hmmm it is compiler dependent... try out with different compilers... but even though dey give same results,standard c left this eature as undefined for efficiency purposes On Wed, Sep 21, 2011 at 7:16 PM, kartik sachan kartik.sac...@gmail.comwrote: @sukran if it is undefined in ansi c so it

Re: [algogeeks] Re: c output

2011-09-21 Thread kartik sachan
thanks sukran... i have one more question evaluation of printf is also undefined in C?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group,

Re: [algogeeks] Re: c output

2011-09-21 Thread sukran dhawan
its right to left On Wed, Sep 21, 2011 at 7:41 PM, kartik sachan kartik.sac...@gmail.comwrote: thanks sukran... i have one more question evaluation of printf is also undefined in C?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

[algogeeks] Re: c output

2011-09-19 Thread abhishek
output is 18 9 0 0 0 8 the same was expected. printf uses stack when it has multiple arguments to print On Sep 18, 1:19 pm, Bhavesh agrawal agr.bhav...@gmail.com wrote: another que.. #includestdio.h main() {     int a;     int i=10;     printf(%d %d %d\n,i+++i,i,i---i);    

[algogeeks] Re: c output

2011-09-19 Thread abhishek
@ sukran if it is giving same ans then there has to be some reason, On Sep 19, 12:45 pm, sukran dhawan sukrandha...@gmail.com wrote: common guys its undefined acc to standard c On Mon, Sep 19, 2011 at 12:36 PM, Siddhartha Banerjee thefourrup...@gmail.com wrote: on

Re: [algogeeks] Re: c output

2011-09-19 Thread sukran dhawan
According to K and R c book , when the return value is specified and yet we fail to return a value, it is undefined. It is compiler dependent. So i feel there is no meaning in thinking abt it On Mon, Sep 19, 2011 at 4:38 PM, abhishek abhishek.ma...@gmail.com wrote: @ sukran if it is giving

Re: [algogeeks] Re: c output

2011-09-19 Thread Bhavesh agrawal
abhishek can you plz explain -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more

Re: [algogeeks] Re: c output,printf(%llx)

2011-09-19 Thread wujin chen
@Dave printf(a=%x, b=%llx,a,b,c); i think c will be ignored~~ , and the output is a=9,b=10 2011/9/19 Dave dave_and_da...@juno.com @Wujin: What do you expect the output to be? How does it differ from what you actually get? Dave On Sep 18, 8:47 am, wujin chen wujinchen...@gmail.com wrote:

[algogeeks] Re: c output,printf(%llx)

2011-09-19 Thread Dave
@Wujin: Okay. But b is an integer and it is being printed as a long long. Since there are no implicit type conversions in procedure calls such as the printf statement, b is taken as a long long, not of an int. So b and the next 32-bits are printed. Dave On Sep 19, 8:18 pm, wujin chen

[algogeeks] Re: c output,printf(%llx)

2011-09-19 Thread Dave
@Wujin: Okay. b is but an integer, yet it is being printed as a long long. Since there are no implicit type conversions in procedure calls such as the printf statement, b is taken as a long long, not of an int. So b and the next 32-bits are printed. The format that these are printed in is a

[algogeeks] Re: c output,printf(%llx)

2011-09-18 Thread Dave
@Wujin: What do you expect the output to be? How does it differ from what you actually get? Dave On Sep 18, 8:47 am, wujin chen wujinchen...@gmail.com wrote: usigned long long x = 0x12345678; int a = 0x09; int b = 0x10; printf(a=%x, b=%llx,a,b,c); the result is: a=9,b=123456780010 i

Re: [algogeeks] Re: c output .. help plz

2011-09-07 Thread Sanjay Rajpal
+1 dave. Sanju :) On Tue, Sep 6, 2011 at 3:40 PM, Dave dave_and_da...@juno.com wrote: @Srivastav: Yeah. You need more parens: printf(%d,(int)(3.14*6.25*6.25)); Without the extra parens, the 3.14 is cast to an int, but then implicitly recast to a double for the multiplications. With the

[algogeeks] Re: C output????

2011-09-06 Thread siva viknesh
thanks a lot guys :) On Sep 6, 11:48 am, Rajeshwar Patra rajeshwarpa...@gmail.com wrote: pointer points to read only memory location and this address is then compared whch evaluates to true hence the output... -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] Re: c output .. help plz

2011-09-06 Thread UTKARSH SRIVASTAV
printf behaves abnormally when it sees arguments not matching with its datatype @dave printf(%d,(int)3.14*6.25*6.25); is also giving 0. -- *UTKARSH SRIVASTAV CSE-3 B-Tech 3rd Year @MNNIT ALLAHABAD* -- You received this message because you are subscribed to the Google Groups

[algogeeks] Re: c output .. help plz

2011-09-06 Thread Dave
@Srivastav: Yeah. You need more parens: printf(%d,(int)(3.14*6.25*6.25)); Without the extra parens, the 3.14 is cast to an int, but then implicitly recast to a double for the multiplications. With the parens, the product is formed in type double, and then the result is cast into integer. Sorry

[algogeeks] Re: C output

2011-08-31 Thread abhishek
it will be 4 3 On Aug 31, 9:01 pm, aditi garg aditi.garg.6...@gmail.com wrote: sorry my mistake... it wud be 4 3 second output is quite obvious as it will count till it get string termination and in first one it is a pointer to character so it will be of size 4. On Wed, Aug 31,

[algogeeks] Re: C output

2011-08-17 Thread venkat
yes u r correct On Aug 16, 8:22 pm, Sanjay Rajpal sanjay.raj...@live.in wrote: This is becuase Hello is a constant string and constant strings get stored in *Data Area, not in stack for the function you called. *Thats why pointer to constant string will be returned and program will not produce

Re: [algogeeks] Re: C output

2011-08-17 Thread rajeev bharshetty
No the warning in gcc is ibm1.c: In function ‘main’: ibm1.c:7:19: warning: initialization discards qualifiers from pointer target type On Wed, Aug 17, 2011 at 11:50 AM, venkat p.venkatesh...@gmail.com wrote: yes u r correct On Aug 16, 8:22 pm, Sanjay Rajpal sanjay.raj...@live.in wrote:

[algogeeks] Re: c output

2011-08-16 Thread roopesh bajaj
it is compiler dependent On Aug 1, 5:20 pm, thanu moorthy moorthyth...@gmail.com wrote: Please help me... How can the following output be obtained :  1.main() {  int i=1; printf(%d\t%d\t%d\t,i,i++,i); } output: 2 1 2  2.main() {  int i=1; printf(%d\t%d\t%d\t,i,++i,i); }

[algogeeks] Re: C Output

2011-08-14 Thread Brijesh Upadhyay
I think i got it... STRING always return address of S , which then get summed with 1 and 2. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/kFrZUxzFTxsJ.

Re: [algogeeks] Re: C Output

2011-08-14 Thread sukran dhawan
try out with Microsoft VC++ On Sun, Aug 14, 2011 at 11:47 AM, Brijesh Upadhyay brijeshupadhyay...@gmail.com wrote: I think i got it... STRING always return address of S , which then get summed with 1 and 2. -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] Re: C Output

2011-08-14 Thread sourabh jakhar
compiler dependent and will print some address On Sun, Aug 14, 2011 at 11:48 AM, sukran dhawan sukrandha...@gmail.comwrote: try out with Microsoft VC++ On Sun, Aug 14, 2011 at 11:47 AM, Brijesh Upadhyay brijeshupadhyay...@gmail.com wrote: I think i got it... STRING always return address

[algogeeks] Re: c output doubt

2011-08-14 Thread roopesh bajaj
what is the logic of your concept On Aug 13, 5:01 pm, Kunal Patil kp101...@gmail.com wrote: @rohit: Cast pointer to an integer into an int to get what you are expecting. for e.g. printf(%d,(int)a[4]-(int)a[0]); This will give 16. -- You received this message because you are subscribed

Re: [algogeeks] Re: c output doubt

2011-08-13 Thread Kunal Patil
@rohit: Cast pointer to an integer into an int to get what you are expecting. for e.g. printf(%d,(int)a[4]-(int)a[0]); This will give 16. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Re: c output doubt

2011-08-12 Thread rohit
Thanks a lot On Aug 12, 11:25 am, Avinash Dharan avinashdha...@gmail.com wrote: Pointer incrementation and subtraction are done in terms of memory blocks and not addresses of memory. For example, int *p; p++; The pointer here jumps to the next integer location and not the next address in

[algogeeks] Re: c output

2011-08-01 Thread Agyat
no one can explain such things correctly because they are compiler dependent.The result is not deterministic,it may vary from one platform to another On Aug 1, 8:22 pm, Prashant Gupta prashantatn...@gmail.com wrote: Nikhil only explained third rightly. :-/ I think 1,2,4's output are given wrong

Re: [algogeeks] Re: c output

2011-08-01 Thread Amol Sharma
@agyat +1 these outputs are not standardit's implementation dependent. -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad On Mon, Aug 1, 2011 at 8:55 PM, Agyat jalsa.n.sa...@gmail.com wrote: no one can explain such things correctly because they are

[algogeeks] Re: c output

2011-08-01 Thread ghsjgl k
The output for third only correct 1,2 and 4 are wrong i think printf() is evaluated from right to left and the post inceremet operator increses after assigning the value hence third is correct. also tested them using Dev C++ compiler its working as i said above On Aug 1, 5:20 pm, thanu

[algogeeks] Re: C output

2011-07-28 Thread prabhat
i think there will be warning due to inner structure is not declaring variable. Inner structure must be like: struct yy { char s; struct xx *p; }a; On Jul 27, 9:22 pm, Aman Goyal aman.goya...@gmail.com wrote: #include‹stdio.h› main() { struct xx { int x; struct yy { char s;      

Re: [algogeeks] Re: C output

2011-07-28 Thread Piyush Kapoor
It is not showing compiler error on Codeblocks on my machine. On Thu, Jul 28, 2011 at 2:26 PM, prabhat prabhat0...@gmail.com wrote: i think there will be warning due to inner structure is not declaring variable. Inner structure must be like: struct yy { char s; struct xx *p; }a;

Re: [algogeeks] Re: C output

2011-07-28 Thread Rohit Srivastava
no error in dev c++. On Thu, Jul 28, 2011 at 2:43 PM, Piyush Kapoor pkjee2...@gmail.com wrote: It is not showing compiler error on Codeblocks on my machine. On Thu, Jul 28, 2011 at 2:26 PM, prabhat prabhat0...@gmail.com wrote: i think there will be warning due to inner structure is

Re: [algogeeks] Re: C output

2011-07-28 Thread rajeev bharshetty
No error in gcc 4.3.2 too On Thu, Jul 28, 2011 at 2:47 PM, Rohit Srivastava access2ro...@gmail.comwrote: no error in dev c++. On Thu, Jul 28, 2011 at 2:43 PM, Piyush Kapoor pkjee2...@gmail.comwrote: It is not showing compiler error on Codeblocks on my machine. On Thu, Jul 28,

Re: [algogeeks] Re: C output

2011-07-28 Thread Tyler Durden
Only a warning in Dev C++ due to no variable declaration of inner structure -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/HtevjjeGDZoJ. To post to this

[algogeeks] Re: C output 2

2011-07-27 Thread amit
hello is a string literal and this is what the C standard says about string literals: The multibyte character sequence is then used to initialize an array of static storage duration and length just sufficient to contain the sequence. So memory will remain reserved for hello for the entire

[algogeeks] Re: C output 2

2011-07-27 Thread Abhinav Arora
No it will not cause a memory leak as its a string literal and it behaves more like a read only entity. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit

[algogeeks] Re: C output 2

2011-07-27 Thread private.joker
Passing a pointer across functions does not create any problem and doesn't cause memory leak. but passing an array ,for eg int *fun() { int a[12]; return a; } this creates memory leak as the call stack no more holds the array. So, in essence, though int *a and int a[] behave quite similarly

[algogeeks] Re: C Output

2011-07-26 Thread siva viknesh
ideone.com is also great On Jul 26, 10:03 pm, Ram CEG honest...@gmail.com wrote: ya it would ignore \ alone.. On Tue, Jul 26, 2011 at 10:27 PM, aditi garg aditi.garg.6...@gmail.comwrote: ya thats wat my doubt was...if its not a recognised escape sequence thn how is it interpreted??

Re: [algogeeks] Re: C OUTPUT HELP

2011-07-24 Thread Rabi Chandra Shah
Hey, I guess , there is no defined order in which the function values are evaluated .. Plz check this link ... http://stackoverflow.com/questions/376278/parameter-evaluation-order-before-a-function-calling-in-c/376288#376288... I think we should clear our concept on this part However, you

[algogeeks] Re: C OUTPUT HELP

2011-07-22 Thread Interstellar Overdrive
@T3rminal- Agreed. Thus the expressions like : a[i] = i++; , i=i++ - --i; are irrelevant -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/-lYHVFcDjXYJ. To

[algogeeks] Re: C OUTPUT HELP

2011-07-22 Thread sumit
+1 to t3rminal On Jun 12, 11:38 pm, T3rminal piyush@gmail.com wrote: @all Stop guessing and making your own standards. C standards haven't defined anything (though in gcc arguments are processed from left to right) about processing arguments in a function call. And sentence like

Re: [algogeeks] Re: C OUTPUT HELP

2011-07-22 Thread geek forgeek
@nicks -- ur code for 1st problem is giving me 1 not -1 on gcc..which compiler are you using On Fri, Jul 22, 2011 at 11:58 AM, sumit sumitispar...@gmail.com wrote: +1 to t3rminal On Jun 12, 11:38 pm, T3rminal piyush@gmail.com wrote: @all Stop guessing and making your own standards. C

[algogeeks] Re: C output

2011-07-20 Thread chetan
its showing same output... On Jul 20, 6:40 pm, chetan kapoor chetankapoor...@gmail.com wrote: but its showing output On Wed, Jul 20, 2011 at 6:53 PM, mohit verma mohit89m...@gmail.com wrote: hey guys... 1. char c='a';   while(c=='a') {  printf(%c,c); c=getchar(); }

[algogeeks] Re: C output

2011-07-20 Thread mohit
guys just give input a stream of characters as: a a a a a a a a a a a a ---(press enter) for second case input as: c d e f g h i j b -(press enter) and see the difference. (I know that printf() is line buffered. So why?) 1.printf() shows 'a' one time only. 2.here it shows

Re: [algogeeks] Re: C output

2011-07-20 Thread sunny agrawal
In first case first character input is 'a' and second is space so loop breaks in second loop runs till b is not read hence all characters including spaces are found in output On Wed, Jul 20, 2011 at 7:29 PM, mohit mohit89m...@gmail.com wrote: guys just give input a stream of characters

[algogeeks] Re: C output

2011-07-20 Thread mohit
ohh ...got it. On Jul 20, 7:06 pm, sunny agrawal sunny816.i...@gmail.com wrote: In first case first character input is 'a' and second is space so loop breaks in second loop runs till b is not read hence all characters including spaces are found in output On Wed, Jul 20, 2011 at

Re: [algogeeks] Re: C OUTPUT HELP

2011-07-20 Thread Anurag atri
@Nicks : Kindly share the source from where you are practicing these c output questions .. Thank You :) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this

[algogeeks] Re: c++ output

2011-07-17 Thread Parthiban
The keyword inline means the code is substituted for the declared inline function call in its place itself and this is done at compile time and mostly an optional one left to the compiler to substitute or not. since you have used inline in the snippet it means i checks for the function

[algogeeks] Re: C OUTPUT HELP

2011-07-12 Thread Abhi
PROBLEM 2: First all the expressions are evauated from right to left in printf() and then results printed with tha final value of i. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit

Re: [algogeeks] Re: C OUTPUT HELP

2011-07-12 Thread saurabh singh
For 1st problem learn the concepts of linking.Scanf hasn't been required to link yet in the main. So during compling the program doesn't give any special treatment to scanf. check this, #includestdio.h int charu(int x); int charu(int x) { return x; } main() { int charu=67; int scanf=78; //int

Re: [algogeeks] Re: C OUTPUT HELP

2011-07-12 Thread Anand Saha
But this works, where I have both the variable name and function name used: #includestdio.hint charu(int x);int charu(int x) { return x; } main(){* int a = charu(45); int charu = a;* int scanf=78; //int printf=45; int getchar=6;

[algogeeks] Re: C OUTPUT HELP

2011-06-12 Thread T3rminal
@all Stop guessing and making your own standards. C standards haven't defined anything (though in gcc arguments are processed from left to right) about processing arguments in a function call. And sentence like assgnment to a preincrement expression is delayed vry mch have no meaning .

Re: [algogeeks] Re: C Output

2011-06-05 Thread Ashish kumar Jain
Also,Please note that using relational/comparison operators with floating point numbers/real numbers is not an advisable coding practice. On Mon, May 30, 2011 at 8:12 PM, Dave dave_and_da...@juno.com wrote: @vishal: Floats and doubles are stored in different formats, so looking at the first 8

[algogeeks] Re: c output

2011-06-05 Thread siva viknesh
ya i have seen many questions like this in this group...its all because of sequence points the output varies from compiler to compiler On Jun 4, 9:10 pm, nicks crazy.logic.k...@gmail.com wrote: i agree this type of expressions are not defined and are depend on the machine.. it's

Re: [algogeeks] Re: c output

2011-06-04 Thread Dv!! ITs nt me now!!
statement starts executing from the right side!!! 1st it reads it from left !! while reading b increment two times and new value of b is thn 5 nw it gets executed!!! am i right?? On 6/4/11, hary rathor harry.rat...@gmail.com wrote: in 1st pass both ++b ++b= 4 then ++b= 5; at second pass

Re: [algogeeks] Re: c output

2011-06-04 Thread Rohit Sindhu
Order of evaluation of operands is not defined in C and secondly the result will be compiler implementation dependent. A compiler may store the sub expressions operand values in a temporary storage or can make use of variable value as an operand. *In each case, either of the ++b may be executed

Re: [algogeeks] Re: c output

2011-06-04 Thread nicks
i agree this type of expressions are not defined and are depend on the machine.. it's something like a[i]=i++; the result may vary from machine to machine ! On Sat, Jun 4, 2011 at 5:00 PM, Rohit Sindhu rohit.sindhu.spec...@gmail.com wrote: 1. If the operand values is to be stored in

[algogeeks] Re: c output

2011-06-03 Thread Don
An ANSI-compliant compiler is not required to generate an error for undefined code. The code syntax is correct. ANSI doesn't say what the compiler must do for undefined code, which is why it is undefined. The compiler can do anything. It might do what you expect, or it might not. Don On Jun 1,

Re: [algogeeks] Re: c output

2011-06-03 Thread hary rathor
in 1st pass both ++b ++b= 4 then ++b= 5; at second pass a= 5*5; because ++b is 5 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to

[algogeeks] Re: c output

2011-06-01 Thread Don
That may be true, but it is not guaranteed. Having multiple side affects between sequence points is undefined by the ANSI standard. Therefore an ANSI-compliant compiler could produce an executable which causes monkeys to fly out of your nose. Don On Jun 1, 11:27 am, anuj agarwal

Re: [algogeeks] Re: c output

2011-06-01 Thread richa mahajan
if it is undefined by standard den y dont compilers follow it On Wed, Jun 1, 2011 at 11:59 PM, Don dondod...@gmail.com wrote: That may be true, but it is not guaranteed. Having multiple side affects between sequence points is undefined by the ANSI standard. Therefore an ANSI-compliant

[algogeeks] Re: C Output

2011-05-30 Thread Dave
@vishal: Floats and doubles are stored in different formats, so looking at the first 8 hex digits of the two numbers isn't really helpful. The expression f 0.8 is evaluated as (double)f 0.8, so it would be more useful to print all 16 hex digits of (double)0.8f and 0.8. Then it would be easy to

[algogeeks] Re: C OUTPUT

2011-05-22 Thread Nishant
conversion frm int to float and float to int is very poor in case of printf funtion so when we give the input to t then that value is displayed for all the printf function since %f modifier doesn't accept x (int) as a successful argument so it takes the latest float value.. On May 22, 2:41 pm,

Re: [algogeeks] Re: c output

2010-06-12 Thread divya jain
one of my frnd askd me this question... On 11 June 2010 21:34, Raj N rajn...@gmail.com wrote: @kirubakaran: How can it be 1,1 ? No of characters read in a is 5+ 1 for '\n' so its 6 and for the next one 1+1=2 On Fri, Jun 11, 2010 at 9:09 AM, kirubakaran kirubakaran1...@gmail.comwrote:

Re: [algogeeks] Re: c output

2010-06-12 Thread Arun prasath
The only gurantee in this is that the outer printf result will come first. Why ? because comma operator does not act as sequence point. -Arun prasath N On Sat, Jun 12, 2010 at 3:44 PM, divya jain sweetdivya@gmail.comwrote: thanks to all for explanantions :) On 12 June 2010 15:43, divya

[algogeeks] Re: c output

2010-06-11 Thread Ashish
Explanation: The prototype for printf as per ANSI C is: int printf( const char *format,…) the return value is integer and returns the number of characters successfully read by printf. Also,in case of printf(),the evaluation of expressions passed on as arguments is done from right to left

[algogeeks] Re: c output

2010-06-11 Thread kirubakaran
Output will be 1,1 bcoz printf returns number of characters or integers printed On Jun 11, 12:26 am, divya sweetdivya@gmail.com wrote: #include stdio.h main() {  int a = 1;  char b='c';  int i,j;  printf(%d,%d,printf(%d\n,a),printf(%c\n,b)); wat shd b the o/p of this..plzz

Re: [algogeeks] Re: c output

2010-06-11 Thread Raj N
@kirubakaran: How can it be 1,1 ? No of characters read in a is 5+ 1 for '\n' so its 6 and for the next one 1+1=2 On Fri, Jun 11, 2010 at 9:09 AM, kirubakaran kirubakaran1...@gmail.comwrote: Output will be 1,1 bcoz printf returns number of characters or integers printed On Jun 11, 12:26