answersLogoWhite

0

What Pointer in Data Structure?

Updated: 8/10/2023
User Avatar

Wiki User

13y ago

Best Answer

No, pointer is not a data type but a reference to an object. Pointers are used to refer back to an object which can be anything from a large data value or a collection of values or objects.


A pointer is a variable and is 4 bytes long because 4 bytes = 32 bits, and all addresses in 32 bit operating systems are 4 bytes long :) , so if you want to store an address somewhere you need 4 bytes. A pointer is just 4 bytes in the memory and in these 4 bytes an address is stored.


If you ask the address of an element, like char, int, etc., the address you will get will be the address of the first byte. Only the first byte is saved in the pointer, and then you can manipulate the upcoming bytes.

For example you declare a structure of 12 bytes and you name it myStruct.
let's say that the address of this structure is the address 0x00400001 <- this is the 1st byte.
The second is 0x00400002 and so on till the 12th byte which is 0x0040000C.

Then you declare a pointer to point to myStruct like that:
myStruct *pointer;
The variable pointer is 4 bytes. It doesn't matter if the structure is 12 bytes or 100 bytes or 1 byte. The address of anything in 32-bit systems is always 4 bytes.
In this example the pointer variable contains the address of myStruct which is 0x00400001 <- the 1st byte of the structure.


The pointer might be a data structure because like any other data types, the pointer is always 4 bytes (in 32-bit systems). For 64bits systems which is 8 bytes, the pointers of a 32bit program would logically be the half of them empty like 0x00000000 00400001

User Avatar

Wiki User

7y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

struct S1 {

int fld;

};

struct S1 *p;

typedef struct S2 {

int fld;

} S2;

S2 *p;

typedef struct S3 {

int fld;

} S3, *S3PTR;

S3PTR p;

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

In a "single linked" linked list it is to point to the next node as the node, bear in mind that the only way to traverse from the previous node to the next node is the pointer, I guess you can kind of think of the data structure like a series of destinations only reachable by one way streets. This makes linked list have a higher big O complexity when retrieving elements, but it makes shifting / insertion much faster, because linked lists pointers can easily be moved.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

No, but you can define pointers to primitive (or any) stuctures.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

try this, and you will know:

int i;
pointer p;
double d;

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

It is not exactly a data-type, it is rather a data-type-constructor; for example pointer-to-integer is a data-type.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

For example the structure of a binary tree is often represented by pointers:

typedef struct TreeNode {

struct TreeNode *left, *right;

int Data;

} TreeNode;

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

A pointer is not a structure (primitive or otherwise).

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

void pointer can point to any data type, however each time it would require typecasting to be done for the appropriate type.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What Pointer in Data Structure?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the difference between structure and pointer?

A structure is a collection of primitives or other structures. A pointer is a memory address. Comparison of the two is like comparing bowling balls to cinder blocks. You can say that a structure defines the layout of the data, while a pointer points to data that is a particular structure.


What is difference between pointer and structures?

pointer data type that carry address:of data type that has no name but both of them must have same data type. structures you can make your own data type: struct name put any data type you wants any functions.


Meaning c plus plus pointer to an array and pointer to a structure?

They both mean the same thing; an array is a type of data structure (a linear structure). A pointer variable is just a variable like any other, but one that is used to specifically store a memory address. That memory address may contain a primitive data type, an array or other data structure, an object or a function. The type of the pointer determines how the data being pointed at is to be treated. Pointers must always be initialised before they are accessed, and those that are not specifically pointing at any reference should always be zeroed or nullified with the NULL value. This ensures that any non-NULL pointer is pointing at something valid. Remember that pointer variables are no different to any other variable insofar as they occupy memory of their own, and can therefore point to other pointer variables.


Are structures and pointers related in c plus plus?

Not really, but you can have: - a pointer pointing to a structure (FILE * is an example) - a pointer pointing to a structure-member (eg: struct tm tm; int *ip= &amp;tm.tm_year) - a structure-member that is a pointer (any type) Example: typedef struct TreeNode { struct TreeNode *left, *right; int data; } TreeNode; TreeNode *root = (TreeNode *)calloc (sizeof (TreeNode), 1);


What are the subject-matters of data structure?

types of data structure types of data structure

Related questions

What is the difference between structure and pointer?

A structure is a collection of primitives or other structures. A pointer is a memory address. Comparison of the two is like comparing bowling balls to cinder blocks. You can say that a structure defines the layout of the data, while a pointer points to data that is a particular structure.


How can you use pointer is data structure?

Your question makes no sense.


What is difference between pointer and structures?

pointer data type that carry address:of data type that has no name but both of them must have same data type. structures you can make your own data type: struct name put any data type you wants any functions.


What is an identify?

An identifier is nothing but a data type. It may variable, content, structure or a pointer.


Time taken to insert an element after an element pointed by some pointer in data structure?

O(n)


Meaning c plus plus pointer to an array and pointer to a structure?

They both mean the same thing; an array is a type of data structure (a linear structure). A pointer variable is just a variable like any other, but one that is used to specifically store a memory address. That memory address may contain a primitive data type, an array or other data structure, an object or a function. The type of the pointer determines how the data being pointed at is to be treated. Pointers must always be initialised before they are accessed, and those that are not specifically pointing at any reference should always be zeroed or nullified with the NULL value. This ensures that any non-NULL pointer is pointing at something valid. Remember that pointer variables are no different to any other variable insofar as they occupy memory of their own, and can therefore point to other pointer variables.


What is pointer to a member in objective c?

It is a pointer that points to a member of a structure.


What is uninitialised pointer?

A pointer is an address or the name for the location for an item of data. An uninitialised pointer is one that has not been assigned an initial value or item of data.


What happens if we use an integer pointer as a member of structure instead of structure pointer?

By declaring an integer pointer you are declaring that any non-zero reference stored in the pointer is guaranteed to be an integer reference. In order to guarantee the reference is actually a structure, the pointer must be declared as such, because casting an integer to a structure can never be regarded as being type-safe.


Can structure contain a pointer itself?

Yes a simple exp is the link list. struct node { int data; struct node *link; }


How can one create a pointer to structure in C?

Create a pointer of the type (pointer to struct) and assign the address of an instance of the structure to your pointer: typedef struct x { /* ... */ }; struct x my_structure; struct x* ptr = &amp;my_structure;


Are structures and pointers related in c plus plus?

Not really, but you can have: - a pointer pointing to a structure (FILE * is an example) - a pointer pointing to a structure-member (eg: struct tm tm; int *ip= &amp;tm.tm_year) - a structure-member that is a pointer (any type) Example: typedef struct TreeNode { struct TreeNode *left, *right; int data; } TreeNode; TreeNode *root = (TreeNode *)calloc (sizeof (TreeNode), 1);