OK I'm a beginner at C++ so don't mock me for this question, so when I declare a pointer ptr (int *ptr; ) and then define ptr as 5 by saying *ptr=5; what adress is ptr pointing at-a temporary variable? Thank you-just curious.
CPPRULZ
0
Junior Poster in Training
Recommended Answers
Jump to PostQuick pointer answer: you DON'T DEFINE ptr pointer variable but use it.
int *ptr; // Now ptr has a garbage value (points to nowhere) int var; ptr = &var; // Now ptr points to var. *ptr = 5; // Now var has value 5.
Jump to PostYou have modified an unknown value in the memory, this is dangerous
All 5 Replies
ArkM
1,090
Postaholic
manzoor
2
Junior Poster in Training
Narue
5,707
Bad Cop
Team Colleague
CPPRULZ
0
Junior Poster in Training
JoBe
36
Posting Pro in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.