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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:53:38+00:00 2026-06-15T20:53:38+00:00

When running the following, it keeps printing the same memory address. #include <stdio.h> int

  • 0

When running the following, it keeps printing the same memory address.

#include <stdio.h>

int array[5] = {2, 4, 6, 8, 10};
int *pointer;


int main()
{
        pointer = array;
        printf("%p:\t%d\n", pointer, *pointer);
        return 0;
}

I don’t know whether this is a problem, but I’m still curious to know why this would be the case, when declaring it within main() would keep returning new addresses.

  • 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-15T20:53:40+00:00Added an answer on June 15, 2026 at 8:53 pm

    The reason why you normally get the same address for “array” in the code you posted, but get different addresses if you declare array inside main, is that the array outside main has global scope and so is allocated in a single fixed location, whereas array if declared inside main is allocated on the stack when main is entered (and could conceivably be allocated several times if you called main from elsewhere).

    The security feature of randomizing addresses that is described in other answers applies to the stack, not to variables with static duration, because common exploits work by overwriting the stack with hostile code, then jumping to it by overwriting a return address, which is also stored on the stack. Overwriting a non-stack variable with hostile code still leaves the attacker the problem of executing it, and so is a lesser security concern.

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

Sidebar

Related Questions

I keep running into the following problem: (System.Console.ReadLine ()).Split [|'('; ')'|] |> Array.filter (fun
Running the following code: preg_match(/^top\-sites\-csv\_(.+)\_/i, $file, $matches); $site_id = $matches[1]; And it keeps generating
I'm running tomcat6 on centos 6, keeps getting the following error in the log
I'm trying to get http://www.gelens.org/code/gevent-websocket/ running and keep getting the following error. socket_id=1 already
I am running following LINQ query in order to group by CategoryID var test
I am running following code to create bmp image from pdf using Ghost4j i
I am running following query. SELECT T1.C1, T2.C2..., IF( T1.C1<>T2.C1,Changed,1) AS NewColumn From T1
I am running following query.. Select T1.* from T1 LEFT JOIN T2 ON T1.C1
I am running following query in SQL*Plus CREATE TABLE tbl_audit_trail ( id NUMBER(11) NOT
I'm getting unexpected output when running following code, DateFormat df = new SimpleDateFormat(YYYY-MM-dd); Date

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.