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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:19:16+00:00 2026-06-10T07:19:16+00:00

Possible Duplicate: Allocate memory for 2D array with minimum number of malloc calls As

  • 0

Possible Duplicate:
Allocate memory for 2D array with minimum number of malloc calls

As far my knowledge of concern in C void pointer is automatically converted into appropriated data type. Below is the program in which I found the warning:

initialization from incompatible pointer type [enabled by default]

#define ROW 3
#define COL 2

int main()
{

        void **ptr = malloc( ROW*COL* sizeof(int) );

        int (*p)[COL] = ptr;

        int i, j;

        for( i = 0; i < ROW; ++i )
                for( j = 0; j < COL; ++j )
                        scanf("%d", &p[i][j]);

        for( i = 0; i < ROW; ++i )
        {
                for( j = 0; j < COL; ++j )
                        printf("%d ", p[i][j]);
                printf("\n");
        }
        free(ptr);
        return 0;
}

but it worked perfectly. If void** pointer is type casted into a “pointer to a COL size integer array” then it’s behavior should change and behave like 2D array?

  • 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-10T07:19:17+00:00Added an answer on June 10, 2026 at 7:19 am

    Firstly, void ** pointer is not a void * pointer. void ** and void * are two completely different types. Whatever conversion properties apply to void * don’t apply to your ptr. Your initialization is indeed invalid, as compiler told you in the warning message.

    Secondly, there’s absolutely no need for a void ** pointer in your program. Where did it come form anyway? If you wanted to have an “intermediate” pointer ptr in your program, you should have declared it with void * type

    void *ptr = malloc(ROW * COL * sizeof(int));
    int (*p)[COL] = ptr;
    

    and the warning would disappear. However, as I said in my previous answer, there’s no real need for any intermediate pointer in this case. You can just do

    int (*p)[COL] = malloc(ROW * sizeof *p);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: When you exit a C application, is the malloc-ed memory automatically freed?
Possible Duplicate: When you exit a C application, is the malloc-ed memory automatically freed?
Possible Duplicate: Why would you ever want to allocate memory on the heap rather
Possible Duplicate: Allowed memory size of 33554432 bytes exhausted (tried to allocate 43148176 bytes)
Possible Duplicate: C++: why is new needed? Why cant I use malloc to allocate
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: C programming, why does this large array declaration produce a segmentation fault?
Possible Duplicate: Create new C++ object at specific memory address? I am writing what
Possible Duplicate: c difference between malloc and calloc Please explain the significance of this
Possible Duplicate: std::string and its automatic memory resizing I am just curious, how are

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.