Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8130909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:54:25+00:00 2026-06-06T08:54:25+00:00

I have an example involving a pointer to a 2D array. Can someone help

  • 0

I have an example involving a pointer to a 2D array. Can someone help me understand what is going on in this example?

int main()
{

    int i = 0, j=0, sum0=0, sum1=0;
    int data[4][3] = { {23,55,50},{45,38,55},{70,43,45},{34,46,60}};
    int *Ptr;
    Ptr = *data;    //Why is the indirection operator used here? 
                    // Does Ptr = 23 by this assignment?

    for (i=0; i<4; i++) {
        sum1 = 0;
        for (j = 0; j < 3; j++) {
            sum1 += data[i][j];
        }
        if (sum1 > sum0) {
                 sum0 = sum1;
                 Ptr = *(data + i);     // Seems like this statement makes Ptr
        }                               // point one row below ... what syntax
    }                                   // can you use to access columns then?
                                       // Is it possible to use pointer arithmetic
    for (i=0; i<3; i++)                 // to access elements of data[i][j] that
        printf("%d\n", Ptr[i]);          // are not at j = 0?

  return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T08:54:26+00:00Added an answer on June 6, 2026 at 8:54 am

    data is a 2 dimentional array, which has 4 rows and each row has 3 elements (ie 4 X 3).

    Now, Ptr = *data; means you are storing the starting address of 1st row to the pointer variable Ptr. This statement is equivalent to Ptr = *(data + 0). Ptr = *(data + 1) – this means we are assigning 2nd row’s starting address.

    Then *Ptr or *(Ptr + 0) will give you the value of the first element of the row to which is pointing. Similarly, *(Ptr + 1) will give you the value of the second element of the row.

    The for loop in your program is used to identify which row has the maximum value of the sum of its elements (3 elements). Once the control comes out of that for loop, Ptr will be pointing to the row which has the maximum sum of its elements and sum0 will have the value of the sum.

    Consider an array int a[5];, I hope you know that a[0] and 0[a] is the same. This is because a[0] means *(a+0) and 0[a] means *(0 + a). This same logic can be used in 2 dimensional array.

    data[i][j] is similar to *(*(data + i) + j). We can write it as i[data][j] also.

    For more details please refer to the book "Understanding Pointers in C" by Yashavant Kanetkar.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem involving setinterval. It's probably best to show an example so
I have a question today involving the StreamReader class. Specifically initializing this class using
If you have a complex SQL query involving many joins (for example returning Articles
Suppose that we have this code (simplified example): $propertyName = 'items'; $foo = new
I have example.org and foo.example.org pointing to the same directory, /var/www/html/ , and want
Anyone have example Rx code that shows how to execute an action due to
I have example: for line in IN.readlines(): line = line.rstrip('\n') mas = line.split('\t') row
If I have example.com/dir and dir is basically a folder in the example.com server,
Anyone have an example snippet showing how to scale a Font using AffineTransform? Thanks.
I have an example in C# code, but it is using streamWriter . It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.