Re: [algogeeks] c output

2011-08-10 Thread aditi garg
this ques has been answered be4 on this grp...and u missed the macro definition as welljst a few days bak...search the group On Wed, Aug 10, 2011 at 11:00 PM, rohit rajuljain...@gmail.com wrote: main() { int m,n; m=3+max(2,3); n=2*max(3,2); printf(“%d,%d”,m,n); } ans:-m=2,n=3 why

[algogeeks] c output

2011-08-02 Thread Radhika Renganathan
can someone explain the output of following program? #includestdio.h main(){char *p=hai friends,*p1; p1=p;while(*p!='\0') ++*p++;printf(%s,p1);} i got run time error in gcc.. -- radhika .. :) -- You received this message because you are subscribed to the Google Groups Algorithm

Re: [algogeeks] c output

2011-08-02 Thread Ravinder Kumar
++*p++ This statement changing the value of read only memory of string constant *p=hai friends ; -- *With Regards :* Ravinder Kumar B.Tech Final Year Computer Science and Engineering MNNIT Allahabad -- You received this message because you are subscribed to the Google Groups Algorithm

Re: [algogeeks] c output

2011-08-02 Thread Radhika Renganathan
thks ravinder.. ! char p[]=hi char *p = hi are both string constants? On Wed, Aug 3, 2011 at 2:08 AM, Ravinder Kumar ravinde...@gmail.com wrote: ++*p++ This statement changing the value of read only memory of string constant *p=hai friends ; -- *With Regards :* Ravinder Kumar

Re: [algogeeks] c output

2011-08-02 Thread Sandeep Jain
hi is string constant in both cases... However using p[] allocates memory and copies the string hi in it. On Aug 3, 2011 2:17 AM, Radhika Renganathan radi.coo...@gmail.com wrote: thks ravinder.. ! char p[]=hi char *p = hi are both string constants? On Wed, Aug 3, 2011 at 2:08 AM, Ravinder

Re: [algogeeks] c output

2011-08-02 Thread tmdhat
more specifically,, char *p1 = in data; char p2[] = in stack; *p1 points to a string literal in process' data area. p2[] is allocated in the current stack and then the string is copied into it as Jain correctly stated,, this data area is actually part of the process,,, it's allocated a

[algogeeks] c output

2011-08-01 Thread thanu moorthy
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); } output: 2 2 2 3.main() { int i=1; printf(%d\t%d\t%d\t,i,i++,i++); } output: 3 2 1

Re: [algogeeks] c output

2011-08-01 Thread thanu moorthy
thanks Regards by THANU - -- 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] c output

2011-08-01 Thread muruga vel
I cant understand the third one On Mon, Aug 1, 2011 at 6:09 PM, Nikhil Gupta nikhilgupta2...@gmail.comwrote: printf scans the arguments from right to left for any arithmetic operations to be performed. If found, they are evaluated according to their precedence. In 1. main() { int i=1;

Re: [algogeeks] c output

2011-08-01 Thread Nikhil Gupta
3.main() { int i=1; printf(%d\t%d\t%d\t,i,i++,i++); } output: 3 2 1 Scan from right. Rightmost i++ is encountered. Value of i is incremented but this is post increment, so the effect of increment will not show on this i (But other i's are now incremented). Again another i++ is

Re: [algogeeks] c output

2011-08-01 Thread Raman
Niks u r wrng..this is undefined. Different results in different compilers -- 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/-/es-F94sx2KIJ. To post to this

Re: [algogeeks] c output

2011-08-01 Thread muruga vel
So which one to consider On Mon, Aug 1, 2011 at 7:17 PM, Raman raman.u...@gmail.com wrote: Niks u r wrng..this is undefined. Different results in different compilers -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion

Re: [algogeeks] c output

2011-08-01 Thread Prashant Gupta
Nikhil only explained third rightly. :-/ I think 1,2,4's output are given wrong by thanu. On Mon, Aug 1, 2011 at 8:39 PM, muruga vel murugavidya1...@gmail.comwrote: So which one to consider On Mon, Aug 1, 2011 at 7:17 PM, Raman raman.u...@gmail.com wrote: Niks u r wrng..this is undefined.

[algogeeks] C output 3

2011-07-29 Thread Ankur Khurana
Please explain the output, that why is it in that form in hexadecimal form #includestdio.h int main() { printf(%d %x,-11,-11); return 0; } output : -2 fffe -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group,

Re: [algogeeks] C output 3

2011-07-29 Thread aditi garg
this is bec -1 in hexadecimal is On Fri, Jul 29, 2011 at 11:37 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: Please explain the output, that why is it in that form in hexadecimal form #includestdio.h int main() { printf(%d %x,-11,-11); return 0; } output : -2

Re: [algogeeks] C output 3

2011-07-29 Thread sukhmeet singh
I couldn't understand the problem .. u have used %x as indentifier that why it is so On Fri, Jul 29, 2011 at 11:37 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: Please explain the output, that why is it in that form in hexadecimal form #includestdio.h int main() { printf(%d

Re: [algogeeks] C output 3

2011-07-29 Thread Ankur Khurana
i figured it out. I didnt know before that is was in 2's complement form . On Fri, Jul 29, 2011 at 11:53 PM, sukhmeet singh sukhmeet2...@gmail.comwrote: I couldn't understand the problem .. u have used %x as indentifier that why it is so On Fri, Jul 29, 2011 at 11:37 PM, Ankur Khurana

Re: [algogeeks] C output 3

2011-07-29 Thread prashant bhutani
fffe is two's complement of 2. Let me explain for fe and you can extrapolate it with other f's. f =15, e =14. fe = 1110, ~fe = 0001, ~fe+1 = 0010 = 2 which gives your answer. Thanks Regards, Prashant Bhutani Senior Undergraduate Computer Science Engineering (B.Tech) Institute of

[algogeeks] C output

2011-07-28 Thread Aman Goyal
#include‹stdio.h› main() { struct xx { int x; struct yy { char s; struct xx *p; }; struct yy *q; }; } ouput: compiler error. Any logical reasons? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] C output

2011-07-28 Thread aditi garg
well im not sure bt i guess one possible reason could be that struct yy is a member of struct xx..so a pointer of struct yy cannot be declared widout ref to xx... On Wed, Jul 27, 2011 at 9:52 PM, Aman Goyal aman.goya...@gmail.com wrote: #include‹stdio.h› main() { struct xx { int x; struct

Re: [algogeeks] C output

2011-07-28 Thread Prem Krishna Chettri
Well, this is quiet obvious even the least follower of C struct can answer it but the good part is why does compiler is design to do so.. Hope ppls do follow me in this activation rec.. yy *q struct yy (defined in somewhere) x.. Guys above notation is in stack so srry again for no

[algogeeks] C output 2

2011-07-27 Thread Ankur Khurana
if i declare a string constant inside another function like let us say , int how() { char *s=hello; return s; } so when how() get executed , the memory for hello will remain reserved or it can be allocated to others. Will it amount to memory leak ? -- Ankur Khurana Computer Science Netaji

Re: [algogeeks] C output

2011-07-26 Thread Anika Jain
a is a pointer to somewhere where string is written.. p is a pointer to somewhere where new sring is written. temp is made to point at same location to which a is currently pointing that is at string by malloc some new memory is alloted and a is made to point to thast memory.. temp remains to

[algogeeks] C output.

2011-07-26 Thread Ankur Khurana
#includeiostream #includestring.h using namespace std; #define N(e) e#e int main() { int i=1,j=2,k=3; int m = i++ || j++ k++; couti j k m; } output :-2 2 3 1 http://www.ideone.com/0sKBr can anybody explain ? why are ++j and ++k are not evaluating even though operator should be evaluated

Re: [algogeeks] C output.

2011-07-26 Thread rajeev bharshetty
Replace || by and then j and k will get evaluated. The thing is that i think when the compiler sees a || operator ,if the first operand is true than it wont check for the second.Thus j and k are not getting evaluated. On Tue, Jul 26, 2011 at 2:46 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote:

Re: [algogeeks] C output.

2011-07-26 Thread Nitish Garg
This will be evaluated as i++ || (j++ k++) as gets the priority, so i will get incremented to 2. As the left hand side of || is true, the result is true and so the right hand side won't get evaluated. -- You received this message because you are subscribed to the Google Groups Algorithm

Re: [algogeeks] C output.

2011-07-26 Thread Jnana Sagar
exactly what nithish has stated is the reason..as all the programming languages uses short circuit method of evaluation for the relational statements..as the right side expression of the 'or' is true..it doesn't evaluate the left side expression, because now the left side expression doesn't affect

Re: [algogeeks] C output.

2011-07-26 Thread Ankur Khurana
but in precedence order || . Checked the same in dennis ricthie. On Tue, Jul 26, 2011 at 2:53 PM, rajeev bharshetty rajeevr...@gmail.comwrote: Replace || by and then j and k will get evaluated. The thing is that i think when the compiler sees a || operator ,if the first operand is true

Re: [algogeeks] C output.

2011-07-26 Thread Someshwar Chandrasekaran
On Tue, Jul 26, 2011 at 2:56 PM, Ankur Khurana ankur.kkhur...@gmail.com wrote: but in precedence order || . Checked the same in dennis ricthie. and || both have the same precedence. There is a shorthand pattern of evaluation for the expressions. learning that will help Regards, B.C.Someshwar

Re: [algogeeks] C Output

2011-07-26 Thread swetha rahul
Dipankar, Thanks!!! On Tue, Jul 26, 2011 at 8:44 AM, Dipankar Patro dip10c...@gmail.com wrote: Swetha, '\' in C is used to denote a escape sequence in C strings (and also in many other languages). e.g '\n' is for New Line '\n' is counted as one character. Now '\ooo' is for an ASCII in

Re: [algogeeks] C Output

2011-07-26 Thread aditi garg
what will be the output fr this?? printf(ab\c); On Tue, Jul 26, 2011 at 6:22 PM, swetha rahul swetharahu...@gmail.comwrote: Dipankar, Thanks!!! On Tue, Jul 26, 2011 at 8:44 AM, Dipankar Patro dip10c...@gmail.comwrote: Swetha, '\' in C is used to denote a escape sequence in C strings

Re: [algogeeks] C Output

2011-07-26 Thread Ram CEG
op:abc.. \c is not an escape sequence On Tue, Jul 26, 2011 at 10:17 PM, aditi garg aditi.garg.6...@gmail.comwrote: what will be the output fr this?? printf(ab\c); On Tue, Jul 26, 2011 at 6:22 PM, swetha rahul swetharahu...@gmail.comwrote: Dipankar, Thanks!!! On Tue, Jul 26, 2011 at

Re: [algogeeks] C Output

2011-07-26 Thread aditi garg
ya thats wat my doubt was...if its not a recognised escape sequence thn how is it interpreted?? Would the compiler jst ignore ''\''? On Tue, Jul 26, 2011 at 10:25 PM, Ram CEG honest...@gmail.com wrote: op:abc.. \c is not an escape sequence On Tue, Jul 26, 2011 at 10:17 PM, aditi garg

Re: [algogeeks] C Output

2011-07-26 Thread Vivek Srivastava
Yes compiler always ignores the first '\' and if it finds a recognizable character after this escape sequence . it will interpret it. Otherwise it just dumps it according to predefined semantics of machine code generation.But I would suggest everyone in this group to try out http://www.codepad.org

Re: [algogeeks] C Output

2011-07-26 Thread Ram CEG
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?? Would the compiler jst ignore ''\''? On Tue, Jul 26, 2011 at 10:25 PM, Ram CEG

Re: [algogeeks] C output.

2011-07-26 Thread Anurag Narain
@Someshwar: precedence of || http://www.difranco.net/cop2220/op-prec.htm -- 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] C OUTPUT

2011-07-25 Thread aditya kumar
main() { int i = 257; int *iPtr = i; printf(%d %d, *((char*)iPtr), *((char*)iPtr+1) ); } can any one explain me the o/p ?? -- 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

Re: [algogeeks] C OUTPUT

2011-07-25 Thread rajeev bharshetty
257 is stored as B A 0001 0001 So iptr if int* will be pointing to this above So if we typecast it as char* then it will point to 0001 (A) and *ptr+1 will point to 0001(B) Hope this clear . On Mon, Jul 25, 2011 at

Re: [algogeeks] C OUTPUT

2011-07-25 Thread Pankaj
Will not it depend on whether the machine is big or little endian? On Mon, Jul 25, 2011 at 11:50 AM, rajeev bharshetty rajeevr...@gmail.comwrote: 257 is stored as B A 0001 0001 So iptr if int* will be pointing to this

Re: [algogeeks] C OUTPUT

2011-07-25 Thread ~*~VICKY~*~
Consider the binary representation of 257 which is 10001 which will be stored in little endain representation as least significant eight bits + most significant eight bits as follows 0001 | 0001 now iptr on casting to char will point to least significant eight bits which is 1, when

Re: [algogeeks] C OUTPUT

2011-07-25 Thread aditya kumar
thnks all :) @rajeev : u are right dats y *((char*)iPtr+2) will printf 0. On Mon, Jul 25, 2011 at 11:56 AM, ~*~VICKY~*~ venkat.jun...@gmail.comwrote: Consider the binary representation of 257 which is 10001 which will be stored in little endain representation as least significant eight

Re: [algogeeks] C OUTPUT

2011-07-25 Thread Jagannath Prasad Das
depends on endianess of processor On Mon, Jul 25, 2011 at 12:22 PM, aditya kumar aditya.kumar130...@gmail.com wrote: thnks all :) @rajeev : u are right dats y *((char*)iPtr+2) will printf 0. On Mon, Jul 25, 2011 at 11:56 AM, ~*~VICKY~*~ venkat.jun...@gmail.comwrote: Consider the binary

Re: [algogeeks] C OUTPUT

2011-07-25 Thread varun pahwa
@Rajeev : little endian and big endian could create difference in the answers. On Mon, Jul 25, 2011 at 11:50 AM, rajeev bharshetty rajeevr...@gmail.comwrote: 257 is stored as B A 0001 0001 So iptr if int* will be

Re: [algogeeks] C OUTPUT

2011-07-25 Thread rajeev bharshetty
@Varun Ofcourse It Will !!! :) On Mon, Jul 25, 2011 at 11:54 AM, varun pahwa varunpahwa2...@gmail.comwrote: @Rajeev : little endian and big endian could create difference in the answers. On Mon, Jul 25, 2011 at 11:50 AM, rajeev bharshetty rajeevr...@gmail.comwrote: 257 is stored as

Re: [algogeeks] C OUTPUT

2011-07-25 Thread rajeev bharshetty
I was refering to the answer on my system which Little endian .. On Mon, Jul 25, 2011 at 5:11 PM, rajeev bharshetty rajeevr...@gmail.comwrote: @Varun Ofcourse It Will !!! :) On Mon, Jul 25, 2011 at 11:54 AM, varun pahwa varunpahwa2...@gmail.comwrote: @Rajeev : little endian and big endian

[algogeeks] C Output

2011-07-25 Thread swetha rahul
Hi, int main() { int a[5]={1,2,3,4,5}; int *ptr=a+1; printf(%d,*(ptr-1)); } It prints 5... Can somebody explain wats happening here..? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] C Output

2011-07-25 Thread kavitha nk
a points to the address of the next array...i.e base address+20.ptr-1 points to the last element of array...so it is 5. -- //BE COOL// kavi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] C Output

2011-07-25 Thread sagar pareek
here a is data type with 5*sizeof(int) so a+1 will give u next address just after the alloted whole array On Mon, Jul 25, 2011 at 7:44 PM, swetha rahul swetharahu...@gmail.comwrote: Hi, int main() { int a[5]={1,2,3,4,5}; int *ptr=a+1; printf(%d,*(ptr-1)); } It prints 5...

Re: [algogeeks] C Output

2011-07-25 Thread swetha rahul
int main() { int a[5]={1,2,3,4,5}; int *ptr=a; printf(%d,*(ptr)); getch(); } Then why this prints 1.. ?? On Mon, Jul 25, 2011 at 7:50 PM, sagar pareek sagarpar...@gmail.com wrote: here a is data type with 5*sizeof(int) so a+1 will give u next address just after the alloted

Re: [algogeeks] C Output

2011-07-25 Thread Someshwar Chandrasekaran
On Mon, Jul 25, 2011 at 8:20 PM, swetha rahul swetharahu...@gmail.com wrote: int main() {     int a[5]={1,2,3,4,5};     int *ptr=a;     printf(%d,*(ptr));     getch(); } Then why this prints 1.. ?? Here, ptr variable gets the starting address of the array 'a'. the starting address by

Re: [algogeeks] C Output

2011-07-25 Thread Nikhil Gupta
Here a refers to the starting address of the array (or the base address) So when you print *(ptr), it prints the value pointed to by ptr. On Mon, Jul 25, 2011 at 8:20 PM, swetha rahul swetharahu...@gmail.comwrote: int main() { int a[5]={1,2,3,4,5}; int *ptr=a; printf(%d,*(ptr));

Re: [algogeeks] C Output

2011-07-25 Thread sagar pareek
there's a lot diff b/w a and a+1. try to figure out what type of pointer ptr is ? yes its int* type so during assignment a will assign address of a and a+1 will give u address of sizeof(arr) * sizeof(int); but actually ptr is still int* type.. i hope u get it... On Mon, Jul 25, 2011 at 8:20 PM,

Re: [algogeeks] C Output

2011-07-25 Thread Vijay Khandar
ptr points to base addr of a.And on base adrr of a is 1.Assume base addr of a is 4000 then 1-4000,2-4002,3-4004,4-4006 and 5 on 4008 so op 1if in question asking *(ptr+2) then op is 3. Vijay.. On Mon, Jul 25, 2011 at 8:20 PM, swetha rahul swetharahu...@gmail.comwrote: int main() {

Re: [algogeeks] C Output

2011-07-25 Thread swetha rahul
Thanks all... Got it!!! On Mon, Jul 25, 2011 at 8:29 PM, Vijay Khandar vijaykhand...@gmail.comwrote: ptr points to base addr of a.And on base adrr of a is 1.Assume base addr of a is 4000 then 1-4000,2-4002,3-4004,4-4006 and 5 on 4008 so op 1if in question asking *(ptr+2) then op is 3.

[algogeeks] C Output

2011-07-25 Thread swetha rahul
char *s=\12345s\n; printf(\n %d,strlen(s)); The output is 5...?? But how.?? -- 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] C output

2011-07-25 Thread swetha rahul
*void main() *{* int i; char *a=String; char *p=New String; char *Temp; Temp=a; a=malloc(strlen(p) + 1); strcpy(a,p); p = malloc(strlen(Temp) + 1); strcpy(p,Temp); printf((%s, %s),a,p); free(p); free(a); } * * * * * *output is (New String,String)* * * *how does Temp retains String even after New

Re: [algogeeks] C Output

2011-07-25 Thread Dipankar Patro
Swetha, '\' in C is used to denote a escape sequence in C strings (and also in many other languages). e.g '\n' is for New Line '\n' is counted as one character. Now '\ooo' is for an ASCII in octal representation. here is the list of all escape sequences:

Re: [algogeeks] C OUTPUT HELP

2011-07-22 Thread Interstellar Overdrive
@nicks- Dev-cpp supports gcc compilers only. Just saying -- 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/-/tpDu2bt_tG8J. To post to this group, send email to

Re: [algogeeks] C output

2011-07-20 Thread chetan kapoor
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(); } .. 2. char c='a'; while(c!='b') { printf(%c,c); c=getchar(); }

Re: [algogeeks] c++ output

2011-07-17 Thread varun pahwa
@sourabh are you sure the code int main() { g(); f(); } inline int f(){ g(); return g()+1; } inline int g() { return 1; } does work i think i must give compilation error. Because a function need to be declared, before it is called in case of c++. and by inline the code in the function is

Re: [algogeeks] c++ output

2011-07-17 Thread Tushar Bindal
@varun you are contradicting your own statement when inline replaces the code at place where it is called, then this code will work fine. and the other one w/o inline won't as explained by others also. there seems to be some confusion in your statement. -- Tushar Bindal Computer Engineering

[algogeeks] C output problem

2011-07-17 Thread aditi garg
#includestdio.h #define FUN(arg) do\ {\ if(arg)\ printf(have fun...,\n);\ } while(i--) void main() {int i=2; FUN(i3); } A.have fun.. have fun.. have fun.. B.have fun..have

Re: [algogeeks] C output problem

2011-07-17 Thread Piyush Sinha
the output will be (b) before looking for the reason, you should know the syntax of printf *int printf(const char *format,)* the function at the string after the comma operator only if the format string aks for any format specifier like %d or %f etc...u can try it like this also in normal

Re: [algogeeks] C output problem

2011-07-17 Thread aditi garg
Thanks a lot :) On Mon, Jul 18, 2011 at 2:48 AM, Piyush Sinha ecstasy.piy...@gmail.comwrote: the output will be (b) before looking for the reason, you should know the syntax of printf *int printf(const char *format,)* the function at the string after the comma operator only if the

Re: [algogeeks] C OUTPUT AGAIN

2011-07-16 Thread sukhmeet singh
for problem1 you can use %hi or %hd .. while scanning .. On Thu, Jul 14, 2011 at 12:03 PM, Gaurav Jain gjainroor...@gmail.comwrote: @Nicks *Problem 1* %d is used to take a signed integer as input. To take a short integer as input, use %hi. That way, you would get the correct answer as 2.

Re: [algogeeks] C OUTPUT AGAIN

2011-07-16 Thread Kamakshii Aggarwal
@gaurav :y it is -2?y not +2? On Sat, Jul 16, 2011 at 2:13 PM, sukhmeet singh sukhmeet2...@gmail.comwrote: for problem1 you can use %hi or %hd .. while scanning .. On Thu, Jul 14, 2011 at 12:03 PM, Gaurav Jain gjainroor...@gmail.comwrote: @Nicks *Problem 1* %d is used to take a signed

Re: [algogeeks] C OUTPUT AGAIN

2011-07-16 Thread Nishant Mittal
value of b = 10 (in binary) and since b is a signed integer and also MSB is 1 so final value of b is 2's complement of 10 i.e. -2 On Sun, Jul 17, 2011 at 12:55 AM, Kamakshii Aggarwal kamakshi...@gmail.comwrote: @gaurav :y it is -2?y not +2? On Sat, Jul 16, 2011 at 2:13 PM, sukhmeet singh

Re: [algogeeks] C output

2011-07-15 Thread Sandeep Jain
This should help you out. http://msdn.microsoft.com/en-us/library/f90831hc.aspx Regards, Sandeep Jain On Fri, Jul 15, 2011 at 11:15 AM, abhishek kumar mailatabhishekgu...@gmail.com wrote: @Sandeep Jain sandeep, please be more clear about lvalue rvalue assignment. -- You received

[algogeeks] C output

2011-07-14 Thread abhishek kumar
hi friends, i have a doubt about this code. what will be its output and how. int a=35,*b; b=a; ++*b=++*b; -- 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] C output

2011-07-14 Thread Anika Jain
compilation error lvalue required coz on lhs of ++*b=++*b is not a variable but a value On Thu, Jul 14, 2011 at 11:58 AM, abhishek kumar mailatabhishekgu...@gmail.com wrote: hi friends, i have a doubt about this code. what will be its output and how. int a=35,*b; b=a; ++*b=++*b; --

Re: [algogeeks] C OUTPUT AGAIN

2011-07-14 Thread Gaurav Jain
@Nicks *Problem 1* %d is used to take a signed integer as input. To take a short integer as input, use %hi. That way, you would get the correct answer as 2. *Problem 2:* a:1 means that variable a is of width *1 bit* Similarly, b:2 means that b is of width *2 bits* b = 6 sets the two bits as 10,

Re: [algogeeks] C OUTPUT HELP

2011-07-14 Thread sagar pareek
@sandeep +1 for your answer of question 2 :) On Tue, Jul 12, 2011 at 8:57 AM, Sandeep Jain sandeep6...@gmail.com wrote: I'll put it in simple words, when printf is executed, it expects the arguments to be of the same type and in the same order as they appear in the format string. Otherwise,

Re: [algogeeks] C Output

2011-07-14 Thread sameer.mut...@gmail.com
1st problem format specifier is %d whereas memory is allocated only for short int memory allocated-2bytes. but being stored in 4bytes. so a is overwritten by b. In dis case where u give a=1, b=1, a becomes become 0. n so it gives:0+1=1 in d scanf if u use %hd instead u ll get d right output!!

Re: [algogeeks] C Output

2011-07-14 Thread Gaurav Jain
@Nicks *Problem 1* %d is used to take a signed integer as input. To take a short integer as input, use %hi. That way, you would get the correct answer as 2. *Problem 2:* a:1 means that variable a is of width *1 bit* Similarly, b:2 means that b is of width *2 bits* b = 6 sets the two bits as 10,

Re: [algogeeks] C Output

2011-07-14 Thread Anil Arya
@nicks ---solving 295c questions .good dude.. On Thu, Jul 14, 2011 at 8:01 AM, nicks crazy.logic.k...@gmail.com wrote: Hey Guys, plz help me in getting these 2 C output problems *PROBLEM 1.* * * *#*includestdio.h int main() { short int a,b,c; scanf(%d%d,a,b); c=a+b;

Re: [algogeeks] C output

2011-07-14 Thread Gaurav Jain
@Anika The code executes just all right. @Abhishek This is related to one of those irritating issues about precedence of operators. ++ and * have the same precedence and have right-to-left associativity. So your expression reads as ++(*b) = ++(*b) RHS evaluates to 36 which gets stored in (*b)

Re: [algogeeks] C Output

2011-07-14 Thread saurabh singh
then the version of spoj compiler for d must be belonging to an entirely different world.I have solved a few problems using D and it had entirely different syntax On Thu, Jul 14, 2011 at 9:39 AM, shilpa gupta shilpagupta...@gmail.comwrote: if you have any doubt than run it i have done

Re: [algogeeks] C Output

2011-07-14 Thread saurabh singh
ignore anything i wrote above.I am an idiot anyway. On Thu, Jul 14, 2011 at 2:42 PM, saurabh singh saurab...@gmail.com wrote: then the version of spoj compiler for d must be belonging to an entirely different world.I have solved a few problems using D and it had entirely different syntax

Re: [algogeeks] C output

2011-07-14 Thread Gaurav Jain
@Abhi Have a look at this. http://codepad.org/zMV45iFY On Thu, Jul 14, 2011 at 2:26 PM, Abhi abhi123khat...@gmail.com wrote: @gaurav jain: http://ideone.com/mRS9N lvalue is required as LHS of assignment operator is a constant 'value'. -- You received this message because you are

Re: [algogeeks] C output

2011-07-14 Thread T3rminal
@ all This code is error in C as pre-increment operator in C returns rvalue but it will work fine in C++ as it returns lvalue in C++ which is required as LHS of assignment operator -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this

Re: [algogeeks] C output

2011-07-14 Thread Sandeep Jain
Yup... *In C++* Pre-Increment Pre-Decrement return LValue Post-Increment Post-Decrement return RValue *In C* Pre-Increment Pre-Decrement return RValue Post-Increment Post-Decrement return RValue Regards, Sandeep Jain On Thu, Jul 14, 2011 at 4:08 PM, T3rminal piyush@gmail.com wrote:

Re: [algogeeks] C OUTPUT HELP

2011-07-14 Thread T3rminal
1) getchar must be a function in that case . Check /usr/include/stdio.h . It must have contained an extern definition (it is on my machine). 2) Machines generally have separate registers for floating point values(let say %fr). While executing this line *printf(%d\n,t); *that register is loaded

Re: [algogeeks] C output

2011-07-14 Thread abhishek kumar
@Gaurav Jain in turbo c++,(this was a c program). it is giving output 36. -- 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/-/uuO64oNqACMJ. To post to this

Re: [algogeeks] C output

2011-07-14 Thread Sandeep Jain
@ALL: Turbo C is one of the most pathetic compilers I've seen. It has tremendous skills to ruin your concepts. Regards, Sandeep Jain On Fri, Jul 15, 2011 at 10:35 AM, abhishek kumar mailatabhishekgu...@gmail.com wrote: @Gaurav Jain in turbo c++,(this was a c program). it is giving

Re: [algogeeks] C output

2011-07-14 Thread abhishek kumar
@Gaurav Jain but in Turbo C++ (as a c++ program) it is giving output a=36. -- 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/-/ORNJxARkBIoJ. To post to this

Re: [algogeeks] C output

2011-07-14 Thread abhishek kumar
@Sandeep Jain sandeep, please be more clear about lvalue rvalue assignment. -- 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/-/42bIvZNRPRYJ. To post to this

Re: [algogeeks] C Output

2011-07-13 Thread sanjay ahuja
For Problem 1, scanf tries to read 8 bytes from console (2 interger due to %d) and it starts writing in memory from right to left. since the variable are defined as short only two bytes will be stored. bytes read by scanf 0 0 0 1 0 0 0 1 from right to left first 2 bytes that will be stored to b

Re: [algogeeks] C Output

2011-07-13 Thread shilpa gupta
in second problem a:1 and b:3 means default initialization but not in c it is D programming language but u may b trying to compile it with c complier that's why it is showing wrong result..if u will compile it with D language compiler than it will print 6 and 2.and if u will not

Re: [algogeeks] C Output

2011-07-13 Thread saurabh singh
There is nothing wrong going wrong in the code shilpa. It specifies bit field a has now only 1 bit b has 2 bit. when u write t.a=6=(0110) it is stored as 0. while when u write t.b=2 it is stored as 10 which in 2's complement its -2. check size of t if you doubt me. On Thu, Jul 14, 2011 at 9:11

Re: [algogeeks] C Output

2011-07-13 Thread John Hayes
@saurabh why in 2's complement form ? On Thu, Jul 14, 2011 at 9:21 AM, saurabh singh saurab...@gmail.com wrote: There is nothing wrong going wrong in the code shilpa. It specifies bit field a has now only 1 bit b has 2 bit. when u write t.a=6=(0110) it is stored as 0. while when u

Re: [algogeeks] C Output

2011-07-13 Thread sanjay ahuja
For problem two the structure is bit field structure a:1 means only one lower order bit will be stored b:2 means only two lower order bits will be stored since both are defined as int (signed) t.b = 6 means 110, but 10 will be stored to b and being signed interger its value become -2 t.b = 7

Re: [algogeeks] C Output

2011-07-13 Thread shilpa gupta
@saurabh .u r right it is correct but thing i have written is also correct in D language it is initialization of elements of a structure but the correct ans for this question will be yours.. On Thu, Jul 14, 2011 at 9:21 AM, saurabh singh saurab...@gmail.com wrote: There is nothing

Re: [algogeeks] C Output

2011-07-13 Thread sanjay ahuja
because your type is int (signed) and not unsigned..make it unsigned you will understand why is like this! On Thu, Jul 14, 2011 at 9:27 AM, John Hayes agressiveha...@gmail.com wrote: @saurabh why in 2's complement form ? On Thu, Jul 14, 2011 at 9:21 AM, saurabh singh saurab...@gmail.com

Re: [algogeeks] C Output

2011-07-13 Thread John Hayes
thnx all...i finally got it :) On Thu, Jul 14, 2011 at 9:30 AM, sanjay ahuja sanjayahuja.i...@gmail.comwrote: because your type is int (signed) and not unsigned..make it unsigned you will understand why is like this! On Thu, Jul 14, 2011 at 9:27 AM, John Hayes agressiveha...@gmail.com

Re: [algogeeks] C Output

2011-07-13 Thread saurabh singh
By the way I am no master of D but isn't it compilation error? D was made to imitate java concept of importing librariesSo its a compile error anyway,:) On Thu, Jul 14, 2011 at 9:30 AM, sanjay ahuja sanjayahuja.i...@gmail.comwrote: because your type is int (signed) and not unsigned..make it

Re: [algogeeks] C Output

2011-07-13 Thread shilpa gupta
if you have any doubt than run it i have done so..it is running On Thu, Jul 14, 2011 at 9:38 AM, saurabh singh saurab...@gmail.com wrote: By the way I am no master of D but isn't it compilation error? D was made to imitate java concept of importing librariesSo its a compile error

[algogeeks] C Output

2011-07-13 Thread nicks
Hey Guys, plz help me in getting these 2 C output problems *PROBLEM 1.* * * *#*includestdio.h int main() { short int a,b,c; scanf(%d%d,a,b); c=a+b; printf(%d,c); return 0; } INPUT- 1 1 OUTPUT 1 i am not getting why 1 is coming in the output.what difference is using short making in the code

[algogeeks] C OUTPUT AGAIN

2011-07-13 Thread nicks
Hey Guys, plz help me in getting these 2 C output problems *PROBLEM 1.* * * *#*includestdio.h int main() { short int a,b,c; scanf(%d%d,a,b); c=a+b; printf(%d,c); return 0; } INPUT- 1 1 OUTPUT 1 i am not getting why 1 is coming in the output.what difference is using short making in the code

[algogeeks] C OUTPUT AGAIN

2011-07-13 Thread nicks
Hey Guys, plz help me in getting these 2 C output problems *PROBLEM 1.* * * *#*includestdio.h int main() { short int a,b,c; scanf(%d%d,a,b); c=a+b; printf(%d,c); return 0; } INPUT- 1 1 OUTPUT 1 i am not getting why 1 is coming in the output.what difference is using short making in the code

Re: [algogeeks] C OUTPUT HELP

2011-07-12 Thread Anand Saha
On Tue, Jul 12, 2011 at 1:29 AM, nicks crazy.logic.k...@gmail.com wrote: *PROBLEM 3.* * * #includestdio.h main() { enum {low='a',high='b'}tag; char try=low; printf(Size=%d,sizeof(tag)); switch (try) { case 'a':printf(aaa);break; case 'b':printf(bbb); case 'c':printf(ccc); }

<    1   2   3   >