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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:44:07+00:00 2026-06-14T22:44:07+00:00

i’m using a pointer to pointer to intger as a 2 Dims array, i

  • 0

i’m using a pointer to pointer to intger as a 2 Dims array, i wrote these code but i failed on getting the integer value.

#include<stdio.h>
#include<conio.h>

void main(void)
{
    int **pptr = 0, size = 0, size2 = 0, i, j;

    clrscr();
    printf("Enter Size of Main Store n");
    scanf("%d", &size);

    pptr = (int **) malloc(size * sizeof(int *));

    printf("Enter Size of Sub Store n");
    scanf("%d", &size2);

    for (i = 0; i < size; i++) {
        pptr[i] = (int *) malloc(size2 * sizeof(int));
    }

    printf("Enter Values n");

    for (i = 0; i < size; i++) {
        for (j = 0; j < size2; j++) {
            scanf("%dn", pptr[i][j]);
        }
    }

    clrscr();
    printf(" Valuesn");

    for (i = 0; i < size2; i++, pptr++) {
        printf("%dn", *pptr + i);
    }

    getch();
}

it prints rubbish!!

  • 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-14T22:44:09+00:00Added an answer on June 14, 2026 at 10:44 pm

    scanf("%d", arg) expects a pointer to int, but

    for (i = 0; i < size; i++) {
        for (j = 0; j < size2; j++) {
            scanf("%dn", pptr[i][j]);
        }
    }
    

    you pass it an int, an uninitialised int at that. The indeterminate value in that memory location is then interpreted as a pointer, and the scan tries to store the converted value who-knows-where. It is not unlikely that that will cause a segmentation fault.

    You should pass &pptr[i][j] as the argument there.

    for (i = 0; i < size2; i++, pptr++) {
        printf("%dn", *pptr + i);
    }
    

    prints the int* *pptr +i, which is &pptr[0][i], using the %d format that expects an int argument.

    You should

    printf("%d\n", pptr[0][i]);
    

    if you want to print the values of the diagonal (as seems to be the case, since you also increment pptr in the loop), or, better

    for(i = 0; i < size && i < size2; ++i) {
        printf("%d\n", pptr[i][i]);
    }
    

    or, if you want to print the entire grid,

    for(i = 0; i < size; ++i) {
        for(j = 0; j < size2; ++j) {
            printf("%d ", pptr[i][j]);
        }
        printf("\n");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.