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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:37:19+00:00 2026-06-08T06:37:19+00:00

#include<stdio.h> int main(int argc , char *argv[]) { int array[2][2] = {{1,100},{1000,10000}}; int *pointer

  • 0
#include<stdio.h>
int main(int argc , char *argv[])
{
    int array[2][2] = {{1,100},{1000,10000}};

    int *pointer    = array;
    int *ppointer   = &array;
    int *pppointer  = array[0];
    int *ppppointer = &array[0];

    printf("%d\n",*pointer);
    printf("%d\n",*ppointer);
    printf("%d\n",*pppointer);
    printf("%d\n",*ppppointer);

    return 0;
}

Four pointers are point to the first element of array.
which definition shown above is better?
And I don’t known why the same value to array and &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-08T06:37:21+00:00Added an answer on June 8, 2026 at 6:37 am

    The only reason all for of your definitions compile is that your C compiler is too permitting when it comes to pointer type conversions. If you use some switches that make it more pedantic in this regard, it should immediately tell you that only the third initialization is valid, while the rest are erroneous.

    In most contexts (with a few exceptions) when array of type T[N] is used in an expression, it “decays” (gets implicitly converted) to pointer type T * – a pointer that points to its first element. In other words, in such contexts for any array A, the A expression is equivalent to &A[0]. The only contexts where array type decay does not occur are unary & operator, sizeof operator and string literal used as an initializer for a char array.

    In your example array is a value of int [2][2] type. When used on the right-hand side of initialization it decays to pointer type int (*)[2]. For this reason this is invalid

    int *pointer    = array;
    

    The right-hand side is int (*)[2], while the left-hand side is int *. These are different pointer types. You can’t initialize one with the other.

    The

    int *ppppointer = &array[0];
    

    is exactly equivalent to the previous one: the right-hand side produces a value of int (*)[2] type. It is invalid for the very same reason.

    The &array expression produces a pointer of int (*)[2][2] type. Again, for this reason

    int *ppointer   = &array;
    

    is invalid.

    The only valid initialization yo have in your example is

    int *pppointer  = array[0];
    

    array[0] is an expression of int [2] type, which decays to int * type – the same type that you have on the left-hand side.

    In other words there’s no question of which one “better” here. Only one of your initialization is valid, others are illegal. The valid initialization can also be written as

    int *pppointer  = &array[0][0];
    

    for the reasons I described above. Now, which right-hand side is “better” (array[0] or &array[0][0]) is a matter of your personal preference.


    In order to make your other initializations valid, the pointers should be declared as follows

    int (*pointer)[2]     = array;
    int (*ppointer)[2][2] = &array;
    int (*ppppointer)[2]  = &array[0];
    

    but such pointers will have different semantics from an int * pointer. And you apparently need int * specifically.

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

Sidebar

Related Questions

#include <stdio.h> int main(int argc, char *argv[]) { long* fp; while(1) { fp =
#include<stdio.h> #include<math.h> int main(int argc, char **argv){ // read in the command-line argument double
#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { if(argc != 2) return
#include<stdio.h> #include<zlib.h> #include<unistd.h> #include<string.h> int main(int argc, char *argv[]) { char *path=NULL; size_t size;
This code is giving me segfault : #include <stdio.h> int main(int argc,char** argv[]){ int
In the following code: #include<stdio.h> int main(int argc,char *argv[]){ int index; for(index = 0;
Here's what I have: #include <stdlib.h> #include <string.h> #include <stdio.h> int main(int argc, char
#include vss.h #include vswriter.h #include <VsBackup.h> #include <stdio.h> #define CHECK_PRINT(result) printf(%s\n,result==S_OK?S_OK:error) int main(int argc,
I wrote a simple C program: #include <unistd.h> #include <stdio.h> int main( int argc,
stattest.c: // compile: gcc -o stattest stattest.c #include <stdio.h> #include <sys/stat.h> int main(int argc,

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.