[algogeeks] Re: is it correct??
Use sprintf(string, formatSpecifier, variable) instead u can even use %o %x for changing integer to corresponding oct and hex... -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: is it correct??
The behaviour of allowing the following code to compile: cin >> x; int a[x]; by gcc/g++ is due to historical reasons. This kind of a declaration is called a variable length array however it is not supported by the C++ and C standards. To prove that this is the case, recompile with g++ -pedantic You get: vla.cpp:8:9: warning: ISO C++ forbids variable length array ‘a’ -- DK -- 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/-/iRg-lRTKNLUJ. 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: is it correct??
Its from stack. Using int a[n] the amount of memory that can be allocated is very small as compared to that in case of using malloc( heap allocation ). On Wed, Jun 15, 2011 at 2:45 PM, sunny agrawal wrote: > @kartik sachan > This function is *not* defined in ANSI-C and is *not* part of C++, but is > supported by some compilers. > > and +1 to Shachindra's post...i also think memory allocation will be > from heap...not stack > > > On Wed, Jun 15, 2011 at 2:34 PM, Shachindra A C wrote: > >> @vipul : dynamic memory allocation from stack? are you sure? generally >> dynamic memory allocations are done from the heap right? >> >> >> On Wed, Jun 15, 2011 at 2:28 PM, kartik sachan >> wrote: >> >>> hey is itoa() is supported by g++ compliers??? >>> >>> -- >>> 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 options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >> >> >> >> -- >> Regards, >> Shachindra 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 >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > Sunny Aggrawal > B-Tech IV year,CSI > Indian Institute Of Technology,Roorkee > > > -- > 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 options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Regards, Vipul -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: is it correct??
@kartik sachan This function is *not* defined in ANSI-C and is *not* part of C++, but is supported by some compilers. and +1 to Shachindra's post...i also think memory allocation will be from heap...not stack On Wed, Jun 15, 2011 at 2:34 PM, Shachindra A C wrote: > @vipul : dynamic memory allocation from stack? are you sure? generally > dynamic memory allocations are done from the heap right? > > > On Wed, Jun 15, 2011 at 2:28 PM, kartik sachan wrote: > >> hey is itoa() is supported by g++ compliers??? >> >> -- >> 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 options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > Regards, > Shachindra 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 > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: is it correct??
@vipul : dynamic memory allocation from stack? are you sure? generally dynamic memory allocations are done from the heap right? On Wed, Jun 15, 2011 at 2:28 PM, kartik sachan wrote: > hey is itoa() is supported by g++ compliers??? > > -- > 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 options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Regards, Shachindra 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 algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: is it correct??
hey is itoa() is supported by g++ compliers??? -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: is it correct??
Its not a standard, it is one of the gcc extension i.e variable length arrays. Memory allocation is done dynamically from stack in such case. On Tue, Jun 14, 2011 at 8:27 PM, kartik sachan wrote: > it is correct ...in c++ 4.3.2 compiler > > -- > 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 options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Regards, Vipul -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: is it correct??
it is correct ...in c++ 4.3.2 compiler -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: is it correct??
but such a declaration is working correctly in g++ On Tue, Jun 14, 2011 at 8:22 PM, Don wrote: > One line or the other is not correct. The size of an array must be a > constant, and you can't read into a const. > If you want to do something like this, use malloc: > > cin >> x; > int *a = (int *)malloc(x*sizeof(int)); > > You can now use "a" as if it is an array of size x. Be sure to free > the memory before "a" goes out of scope. > > Don > > On Jun 14, 9:39 am, amit wrote: > > is such a declaration correct: > > cin>>x; > > int a[x]; > > -- > 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 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: is it correct??
One line or the other is not correct. The size of an array must be a constant, and you can't read into a const. If you want to do something like this, use malloc: cin >> x; int *a = (int *)malloc(x*sizeof(int)); You can now use "a" as if it is an array of size x. Be sure to free the memory before "a" goes out of scope. Don On Jun 14, 9:39 am, amit wrote: > is such a declaration correct: > cin>>x; > int a[x]; -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.