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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:42:52+00:00 2026-06-05T18:42:52+00:00

I created a 2-D matrix using double pointer like that: int** pt; pt =

  • 0

I created a 2-D matrix using double pointer like that:

int** pt; pt = (int*) malloc(sizeof(int)*10);

I know that a pointer is freed like that

free(ptr);

How can we free the double pointer?

What if we print something and later freed that memory and exit the program? Does the final memory consist of that which we used or it will be same as initial?

  • 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-05T18:42:54+00:00Added an answer on June 5, 2026 at 6:42 pm

    Say you have a matrix mat

    int** mat = malloc(10 * sizeof(int*));
    for (int i=0; i<10; ++i) {
      mat[i] = malloc(10 * sizeof(int));
    }
    

    then you can free each row of the matrix (assuming you have initialized each correctly beforehand):

    for (int i=0; i<10; ++i) {
      free(mat[i]);
    }
    

    then free the top-level pointer:

    free(mat);
    

    For your second question: if you allocate memory and use it, you will change that memory, which will not be “reverted” even if you free it (although you will not be able to access it reliably/portably any more).

    Note: the top-level malloc is using sizeof(int*) as you are allocating pointer-to-ints, not ints — the size of int* and int are not guaranteed to be the same.

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

Sidebar

Related Questions

Using JavaScript, how do I create an HTML table that can "accept" numeric matrix
I have created the following type using implicit type construction: open System type Matrix(sourceMatrix:double[,])
I want to create images like this from a double precision matrix using MATLAB.
I recently created a generic Matrix<T> class that acts as a wrapper around a
When I create a matrix using Eigen, like this: Eigen::MatrixXd M(3,3); M<< 1.0, 4.0,
I have created a sparse matrix using MEX and also created a sparse matrix
I've created a class that can be parameterised by anything that can be converted
I've created the following matrix in R: positions = cbind(seq(from = 20, to =
I have created a 2x2 matrix of 2x2 matrices: a = matrix([[matrix([[ 1, 2],
I am trying to create a matrix that is 3 x n, with each

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.