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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:03:38+00:00 2026-06-06T09:03:38+00:00

I was experimenting with array of pointers address calculation arithmetic.I got confused with the

  • 0

I was experimenting with array of pointers address calculation arithmetic.I got confused with the output of the above code.Could anyone explain whats happening?

void foo()
{
    int i=10,k=3,l=20,m=30;
    int *ary[2];
    ary[0]=&i;
    int b=20;
    ary[1]=&k;

    printf("%d\n",ary[0][1]);
}

Output is 3

Second program

void foo()
{
    int i=10,k=3,l=20,m=30;
    int *ary[2];
    ary[0]=&i;
    int b=20;
    ary[1]=&b;

    printf("%d\n",ary[0][1]);
}

Output is 20.

How is address calculation done in these above codes?

  • 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-06T09:03:39+00:00Added an answer on June 6, 2026 at 9:03 am

    In both code samples ary[0] is a pointer to a single integer. So when you do array[0][1] you’re accessing that pointer out of bounds. So the behavior of both of your code samples is undefined.

    The reason that you’re getting the behavior you’re seeing on your particular compiler is probably, that all the variables whose address you don’t take are stored in registers and not in memory (or possibly they aren’t stored at all because you never use them).

    So in example 1 the only variables in memory are i and k. And in example 2 the only variables in memory are i and b. So in example 1 k is the variables that comes directly after i in memory and example 2 that variable is b.

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

Sidebar

Related Questions

I'm experimenting on this code that I got from the net (I'm trying to
I've got an array like this array 2 => string 'Member forum 1' 5
gcc 4.4.4 c89 I was just experimenting with a int array. And something just
Experimenting with JsHelper in CakePHP 2.0, I got a Request method to update the
I'm experimenting with the Visual Studio 11 Dev Preview. I've got a problem domain
I have an array of a million integers because I am experimenting with parallel
I am experimenting with calling delegate functions from a delegate array. I've been able
I'm experimenting with the concept of pointer to multi-dimension array in C. Suppose I
I was just experimenting with the use of pointers when dealing with arrays and
I am experimenting with the Endicia shipping label server. The sample code below allows

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.