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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:45:38+00:00 2026-05-24T01:45:38+00:00

My questions are marked in code comments in the snippet below. int *foo(){ int

  • 0

My questions are marked in code comments in the snippet below.

int *foo(){
    int a = 10;
    int b = 20;
    return &b;
}
int *foo2(){
    int aa = 44;
    int bb = 40;
    return &bb;
}

int main(int argc, char* argv[])
{
    int *p = foo();
    int *p2 = foo2();

    int  a = 700;
    int *b = & a;

//  cout<<*b<<endl; /* what & why the difference from adding & removing this line?? */
    cout<<a<<endl;
    cout<<*p<<endl; /* what & why happened to "p" */

    return 0;
}
  • 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-24T01:45:39+00:00Added an answer on May 24, 2026 at 1:45 am

    In foo() and foo2() you are returning pointers to local variables. These locals have automatic storage and it is undefined behavior to use a pointer to them once they go out of scope. Therefor p and p2 contain nothing useful. It might work, it might not.

    I can’t understand your question very well, so I hope I got it all.

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

Sidebar

Related Questions

i wrote the following code.... #include< iostream> #include< fstream> using namespace std; int main()
Consider the following code, integral to my questions below: import functools N = 3
First, I noticed there are many questions regarding this, lots marked as duplicate. I
The questions says everything, take this example code: <ul id=css-id> <li> <something:CustomControl ID=SomeThingElse runat=server
I have few questions connected with struct and typedef, there is piece of code
Given this code: public class Messager implements Runnable { public static void main(String[] args)
Before I get marked as dupe of articles like: [http://stackoverflow.com/questions/635123/what-is-a-good-tool-or-site-to-use-to-performance-test-a-web-page-site][1] Most of the answers
Look at this django code: filtered = Question.objects.filter(children__marked=True).distinct() return Question.objects.exclude(id__in=filtered) It returns the list
I have this buffer given: unsigned char *buffer; int buffer_length; This is how I
I have code that looks like this: function foobar(array& $objects, $con = null) {

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.