fork(1) download
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdio.h>
  4. static char msg[]="Hi,HelLow World!";
  5. char * strValFunc(int pos){return &(msg[pos]);}
  6. double *doublePtrFunc(double * d){return d;}
  7. int charArgFunc(char ch){return ch;}
  8.  
  9. int main(void) {
  10. {//(1) :pattern "a(*b)[c];" : "double (*g)[*q];" : "char v=strValFunc(*q)[*r];"
  11. int p=3;
  12. int *q=&p;
  13. {
  14. double f[4][*q];
  15. double (*g)[*q]; //pattern "a(*b)[c];"
  16. f[2][1]=3.14;
  17. g=(void *)&f;
  18. (*g)[1]= (f[2][1]);
  19. printf("%g\n",(*g)[1]);
  20. }
  21. {
  22. int *r=q;
  23. char v=
  24. strValFunc(*q)[*r]; //pattern "a(*b)[*c];"
  25. printf("%c\n",v);
  26. printf("%d %c\n",*q,msg[3+3]);
  27. }
  28. }
  29. { //(2): pattern "a(*b(*c));" : "(double*) doublePtrFunc(*r);" : "double *yPtr=(double *) doublePtrFunc(*r);"
  30. double p=3.14159265;
  31. double *q= &p;
  32. double **r= &q;
  33. {
  34. (double*) doublePtrFunc(*r); //pattern a(*b(*c));"
  35. // g= & doubleFunc;
  36. printf("%g\n",*doublePtrFunc(&p));
  37. }
  38. {
  39. double *yPtr=
  40. (double *) doublePtrFunc(*r); //pattern a(*b(*c));
  41. printf("%g \n",*yPtr);
  42. }
  43. }
  44. { //(3): pattern "a(*b[c]);" : "char (*g[*q]);" : "int *r=q; char * strPtrArr[*q+1];"
  45. int p=3;
  46. int *q=&p;
  47. {
  48. // int val[*q*2]; // allocate void area. variable-sized object may not be initialized
  49. char (*g[*q]); //pattern "a(*b[c]);"
  50. g[1]= &msg[*q];
  51. printf("%c\n",(*g[1]));
  52. }
  53. {
  54. int *r=q;
  55. char * strPtrArr[*q+1];
  56. strPtrArr[*r]= (char *)&msg;
  57. int v=
  58. charArgFunc(*strPtrArr[*r]); //pattern "a(*b[*c]);"
  59. printf("%c\n",v);
  60. printf("%d %c\n",*q,msg[3+3]);
  61. }
  62. }
  63. {// pattern a[*b][*c];" 失格
  64. int m=3,n=4;
  65. int *p= &m,*q=&n;
  66. {
  67. int a= -1,b= -2, // 左記の宣言に続く、宣言文の一部
  68. integerDynamicArr[*p][*q]; //pattern a[*b][*c]; 完結した宣言文ではない
  69. int i,j;
  70. for(i=0;i<*p;i++)for(j=0;j<*q;j++) integerDynamicArr[i][ j]=100*i+j;
  71.  
  72. for(i=0;i<*p;i++){
  73. for(j=0;j<*q;j++) printf("%3d\t",integerDynamicArr[i][j]);
  74. printf("\n");
  75. }
  76. int u=
  77. integerDynamicArr[*p][*q]; //pattern a[*b][*c];"
  78. printf("%d %d %d \n",u,a,b);
  79. printf("%p %p %p %p %p \n",(void*)&integerDynamicArr[*p][*q],(void *)&a,(void *)&b,(void *)&i,(void *)&j);
  80. }
  81. }
  82. return 0;
  83. }
Success #stdin #stdout 0s 2112KB
stdin
Standard input is empty
stdout
3.14
L
3 L
3.14159
3.14159 
H
H
3 L
  0	  1	  2	  3	
100	101	102	103	
200	201	202	203	
0 -1 -2 
0xbfac9d30 0xbfac9d54 0xbfac9d50 0xbfac9d4c 0xbfac9d48