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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:44:24+00:00 2026-06-15T12:44:24+00:00

int a = 10; int *p = &a; *p = 20; /* Is this

  • 0
int a = 10;    
int *p = &a; 

*p = 20;  /* Is this a valid statement? */

I understand that if I do int *p; and then if I do *p = 10 , it is invalid because I have not assigned any memory to p. However, I was wondering if initializing a pointer to some address allocates memory to that pointer or not?

  • 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-15T12:44:25+00:00Added an answer on June 15, 2026 at 12:44 pm
    int a = 10;    
    int *p = &a; 
    
    *p = 20;  /* Is this a valid statement? */
    

    The answer is YES in this particular case.

    But when you do like this :

    int *ptr;  //declaration of pointer variable
    *ptr = 20;  // It means you are assigning value 20 to the variable where `ptr` points to.
    

    But actually ptr is not pointing to anywhere, basically it means it has indeterminate value.

    so doing *ptr = 20 will put the value 20 to the memory address pointed to by ptr.
    So it’s called Undefined bahavior

    In you case it’s valid because &a is valid memory location and p started pointing to that variable when we do p= &a.

    so *p = 20 means actually changing or assigning the value of a using the pointer p.

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

Sidebar

Related Questions

I don't understand the output of this program: int arr[]={1,7,4,2,5,8}; int x=(&(arr[arr[1]-arr[4]])-arr); printf(%d ,x);
The following C++ is invalid because reference variables require initializers: int& a; // illegal
Is this code valid? int foo() { std::vector<std::string>& v = std::vector<std::string>(5, X); // Do
Equal Objects must have equal hashcodes. As per my understanding this statement is valid
In a C++ function like this: int& getNumber(); what does the & mean? Is
This is the C++ code: #include<iostream> using namespace std; int a=8; int fun(int &a)
From this code: int x = 5; int other = 10; vector<int*> v_ptr; v_ptr.push_back(&x);
int main() { int p; scanf(%d,&p); fun() { int arr[p]; // isn't this similar
Hopefully whoever reads this knows about default arguments: void setCase (string &str, int form
class A { int Avalue; A& operator=(A& copyMe) { Avalue = copyMe.Avalue; return *this;

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.