A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

Consider the following c program #include<stdio.h> #include<conio.h> 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?

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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) ?

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks for that

  5. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.