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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:29:37+00:00 2026-05-23T13:29:37+00:00

Well, here is a full sample that works but the console vanishes right after

  • 0

Well, here is a full sample that works but the console vanishes right after the last print and i cant make it stay. Also there are a few queries that I include in some lines

//bidimensional array dynamic memory allocation

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

void main()

{
     int **p; // pointer to pointer
     int n,m,i,j,k; // n is rows, m is cols, i and j are the indexes of the array, k  is going to be like m, but used to print out

     do
     {
     printf("\n how many rows?");
     scanf ("\%d", &n);
     }
     while (n <= 0);

// booking memory for an array of n elements, each element is a pointer to an int (int *)

//Query: a pointer to an int? wouldnt it be a pointer to a pointer ? It uses **

     p = (int **) malloc (n * sizeof(int *)); // 
     if(p == NULL)
          {
          printf("Insuficient memory space");
          exit( -1);
          }

          for (i = 0; i < n; i++)  // now lets tell each row how many cols it is going to have
          {
              printf("\n\nNumber of cols of the row%d :", i+1); // for each row it can be different

              scanf("%d", &m); // tell how many cols
              p[i] = (int*)malloc(m * sizeof(int)); // we allocate a number of bytes equal to datatype times the number of cols per row

/Query: I cant grasp the p[i] because if p was a pointer to a pointer, what is that array notation, i mean the square brackets/

              if(p[i] == NULL)
              { printf("Insuficient memory space");
              exit(-1);
              }

              for (j=0;j<m;j++)
              {
                  printf("Element[%d][%d]:", i+1,j+1);
                  scanf("%d",&p[i][j]); // reading through array notation
              }

              printf("\n elements of row %d:\n", i+1);
              for (k = 0; k < m; k++)
              // printing out array elements through pointer notation
              printf("%d ", *(*(p+i)+k));
          }

              // freeing up memory assigned for each row
              for (i = 0; i < n; i++)
              free(p[i]);
              free(p);// freeing up memory for the pointers matrix

              getchar(); // it cannot stop the console from vanishing
              fflush(stdin); // neither does this
}

// ********thanks a lot******

  • 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-05-23T13:29:38+00:00Added an answer on May 23, 2026 at 1:29 pm

    it’s easy to understand pointers in context of arrays.
    So if

    int * p

    is the one-dimensional array of int, then int ** p will be two -dimensional array of int. In other words it is an array that containt a pointers to one-dimensional array.

    so

    p = (int **) malloc (n * sizeof(int *)); // 

    is a pointer to the pointer

    and p[i] is current pointer to the int.

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

Sidebar

Related Questions

I've asked at github , but will try asking here as well. Nothing wrong
This is just something I was wondering. Well here goes, Say I declare a
Extreme Android developer newbie here...well, new to Android development, not development in general. I
Well i am here writing some constraints for a db I am working on
Well i need some help here i don't know how to solve this problem.
Well, here's a nice obscure one. I'm trying to compile the latest open transport
Here is my code (well, some of it). The question I have is, can
Well, here is what I wanna do: I have a text field and a
Here's one from the No question's too dumb department: Well, as the subject says:
Well, this is my first post here and really enjoying the site. I have

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.