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

  • SEARCH
  • Home
  • 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 9195533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:38:53+00:00 2026-06-17T21:38:53+00:00

I was browsing a question and found this answer. I couldnt understand this program

  • 0

I was browsing a question and found this answer.

I couldnt understand this program at the end of the answer,
Specifically the first three lines of the putoff function

 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>

 #define NUM_ELEM(ar) (sizeof(ar) / sizeof((ar)[0]))

int * put_off(const int newrow[2])
{
static int mymatrix[3][2];
static int (*rowp)[2] = mymatrix;
int (* const border)[] = mymatrix + NUM_ELEM(mymatrix);

memcpy(rowp, newrow, sizeof(*rowp));
rowp += 1;
if (rowp == border) {
    rowp = mymatrix;
}

return *rowp;
 }

int main(int argc, char *argv[])
{
int i = 0;
int row[2] = {0, 1};
int *rout;

for (i = 0; i < 6; i++) {
    row[0] = i;
    row[1] += i;
    rout = put_off(row);
    printf("%d (%p): [%d, %d]\n", i, (void *) rout, rout[0], rout[1]);
}

return 0;
  }

I need some help with the first 3 lines in the function in the program.

  • 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-17T21:38:54+00:00Added an answer on June 17, 2026 at 9:38 pm

    Here are some explanatory notes to get you going:

    static int mymatrix[3][2];
    

    mymatrix is a 2D array of ints with 3 rows and 2 columns. C uses row-major order, meaning the rows are stored one after the other in memory. The static keyword makes its values persistent across function calls (while the scope is still local).

    static int (*rowp)[2] = mymatrix;
    

    This declares a pointer to array of two integers (i.e., a row of mymatrix in this case). Initializing it to mymatrix is the equivalent of initializing it to the first row. The static keyword of course means the same as above.

    int (* const border)[] = mymatrix + NUM_ELEM(mymatrix);
    

    border is a constant pointer (i.e., the pointer can’t be changed) to an array of ints. It is initialized to a memory address beyond mymatrix (which is maybe a tad unusual). Specifically, it points to the next row that would exist if mymatrix had one more row, so when the row pointer points to exactly that spot, the function wraps around the row pointer back to the first row having filled the entire matrix.

    For conglomerations of pointers, arrays parentheses, etc., you can always try cdecl to see if it can translate it for you.

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

Sidebar

Related Questions

I was browsing the web and found this site . I noticed how the
I'm sorry if this question has been asked before, I've tried googling/looking on here/browsing
This question sounds too trivial, but I could not find the answer anywhere. I
This question on my courswork that I could not understand. Q. The JAVA Language
While browsing questions and answers in this forum i found a piece of code
The issue I've found is very similar to this question , except that Safari
I found this code for a generic DAO interface while browsing around: public interface
EDIT: As it turns out when I was browsing I found a question the
Came across this one while browsing the response to another question on SO (
I was browsing Scott Hanselman's Developer Interview question list , and ran across this

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.