GeeksforGeeks » C/C++ Programming Questions

Why does this program give error?

(3 posts)

Tags:

  1. Himanshu
    guest
    Posted 1 year ago #

    #include<stdio.h>
    int main()
    {
      int x[10];
      int (*p)[10];
      p = x;
      getchar();
      return 0;
    }
    
  2. mario
    Member
    Posted 1 year ago #

    I think you cant direct assign a integer array to pointer unlike character array, try p = &x. This will work I believe.

  3. Himanshu
    guest
    Posted 1 year ago #

    yes, the following program works.

    #include<stdio.h>
    #include<stdio.h>
    int main()
    {
      int x[10] = {12, 13, 14};
      int (*p)[10];
      p = &x;
      printf("%d", (*p)[0]);
      getchar();
      return 0;
    }
    

    Thanks :)


Reply

You must log in to post.

RSS feed for this topic