0
 #include<stdio.h>
    main()
    {
    int a[3][3]={1,2,3,4,5,6,7,8,9};
    int *p;
    p=a[0];printf("\nres:%d\n",*p); //here p points to a[0][0]
    p=a[1];printf("\nres:%d\n",*p); //here p points to a[1][1]
    p=a[2];printf("\nres:%d\n",*p); //here p points to a[2][2]
    p=a[12];printf("\nres:%d\n",*p); //here p points to garbage value
    }

how to access or point a[0][1] and other elements using only a[i] representation,what should the value of i be ?

1
  • p=a[0] + 1; //p points to a[0][1]. also p=a[1]; //p points to a[1][0], p=a[2]; //p points to a[2][0] Commented Apr 10, 2016 at 3:40

2 Answers 2

1
p=a[0];printf("\nres:%d\n",*p); //here p points to a[0][0]

Correct.

p=a[1];printf("\nres:%d\n",*p); //here p points to a[1][1]

Incorrect. p points to a[1][0].

p=a[2];printf("\nres:%d\n",*p); //here p points to a[2][2]

Incorrect. p points to a[2][0].

how to access or point a[0][1]

p = a[0];  // p points to a[0][0]
++p;       // Now p points to a[0][1]

You can also use:

p = &a[0][1];
Sign up to request clarification or add additional context in comments.

Comments

1
p = a[i] + i;//point to a[i][i]
p = a[i]; //point to a[i][0]

That's how to get the element of array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.