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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:18:48+00:00 2026-06-01T14:18:48+00:00

Hi all it’s been sometime since I’ve touched C so I’m really rusty on

  • 0

Hi all it’s been sometime since I’ve touched C so I’m really rusty on it. I wrote a small program to create a matrix using two dynamic arrays. However, I’m getting this warning and I don’t understand why? I guess I’m not quite sure about pointers to pointers. Can someone help me point out where my problem is? Thanks.

sm.c: In function ‘main’:
sm.c:11:13: warning: initialisation from incompatible pointer type [enabled by default]
sm.c: In function ‘makeMatrix’:
sm.c:27:3: warning: return from incompatible pointer type [enabled by default]


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

typedef int (**intptr) (); 
intptr makeMatrix(int n); 

int main(int argc, char *argv[]) {

  int n = 2;  

  int **A = makeMatrix(n);
  if(A) { 
    printf("A\n");
  }
  else printf("ERROR");
}

intptr makeMatrix(int size) {
  int **a = malloc(sizeof *a * size);
  if (a) 
  {
    for (int i = 0; i < size; i++)
    {   
      a[i] = malloc(sizeof *a[i] * size);
    }   
  }
  return a;
}
  • 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-01T14:18:49+00:00Added an answer on June 1, 2026 at 2:18 pm

    You’ve got some problems here:

    typedef int (**intptr) (); 
    intptr makeMatrix(int n); 
    
    ...
    
    int **A = makeMatrix(n);
    

    The intptr typedef declares a pointer to a pointer to a function that takes an indeterminate number of arguments and returns an int. A is not an int.

    You need to write:

    int **makeMatrix(int n);
    
    
    int **A = makeMatrix(n);
    

    Using a typedef won’t help much here.

    typedef int **(*intptr)();
    

    That declares a pointer to a function that returns a pointer to a pointer to an int. But writing

    intptr makeMatrix(int n);
    

    would declare that makeMatrix() returns a pointer to a function, not an int **.

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

Sidebar

Related Questions

All, I am building a small site using PHP. In the site, I receive
All the examples I've come across using Google Maps API seem to show a
All of the examples I've seen of using yield return x; inside a C#
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
All, I am trying to create a table to receive user inputs (UGC). This
All, I'm using wordpress with this and for some reason the eventDrop stopped working.
All I need is to create a file that contains a file names' list
All, I'm using Facebook Connect (JS SDK) to authenticate a user to my site.
All along I've been testing on an Android 2 version ported to x86 (which
all, I am trying to multiply a matrix to a vector in OpenGL, but

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.