Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 8 Online
OpenStudy (anonymous):

Consider the following c program #include #include void get_forest(int *str); main() { int field[80][80],i,j; for(i=0;i<80;i++) for(j=0;j<80;j+) field[i][j] = rand()%2; get_forest(field); } void get_forest(int *str) { printf("%d",*str); printf("%d",*(str+4)); } It seems that in get_forest the second print command cant print the actual value that means in this case field[3][0].How can I fix it?

OpenStudy (anonymous):

Python class, bro... Anyway, I think the second line would print out field[0][4]. If you want to print field[3][0], why not just replace that print statement with cout<<field[3][0] ? Much more reliable than pointer arithmetic.

OpenStudy (anonymous):

Thanks bro but I was wanting to do it with c and the Borland compiler did not give that expected result and I just want to know how I can access a string from another function using pointer arithmatic

OpenStudy (anonymous):

Try using a one-dimensional string Not sure how it would interpret pointer arithmetic in a 2D array, but did you try printing *(field+3*80) ?

OpenStudy (anonymous):

Thanks for that

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!