[algogeeks] array constant
Why it is showing an error at line number 5 1. void main() 2. { 3. clrscr(); 4. int i,max=5; 5. float arr[max]; 6. for(i=0;imax;i++) 7.scanf(%f,arr[i]); 8. getch(); 9.} -- 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] array constant
make max as a macro. as for c static memory allocation take place either with a constant or a macro. i.e. either u declare #define max 5 then write float arr[max]; or u may write float arr[5]; On Sat, Jul 30, 2011 at 1:05 PM, Arshad Alam alam3...@gmail.com wrote: Why it is showing an error at line number 5 1. void main() 2. { 3. clrscr(); 4. int i,max=5; 5. float arr[max]; 6. for(i=0;imax;i++) 7.scanf(%f,arr[i]); 8. getch(); 9.} -- 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. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- 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] array constant
or const int max=5; On Sat, Jul 30, 2011 at 1:09 PM, varun pahwa varunpahwa2...@gmail.comwrote: make max as a macro. as for c static memory allocation take place either with a constant or a macro. i.e. either u declare #define max 5 then write float arr[max]; or u may write float arr[5]; On Sat, Jul 30, 2011 at 1:05 PM, Arshad Alam alam3...@gmail.com wrote: Why it is showing an error at line number 5 1. void main() 2. { 3. clrscr(); 4. int i,max=5; 5. float arr[max]; 6. for(i=0;imax;i++) 7.scanf(%f,arr[i]); 8. getch(); 9.} -- 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. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- 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. -- Ankur Khurana Computer Science Netaji Subhas Institute Of Technology Delhi. -- 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] array constant
just adding to the concept.. this is not allowed since value of max may change during the program .. either by declaring it as a macro or as a const we (as said by ankur and varun ) restrict that the value from changing during the program ..!! On Sat, Jul 30, 2011 at 1:09 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: or const int max=5; On Sat, Jul 30, 2011 at 1:09 PM, varun pahwa varunpahwa2...@gmail.comwrote: make max as a macro. as for c static memory allocation take place either with a constant or a macro. i.e. either u declare #define max 5 then write float arr[max]; or u may write float arr[5]; On Sat, Jul 30, 2011 at 1:05 PM, Arshad Alam alam3...@gmail.com wrote: Why it is showing an error at line number 5 1. void main() 2. { 3. clrscr(); 4. int i,max=5; 5. float arr[max]; 6. for(i=0;imax;i++) 7.scanf(%f,arr[i]); 8. getch(); 9.} -- 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. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- 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. -- Ankur Khurana Computer Science Netaji Subhas Institute Of Technology Delhi. -- 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.
Re: [algogeeks] array constant
In GCC, its okay!! -- 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] array constant
yeah u can do any non executable statement before you declare the array.remove clrscr statement everything will be fine http://www.ideone.com/SpKpQ On Sat, Jul 30, 2011 at 1:16 PM, Bhanu Pratap Singh bp.mn...@gmail.comwrote: In GCC, its okay!! -- 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. -- Saurabh Singh B.Tech (Computer Science) MNNIT ALLAHABAD -- 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] array constant
If the value can change then do the memory initialization at run-time using malloc/calloc. The line 5 is giving error because the declaration of an array (and so the allocation of memory) happens at compile time, while the initialization of the variables happen when the program is loaded for the execution. In that case, you are asking compiler to allocate the memory but how much has to be decided at run-time, so the compiler throws an error! To make initializations, use compile time constants using const keyword or macros or giving the size by yourself.. Thanks Regards, Prashant Bhutani Senior Undergraduate Computer Science Engineering (B.Tech) Institute of Technology - BHU (IT-BHU) Varanasi-221005 On Sat, Jul 30, 2011 at 1:14 PM, sukhmeet singh sukhmeet2...@gmail.comwrote: just adding to the concept.. this is not allowed since value of max may change during the program .. either by declaring it as a macro or as a const we (as said by ankur and varun ) restrict that the value from changing during the program ..!! On Sat, Jul 30, 2011 at 1:09 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: or const int max=5; On Sat, Jul 30, 2011 at 1:09 PM, varun pahwa varunpahwa2...@gmail.comwrote: make max as a macro. as for c static memory allocation take place either with a constant or a macro. i.e. either u declare #define max 5 then write float arr[max]; or u may write float arr[5]; On Sat, Jul 30, 2011 at 1:05 PM, Arshad Alam alam3...@gmail.com wrote: Why it is showing an error at line number 5 1. void main() 2. { 3. clrscr(); 4. int i,max=5; 5. float arr[max]; 6. for(i=0;imax;i++) 7.scanf(%f,arr[i]); 8. getch(); 9.} -- 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. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- 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. -- Ankur Khurana Computer Science Netaji Subhas Institute Of Technology Delhi. -- 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. -- 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] array constant
If a compiler is compiling the code, simply means the compiler is intelligent enough to know what you want to do. But the language specifications, clearly explains not to do such things as these are non-portable!! Thanks Regards, Prashant Bhutani Senior Undergraduate Computer Science Engineering (B.Tech) Institute of Technology - BHU (IT-BHU) Varanasi-221005 On Sat, Jul 30, 2011 at 1:19 PM, saurabh singh saurab...@gmail.com wrote: yeah u can do any non executable statement before you declare the array.remove clrscr statement everything will be fine http://www.ideone.com/SpKpQ On Sat, Jul 30, 2011 at 1:16 PM, Bhanu Pratap Singh bp.mn...@gmail.comwrote: In GCC, its okay!! -- 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. -- Saurabh Singh B.Tech (Computer Science) MNNIT ALLAHABAD -- 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.