## Pointers box and circle diagram

box and pointer diagram
pointer diagram c++
c pointer diagram

Given the following Code

```int main()
{
int z;
int **x;
int * y;

x = (int**)malloc(sizeof(int*));
y = (int*)malloc(sizeof(int));
*y = 6;
*x = y; // Point 1
z = 3;
*x = &z; // Point 2
}
```

I am to draw box-and-circle diagrams of variables at point 1 and point 2.

Following is what i have got point 1.

Following is what i have got for point 2.

can anyone confirm if my approach is correct and my solution? sorry i am new to pointers and c.

Let's take this step by step. First, we reserve a few locations on the stack for the variables.

Next, allocate a small block the size of int pointer.

The newly allocated block should eventually be assigned an address of an int since X is a pointer to a pointer to an int. Next, allocate another small block.

Now put the address of y into the location pointed to by x

Lastly, assign 3 to z and change the value that x is pointing to, which will now be the address of z.

Hope this helps.

[PDF] Box-and-Pointer Diagrams, Discussion: Box-and-pointer diagrams help you trace by hand and understand code, especially code that features pointers (and/or arrays, which can be thought of  A box in a box & pointer diagram is formed by drawing a square. Two squares next to each other describes the object formed by using the constructor, cons . The orientation should be horizontal for clarity. Each square contains a pointer that points to something.

At point 1:

a. `y` contains the address of a dynamically allocated block of memory (let's call this "Block A") that contains the value `6`

b. `x` contains the address of a different dynamically allocated block of memory (let's call this "Block B"), and "Block B" contains the address of "Block A".

c. `z` is an uninitialized `int`

At point 2:

a. `y` is unchanged from point 1

b. `z` now contains the value `3`

c. `x` still contains the address "Block B", but "Block B" now contains the address of `z` rather than the address of "Block A".

Diagrammatically, where circles are variables with automatic storage duration (i.e. `x`, `y` and `z`) and rectangles are dynamically allocated blocks of memory:

CSE 340 9-23-15 Lecture: "Semantics Pt. 3", To use the box and pointer diagrammer, just type (view data). (define l The diagrammer will work for arbitrarily circular and complicated list structures. You can  The old pointer has thinned and darkened, but remains on the diagram. You can remove the 1 and the pointer to it by clicking Button-3 on the 1 or the pointer to it. When the mutation occured new data had to be put on the diagram. Since it would be difficult to pick a really good place to diagram new objects and cells, anything on the diagram is movable.

NO!! This should clear your doubt. Consider the `address(y)=300, address(z)=400. content(300)=6, content(400)=3`

`*x = y; // Point 1`

The above statement says that the content of pointer `x` will be the address of `y`. So the pointer x is pointing to pointer `y`. (i.e. `content(x)=300` )

`*x = &z; // Point 2`

The above statement says that the content of pointer `x` will be the address of `z`. So the pointer x is pointing to pointer `z`. (i.e. `content(x)=400` )

NOTE: In order to access the values you have to do `**x` which will finally access the values. We know that (*) is dereference operator. Now lets try to access the values using above terminology.

Point 1: `**x` => `*(*x)` => `*(address(y))` => `*(300)` => `content(300)` => 6.

Point 2: `**x` => `*(*x)` => `*(address(z))` => `*(400)` => `content(400)` => 3.

Box and Pointer Diagrams, To get the typewriter font: \mathtt{the text}; To create a box: \fbox{box} I think it could be worth mentioning that http://yuml.me/diagram/scruffy/class/draw can be a https://tex.stackexchange.com/questions/201071/how-do-i-make-tikz-circular-​  (It comes with free-hand circles!) \\$\endgroup\\$ – Simon Forsberg May 1 '14 at 21:01 1 \\$\begingroup\\$ Just a note: on my work computer I can't see any images linked in questions/answers on SE, but math jax works just fine.

I'm not wholly familiar with this, but x is of type pointer-to-pointer-to-int - two layers of indirection. Y is of type pointer-to-int - one layer. However, the diagram shows them both having the same indirection from the underlying storage. You do this for the second diagram where you take the address of z, but taking the address of z is the same level of indirection as assigning y to *x, as in both cases, you're telling x to point to a memory address that points directly to memory.

So in short, I think your "point 1" diagram should be similar to your "point 2" diagram, with x's "pointer box" pointing to y's "pointer box".

Edit: I'm also not sure about the "point 2" diagram in that it seems to imply that x is pointer-to-int, as its pointer points directly to z's memory - but it's been a long time since I've seen box-and-pointer diagrams (which this essentially seems to be) to know whether there's an alternative way to add that layer of indirection in. I actually think "Z" and "3" should be in the same box as in box-and-pointer diagrams, since z directly refers to the underlying storage.

How do I draw box-and-pointer diagrams?, Answer to //Pointer Semantics Questions //Box-Circle Diagram Questions //​Garbage Memory Questions //Dangling References Questions For the following code, draw a box-and-pointer diagram with a box for every activation record, field, and object in memory and the instant before the callMe method returns for the first time. Draw your diagram in the style used in the lectures and lecture notes.

//Pointer Semantics Questions //Box-Circle Diagram, Answer to Answer the following question on Pointer Semantics & Box-Circle Diagram: Assume stack memory allocation for nested scope box-and-pointer diagrams drawn in digital ink. The tool was designed to work with the Classroom Learning Partner presentation system. The interpreter was designed to use state of the art sketch recognition tools to recognize shapes, and state of the art text recognition tools to recognize text. Thesis Supervisor: Kimberle Koile, Ph.D.

Answer The Following Question On Pointer Semantics, Given the following C program, draw box-and-circle diagrams of the So at this line, z, *y, and **x are aliases since z isn't a pointer and has a  How to draw the box and pointer diagram for (define list8 (list (cons 3 4) (list 5 6))). From UMass Lowell's COMP.3010 Organization of Programming Languages class, spring 2017 semester.

Chapter 7, type Box is record len, wid: Integer := 0; end record; -- A type for pointers to boxes type BoxPtr Problem: Circular definition Diagram: useful to draw stack next to heap; A more accurate diagram: static at bottom, heap next, stack at other end. Draw the box-circle diagram for p and q at point 2. 6 FIRST sets FIRST sets are defined for terminals and non-terminals as well for a sequence of terminals and non-terminals. FIRST sets for terminals and non-terminals FIRST sets for non-terminals are calculated by applying the following rules repeatedly until no FIRST set changes.