Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the explaination for this simple pointer program output
    primarykey
    data
    text
    <p>I tried to understand the size of address used to store variables and pointers, pointers-pointers and pointers-pointers-pointers. The results are kind of confusing. </p> <p>Here is the code:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;conio.h&gt; #include &lt;stdlib.h&gt; int main(void) { char *** ppptr_string = NULL; int *** ppptr_int = NULL; double *** ppptr_dbl = NULL; char c=0; int i=0; double d=0; printf("\n %d %d %d %d %d\n", sizeof(&amp;ppptr_string), sizeof(ppptr_string), sizeof(*ppptr_string), sizeof(**ppptr_string), sizeof(***ppptr_string)); printf("\n %d %d %d %d %d\n", sizeof(&amp;ppptr_int), sizeof(ppptr_int), sizeof(*ppptr_int), sizeof(**ppptr_int), sizeof(***ppptr_int)); printf("\n %d %d %d %d %d\n", sizeof(&amp;ppptr_dbl), sizeof(ppptr_dbl), sizeof(*ppptr_dbl), sizeof(**ppptr_dbl), sizeof(***ppptr_dbl)); printf("\n sizeof(char) = %d, sizeof(int) = %d, sizeof(double) = %d", sizeof(c), sizeof(i), sizeof(d)); printf("\n sizeof(&amp;char) = %d, sizeof(&amp;int) = %d, sizeof(&amp;double) = %d", sizeof(&amp;c), sizeof(&amp;i), sizeof(&amp;d)); getch(); return 0; } </code></pre> <p>Now the confusion. I can see that a variable address is always 2 bytes long on this machine. Regardless of type of the variable and regardless of the whether its a pointer variable. But why do I get size of 4 for so many entries in here? The pointer has size 4 always regardless of the type. The >address&lt; at which the variable is stored is of size 2. And the content pointed to has a sized depending on the type.</p> <p>Why do I get 4s in the output for sizeof??</p> <p>My output from Borland C++ 5.02 <img src="https://i.stack.imgur.com/uxKkM.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload