answersLogoWhite

0

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

8y ago

What else can I help you with?

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);


Write a c program to insert an element in the beginning at the end at the specified position in a linear linked list?

#include&lt;stdio.h&gt; #include&lt;stdlib.h&gt; typedef struct Node { int data; struct Node *next; }node; void insert(node *pointer, int data) { /* Iterate through the list till we encounter the last node.*/ while(pointer-&gt;next!=NULL) { pointer = pointer -&gt; next; } /* Allocate memory for the new node and put data in it.*/ pointer-&gt;next = (node *)malloc(sizeof(node)); pointer = pointer-&gt;next; pointer-&gt;data = data; pointer-&gt;next = NULL; } int find(node *pointer, int key) { pointer = pointer -&gt; next; //First node is dummy node. /* Iterate through the entire linked list and search for the key. */ while(pointer!=NULL) { if(pointer-&gt;data == key) //key is found. { return 1; } pointer = pointer -&gt; next;//Search in the next node. } /*Key is not found */ return 0; } void delete(node *pointer, int data) { /* Go to the node for which the node next to it has to be deleted */ while(pointer-&gt;next!=NULL &amp;&amp; (pointer-&gt;next)-&gt;data != data) { pointer = pointer -&gt; next; } if(pointer-&gt;next==NULL) { printf("Element %d is not present in the list\n",data); return; } /* Now pointer points to a node and the node next to it has to be removed */ node *temp; temp = pointer -&gt; next; /*temp points to the node which has to be removed*/ pointer-&gt;next = temp-&gt;next; /*We removed the node which is next to the pointer (which is also temp) */ free(temp); /* Beacuse we deleted the node, we no longer require the memory used for it . free() will deallocate the memory. */ return; } void print(node *pointer) { if(pointer==NULL) { return; } printf("%d ",pointer-&gt;data); print(pointer-&gt;next); } int main() { /* start always points to the first node of the linked list. temp is used to point to the last node of the linked list.*/ node *start,*temp; start = (node *)malloc(sizeof(node)); temp = start; temp -&gt; next = NULL; /* Here in this code, we take the first node as a dummy node. The first node does not contain data, but it used because to avoid handling special cases in insert and delete functions. */ printf("1. Insert\n"); printf("2. Delete\n"); printf("3. Print\n"); printf("4. Find\n"); while(1) { int query; scanf("%d",&amp;query); if(query==1) { int data; scanf("%d",&amp;data); insert(start,data); } else if(query==2) { int data; scanf("%d",&amp;data); delete(start,data); } else if(query==3) { printf("The list is "); print(start-&gt;next); printf("\n"); } else if(query==4) { int data; scanf("%d",&amp;data); int status = find(start,data); if(status) { printf("Element Found\n"); } else { printf("Element Not Found\n"); } } } }

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)


What is heterogeneous linked list?

Heterogeneous Linked List is a linked list data-structure that contains or is capable of storing data for different datatypes.void pointer is basically used in these types of linked list as we are not sure of which type of data needs to be stored


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.


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 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;