(TYPE*) POINTER
एक वाक्य रचना जो सूचक का एक प्रकार है-कलाकारों के रूप में व्याख्या की है है। उदाहरण के लिए,
int m = 4;
char* p_char = (char*)&m;
इस प्रकार, p_char
चार के लिए सूचक है। अगर हम p_char
, *p_char
को बाधित करते हैं, तो p_char
अंक की स्थिति में द्विआधारी प्रतिनिधित्व char
(वर्ण) के प्रतिनिधित्व में परिवर्तित हो जाएगा। इस मान का सटीक परिणाम अपरिभाषित है। मुझे नहीं पता कि यह कितना सटीक मूल्य लौटाएगा, लेकिन यह एक अजीब चरित्र č
की तरह कुछ वापस करेगा।
पॉइंटर की गहरी समझ के लिए, मैं जोर देना चाहता हूं कि एक सूचक केवल सी ++ भाषा में प्रदर्शित इकाई तक पहुंचने और कंप्यूटर मेमोरी पर रहने वाली इंटरफेस में से एक है।
#include <iostream>
using namespace std;
/*
* C++ interface to represent entity which resides on computer memory:
* ---------
* 1) object;
* 2) pointer;
* 3) reference;
*
* C++ interpretation of entity through interface: TYPE
* -------------- ----
*
* What is the function of TYPE?
* 1) tell compiler the size of an object of this TYPE needed; (sizeof(int) -> 4 bytes)
* 2) when the value of object at which it resides is dereferenced,
* the binary represented value is transformed to some other
* representation value according to the TYPE's interpretation rule; (if int, interpret it as an int)
*
*
* +----------------+
* | 0x02105207 |
* | 0x02105206 |
* | 0x02105205 |
* int n | 0x02105204 |
* +----------------+
* | 0x02105203 |
* | 0x02105202 |
* | 0x02105201 |
* ---->int m | 0x02105200 |
* | +----------------+
* | | |
* | +----------------+
* | ... ...
* | +----------------+
* ---- int* p | 0x00002298 |
* +----------------+
*
* if the pointer in figure is declared as:
*
* int* p = &m;
*
* the face of 0x00002298 -> 0x02105200 will not be changed until p is
* assigned to other address value;
*
*
*/
class consecutive_two_int
{
public:
consecutive_two_int():m(4),n(123){}
int m;
int n;
};
int main()
{
int * p;
consecutive_two_int obj;
p = &(obj.m);
for(int i = 0; i < 8; ++i)
{
// because pointer of char progresses every 1 byte;
// increment memory byte by byte through it;
cout << *(int*)((char*)p + i) << "\n";
}
return 0;
}
परिणाम, एक उदाहरण के रूप में, यह है:
4 // the first defined int
2063597568 // undefined
8060928 // undefined
31488 // undefined
123 // the second defined int
268435456 // undefined
1175453696 // undefined
-465170432 // undefined
आप प्रोसेसर जहां एक मैं/हे बंदरगाह एक विशिष्ट स्मृति पते में मैप किया गया है पर यह देखने, इसलिए जब आप पढ़ सकते हैं या 'PORTC' बारे में आप बाहरी डिवाइस के साथ जानकारी का आदान-प्रदान कर रहे हैं। –