dynamic define and allocate pointers
dynamic define and allocate pointers I want to dynamically define and allocate pointers: #include<stdio.h> #define def_var(type,name,i) type name##i #define var(name,i) name##i void main(){ int i; for (i=0;i<10;i++){ def_var(float,*ww,i)=NULL; } for (i=0;i<10;i++){ var(ww,i)=(float *)malloc(100); } } But when I compile it, lots of error come up. Can anybody help fix it? There is no point telling us there are errors if you don't include them in your question! But it's obvious the problem is that you're declaring variables in your first for loop and trying to use them in the second one. – Chris Turner Jun 29 at 15:50 for Also you're using malloc incorrectly. You need to specify the size in bytes of what you want to allocate, so to allocate 100 float you want malloc(si...
