DEV Community

CharmingAkashRaj
CharmingAkashRaj

Posted on

1 1

I am getting an error while compiling the c++ code, please help me out to fix this.

Alt Text

You can go through https://onlinegdb.com/Hy_FYU9JP to resolve the bug

Top comments (5)

Collapse
 
dwd profile image
Dave Cridland β€’

Waleed has the details, but you know you needn't cast this at all?

#include<iostream>
// #include<cstdlib>
/* You don't need that. */
using namespace std;

int main()
{
    int temp = 300;

    cout << "Address of variable temp:  " << &temp << std::endl;
    return 0;
}

That compiles fine, and will work, printing out the pointer address in Hex, as is normal.

As Waleed says, if you want it as an integer (and printed in traditional decimal), you need the integer type to be big enough. There's a std::intptr_t for this:

#include<iostream>
using namespace std;

int main()
{
    int temp = 300;

    cout << "Address of variable temp:  " << (std::intptr_t)&temp;
    return 0;
}
Collapse
 
charmingakashraj profile image
CharmingAkashRaj β€’

thanks, I got that 😊

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
charmingakashraj profile image

I just want to change the output as an integer and I am unable to debug this error, please help me out.

dev-to-uploads.s3.amazonaws.com/i/...

Collapse
 
charmingakashraj profile image
CharmingAkashRaj β€’

I am getting output in hexadecimal without using an unsigned keyword but , I just want to change output as an integer, can you tell me how to do this, and yes, my OS is a 64 bit.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay