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

  • Home
  • SEARCH
  • 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 1030963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T13:51:16+00:00 2026-05-16T13:51:16+00:00

I have the following program. However, I can’t understand why I have to pass

  • 0

I have the following program. However, I can’t understand why I have to pass the address of the array. When they are both pointing to the same address. Which is the address of the first element of the array of int’s.

I get a warning when I try and do this “assignment from incompatible pointer type”:

ptr = var;

Complete source code:

void print_values(int (*ptr)[5])
{
    size_t i = 0;
    for(i = 0; i < 5; i++) {
        printf("%d: [ %d ]\n", i, (*ptr)[i]);
    }
}

int main(void)
{
    /* declare a pointer to an array integers */
    int (*ptr)[5] = NULL;
    /* array of integers */
    int var[] = {1, 2, 3, 4, 5};
    /* assign the address of where the array is pointing to (first element) */
    ptr = &var;
    /* Both are pointing to the exact same address */
    printf("var  [ %p ]\n",(void*)var);
    printf("&var [ %p ]\n", (void*)&var);

    print_values(ptr);
    return 0;
}

I compile the code with gcc 4.4.4 c89 -Wall -Wextra -O0

  • 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-05-16T13:51:16+00:00Added an answer on May 16, 2026 at 1:51 pm

    It’s purely a type issue.

    In most expression contexts the name of an array (such as var) decays to a pointer to the initial element of the array, not a pointer to the array. [Note that this doesn’t imply that var is a pointer – it very much is not a pointer – it just behaves like a pointer to the first element of the array in most expressions.]

    This means that in an expression var normally decays to a pointer to an int, not a pointer to an array of int.

    As the operand of the address-of operator (&) is one context where this decay rule doesn’t apply (the other one being as operand of the sizeof operator). In this case the type of &var is derived directly from the type of var so the type is pointer to array of 5 int.

    Yes, the pointers have the same address value (the address of an arrays first element is the address of the array itself), but they have different types (int* vs int(*)[5]) so aren’t compatible in the assignment.

    ISO/IEC 9899:1999 6.3.2.1/4:

    Except when it is the operand of the sizeof operator or the unary & operator, or is a string literal used to initialize an array, an expression that has type “array of type” is converted to an expression of type “pointer to type” that points to the initial element of the array object and is not an lvalue. …

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

Sidebar

Related Questions

let us have a situation in which the following program prints some 10 lines
So I have the following program: https://github.com/eWizardII/homobabel/blob/master/Experimental/demo_async_falcon.py However, when it's run I only get
I currently have the following array in a Java program, byte[] data = new
I have the following program: ~/test> cat test.cc int main() { int i =
I have the following in a program (written in VB.NET): Imports Microsoft.Office.Interop.Excel Public Class
I have the following layout for my test suite: TestSuite1.cmd: Run my program Check
I have the following code: using System; using System.Linq; using System.Linq.Expressions; public class Program
I have the following code, which generates insert queries For Each f As String
I have a server to which multiple clients can connect to. The client is
I have the following function, which generates an integer in a given range: 18

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.