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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:05:42+00:00 2026-05-24T05:05:42+00:00

This is a newbie C++ pointer question. I have no clue on why this

  • 0

This is a newbie C++ pointer question. I have no clue on why this happen…

I found that if i write this code. It is totally valid.

Code1

int *j;    //create an pointer j
*j = 50;   //assign 50 to the *j, meaning value pointed by address 50 is xxx

However, when I wanna try to make it more simple. The compiler give me this error message.

Code2

int *j = 50; //i guess this should be the same with Code1...

Compile error

error: invalid conversion from ‘int*’ to ‘int’

So why would be like that?

  • 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-24T05:05:46+00:00Added an answer on May 24, 2026 at 5:05 am

    There’s a bit of ambiguity in the C syntax there.

    int *j = 50;
    

    is equivalent to

    int *j;
    j = 50;
    

    Actually, what you’re doing in the first snippet of code is dangerous because you haven’t allocated any memory for j before assigning a value to it yet. You’ll need to make memory for it like so:

    in C:

    int *j = (int*) malloc(sizeof(int));
    *j = 50;
    

    in C++

    int *j = new int;
    *j = 50;
    

    Or point the pointer at some other block of memory that’s already valid:

    int k;
    int *j = &k;
    *j = 50;
    printf("%d", k); // 50
    

    Edit: It’s worth pointing out that the ambiguity has to do with the ‘*’ symbol. In the declaration, int *j; the *j means “a pointer named j”. But when you’re using it in the second line “*j = 50”, * becomes the dereference symbol that means “the value at address j”.

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

Sidebar

Related Questions

Firstly: I am totally a newbie for this kind of work. I have a
This is a Fluent NHibernate newbie question, so bear with me. I have a
Sorry for this newbie question, but I can't find on google what I need
Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,
I'm really new to VSTO so sorry if this is a newbie question. I'm
This is a very newbie question and i will probably get downvoted for it,
this question is certainly newbie-generated. When I installed Apache and Passenger to work I
SSRS newbie question here... I have a table where one column is varbinary(max) data.
I am a newbie and I have a question with ABRecordSetValue in Xcode 4.2.
I'm a newbie to this site, so if I mess up any question-asking etiquette

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.