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 8339701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:57:10+00:00 2026-06-09T04:57:10+00:00

I have two structs pointers to pointers typedef struct Square { … … }Square;

  • 0

I have two structs pointers to pointers

typedef struct Square {
...
...
}Square;

Square **s1; //Representing 2D array of say, 100*100
Square **s2; //Representing 2D array of say, 200*200

Both are allocated on the heap using malloc().
I have s1 initialized with certain values and s2 initialized completely with the default values.
Basically I need to resize s1 to the size of s2 while maintaining its (s1) values, and the ‘added’ values would be just as they were in s2 – the default value.

I wrote this question memcpy() from smaller array to larger one but apparently I’m confusing between arrays and pointers/

My question is, how to implement this resizing of s1 to the size of s2. I don’t have to keep the original pointer. I can copy s1 to s2 and return s2 if that’s a better way
I hope I explained what I’m after properly.
Thanks!

  • 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-09T04:57:11+00:00Added an answer on June 9, 2026 at 4:57 am

    Two dimensional arrays are laid out in memory sequentially: row1 row2 row3 etc.

    memcpy does a linear copy from one memory location to another.

    So to achieve what you need:

    a) Create a new array

    Square **s3 = malloc(sizeof(s2));
    

    b) Copy s2 into it

    c) Copy stuff from s1, row by row into new

    for(r = 0; r < NROWS_S1; r++)
        memcpy(s3[r], s1[r], sizeof(Square) * NCOLS_S1);
    

    http://www.fredosaurus.com/notes-cpp/arrayptr/23two-dim-array-memory-layout.html

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

Sidebar

Related Questions

I have two objects both of the same type, for instance: typedef struct s_Object
I have a struct that contains two pointers, < head, iterator > both pointers
So, I have two structs: struct coordinate { float x; float y; } struct
In a C++ program I have two classes (structs) like struct A { int
I have two structs and I have an array of 30 pointer StudentType. I
I have a program that compares variables from two structs and sets a bit
The code is in C. I have two type of objects ( structs )
I have two window form applications written in C, one holds a struct consisting
I have a problem. There are two classes: struct Base { Base* retain() {
Hey I have a problem comparing the value of a CGPoint (struct with two

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.