[algogeeks] C Puzzle

2011-09-17 Thread teja bala
you have to print the list of all the files in a directory and all its sub directories? -- 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 ema

Re: [algogeeks] C Puzzle

2011-09-13 Thread Kapil Gupta
it should be like c=a than will give no error. On Tue, Sep 13, 2011 at 9:45 AM, bharatkumar bagana < bagana.bharatku...@gmail.com> wrote: > *a = 20; gives seg fault .. because 'a' has not been allocated memory > space... > > > On Mon, Sep 12, 2011 at 2:28 PM, Kunal Patil wrote: > >> Allocate mem

Re: [algogeeks] C Puzzle

2011-09-12 Thread bharatkumar bagana
*a = 20; gives seg fault .. because 'a' has not been allocated memory space... On Mon, Sep 12, 2011 at 2:28 PM, Kunal Patil wrote: > Allocate memory for pointer variables. > > > On Mon, Sep 12, 2011 at 11:03 AM, sukran dhawan wrote: > >> run time error >> first int * a is not assigned some addre

Re: [algogeeks] C Puzzle

2011-09-12 Thread Kunal Patil
Allocate memory for pointer variables. On Mon, Sep 12, 2011 at 11:03 AM, sukran dhawan wrote: > run time error > first int * a is not assigned some address... so it will be pointing to > some garbage value > second two pointers of different types without a typecast will result in > unpredictable

Re: [algogeeks] C Puzzle

2011-09-11 Thread sukran dhawan
run time error first int * a is not assigned some address... so it will be pointing to some garbage value second two pointers of different types without a typecast will result in unpredictable results On Mon, Sep 12, 2011 at 10:25 AM, teja bala wrote: > #include > main() > { > int *a; > char *c;

Re: [algogeeks] C Puzzle

2011-09-11 Thread teja bala
@Ishan it is giving segmentation fault ... wat it means? and can u plz correct d code... On Mon, Sep 12, 2011 at 10:30 AM, Ishan Aggarwal < ishan.aggarwal.1...@gmail.com> wrote: > *c = *a; > It will result in an run-time error. > > > On Mon, Sep 12, 2011 at 10:25 AM, teja bala wrote: > >> #inc

Re: [algogeeks] C Puzzle

2011-09-11 Thread Ishan Aggarwal
*c = *a; It will result in an run-time error. On Mon, Sep 12, 2011 at 10:25 AM, teja bala wrote: > #include > main() > { > int *a; > char *c; > *a = 20; > *c = *a; > printf("%d %c",*a,*c); > } > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks"

[algogeeks] C Puzzle

2011-09-11 Thread teja bala
#include main() { int *a; char *c; *a = 20; *c = *a; printf("%d %c",*a,*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, send email to algo

[algogeeks] C puzzle

2011-09-03 Thread teja bala
Find the output of the following code - plzzz xplain the o/p int find(int j) { if(j>1) { j=find(j/10)-(j%10); printf("%d",j); } else { j=0; } return j; } int main() { int i=19222; int k; k=find(i); } -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" g

Re: [algogeeks] C puzzle

2011-08-29 Thread Anup Ghatage
DO NOT use ideone for unix specific system calls. Granted that it is an online compiler but it is best to test unix specific system calls on unix itself.. Ok, so here goes. A few basics that need to be told before hand.. *fork() system call creates a child process, and returns its process id to

Re: [algogeeks] C puzzle

2011-08-29 Thread Kamakshii Aggarwal
http://ideone.com/o4r4o but it is calling red and green just two times each.. On Mon, Aug 29, 2011 at 11:06 PM, rajeev bharshetty wrote: > @Anup : I think you should also try to compile and check the answer... > May be I am wrong But compiler won't > > > On Mon, Aug 29, 2011 at 11:02 PM, Anu

Re: [algogeeks] C puzzle

2011-08-29 Thread teja bala
> > > @Anup > Can u pls explain the program ? -- 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...@googlegrou

Re: [algogeeks] C puzzle

2011-08-29 Thread rajeev bharshetty
@Anup : I think you should also try to compile and check the answer... May be I am wrong But compiler won't On Mon, Aug 29, 2011 at 11:02 PM, Anup Ghatage wrote: > @Rajeev: > > I had written down the recursion tree on paper but since you said that > there were 10 reds and greens, I compiled

Re: [algogeeks] C puzzle

2011-08-29 Thread Anup Ghatage
@Rajeev: I had written down the recursion tree on paper but since you said that there were 10 reds and greens, I compiled the code and checked it myself. I'm afraid you are wrong my friend. The correct answer is indeed 6 RED and 10 GREEN calls. -- Anup Ghatage -- You received this message bec

Re: [algogeeks] C puzzle

2011-08-29 Thread Kamakshii Aggarwal
@rajeev:can u pls explain? On Mon, Aug 29, 2011 at 10:09 PM, rajeev bharshetty wrote: > Each of the red and green are being called 10 times.. > > > On Mon, Aug 29, 2011 at 9:41 PM, Anup Ghatage wrote: > >> If I'm not mistaken, >> >> red() will be called 6 times and green() will be called 10 time

Re: [algogeeks] C puzzle

2011-08-29 Thread rajeev bharshetty
Each of the red and green are being called 10 times.. On Mon, Aug 29, 2011 at 9:41 PM, Anup Ghatage wrote: > If I'm not mistaken, > > red() will be called 6 times and green() will be called 10 times. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm

Re: [algogeeks] C puzzle

2011-08-29 Thread Anup Ghatage
If I'm not mistaken, red() will be called 6 times and green() will be called 10 times. -- 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 emai

[algogeeks] C puzzle

2011-08-29 Thread teja bala
void red() { } void green() { } main() { fork(); int color=fork(); if(color==0) fork(); red(); if(color==0) fork(); green(); getch(); } How many times red and green are called ? please explain it? -- You received thi

Re: [algogeeks] C puzzle

2011-04-08 Thread Balaji S
@pankaj: nice answer...well done..;) -- 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 m

Re: [algogeeks] C puzzle

2011-04-07 Thread pankaj agarwal
in fn1 ptr is pointer to integer i and you are changing content of i by using *ptr from 10 to 100 in fn ptr is pointer to integer i and you are changing pointer ptr by pointing to val(now ptr no more point to integer i).so here only pointer is changing not value. am i clear to you? On Fri, Apr 1

[algogeeks] C puzzle

2011-04-06 Thread navin
see this c code. #include void fn (int *ptr) { const int val=100; ptr=&val; } void fn1(int *ptr) { *ptr = 100; } main() { int i=10; printf("%d ", i); fn(&i); printf("%d ", i); fn1(&i); printf("%d ", i); } What is the difference betw

Re: [algogeeks] C puzzle

2010-10-13 Thread nidhi gupta
No const char * p is a pointer to a constant string, and is not itselves a constant pointer! On Sun, Oct 10, 2010 at 11:41 AM, Harshal wrote: > @Soumya > Typedef merely adds a new name for some existing type, here for char* type > in your code. > So instead you should write *typedef const char*

Re: [algogeeks] C puzzle

2010-10-09 Thread Harshal
@Soumya Typedef merely adds a new name for some existing type, here for char* type in your code. So instead you should write *typedef const char* char*p rather than *typedef char* char*p. bcoz you want new name for the whoole thinge (const char*), not just char*. -- You received this message beca

Re: [algogeeks] C puzzle

2010-10-09 Thread kusuma sanjeev
charp is not a textual replacement of char* since it is typedef. const charp p and charp const p are both equivalent to p being a constant pointer to character. On Sun, Oct 10, 2010 at 10:19 AM, Soumya Prasad Ukil wrote: > @kewat, > If it is const char*, then compilation won't give

Re: [algogeeks] C puzzle

2010-10-09 Thread Soumya Prasad Ukil
@kewat, If it is const char*, then compilation won't give error. But it is something like char *const. But how? On 10 October 2010 08:31, umesh kewat wrote: > Dear prasad > after pre-compiling the expression is like > > const char* p = &a, so now u can understand y its const poin

Re: [algogeeks] C puzzle

2010-10-09 Thread kusuma sanjeev
const char * => pointer to a const integer rt? Correct me if am wrong. On Sun, Oct 10, 2010 at 8:31 AM, umesh kewat wrote: > Dear prasad > after pre-compiling the expression is like > > const char* p = &a, so now u can understand y its const pointer > > > On Sun, Oct 10, 2010 at 1:07 AM, So

Re: [algogeeks] C puzzle

2010-10-09 Thread umesh kewat
Dear prasad after pre-compiling the expression is like const char* p = &a, so now u can understand y its const pointer On Sun, Oct 10, 2010 at 1:07 AM, Soumya Prasad Ukil wrote: > > #include > main() > { > char a ='c'; > typedef char* charp; > const charp p=&a; > p++; >

[algogeeks] C puzzle

2010-10-09 Thread Soumya Prasad Ukil
#include main() { char a ='c'; typedef char* charp; const charp p=&a; p++; } Why p is a constant pointer ? -- regards, soumya prasad ukil -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email