answersLogoWhite

0

Are pointers integers

Updated: 12/12/2022
User Avatar

Wiki User

15y ago

Best Answer

A pointer holds a memory address, from 0 to the upper limit of your memory (in 32 bit addressing this is up to 2^32, 64 bit is up to 2^64 bytes). So in math terms, a pointer could be considered a non-negative integer.

However this is not the same as the integer type used in C and other languages, which refers to how the data at that memory address (the raw bits) is interpreted by the system.

So the expression "int *x;" declares a pointer to an integer, but x is a memory address, not a literal C-style integer. The value pointed to by x, however, will be interpreted as a literal C-style integer.

It may be easier to see using a pointer to a char:

char character = 'C';

char *pointerToCharacter = character;

In this case, character is a standard char variable, and pointerToCharacter is a pointer (which is a memory address) that points to the location in memory of a character.

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Are pointers integers
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Why Two pointers cannot be added in c language?

Because no-one knows what the sum of two pointers should be...of course you can convert them to integers and then sum them, but why on earth would you do that?


What is the difference between handles and pointers?

They exist in different contexts. Handles are like... well handles (or keys, tickets, references etc), to access objects (like files, sockets, resources) you have opened (created, allocated, etc); in the program they can be integers or pointers.


Why array is a implicit pointer?

An array of pointers is exactly what it sounds like - one or more pointers arranged in order in memory, accessible through a common base name and indexed as needed. Philosophically, there is no difference between an array of pointers and an array of objects...int a[10]; // 10 integers, named a[0], a[1], a[2], ..., a[9]int *b[10]; // 10 pointers to int, named b[0], b[1], b[2], ..., b[9]If you initialize the array of pointers...int i;for (i = 0; i < 10; i++) b[i] = &a[i];... then *b[0] would be the same as a[0], etc.


Sort integer numbers in ascending order using pointers?

It's hardly the most efficient way to sort integers. Integers are primitive data types, so it's actually quicker to sort the integers directly rather than point at them. Pointers just add an unnecessary level of indirection. Pointers should only be used for complex data types for which copying/moving would result in greater inefficiency than would otherwise be incurred through pointer manipulation. #include&lt;iostream&gt; #include&lt;vector&gt; int main() { // instantiate a vector of unsorted integers std::vector&lt;int&gt; v = {7,3,5,2,9,4,1,6,8}; // instantiate a vector of pointers to the integers in the vector std::vector&lt;int*&gt; p; for (size_t i=0; i&lt;v.size(); ++i) p.push_back (&amp;v[i]); // sort the pointers (uses insertion sort algorithm): for (size_t i=1; i&lt;p.size(); ++i) { int* x=p[i]; size_t gap = i; size_t pre = i-1; while (gap &amp;&amp; *x&lt;*p[pre]) { p[gap--] = p[pre--]; } p[gap]=x; } // print to prove the sorting worked: std::cout &lt;&lt; "Original order:\t\t\t"; for (size_t i=0; i&lt;v.size(); ++i) std::cout &lt;&lt; v[i] &lt;&lt; '\t'; std::cout&lt;&lt;std::endl; std::cout &lt;&lt; "Sorted order (by pointer):\t"; for (size_t i=0; i&lt;p.size(); ++i) std::cout &lt;&lt; *p[i] &lt;&lt; '\t'; std::cout&lt;&lt;std::endl; }


What is the minimum number of additional pointers will be needed to reverse a singly linked list?

3 pointers...

Related questions

Which are the possibe arithmetic operation with pointers?

Pointers in C are stored as integers. You can perform any mathematical operations on pointers that you can perform on ints.Of course not, the following operations are possible: =, +, +=, ++, -, -=, --, *, [], ->, typecast


Why Two pointers cannot be added in c language?

Because no-one knows what the sum of two pointers should be...of course you can convert them to integers and then sum them, but why on earth would you do that?


What is the difference between handles and pointers?

They exist in different contexts. Handles are like... well handles (or keys, tickets, references etc), to access objects (like files, sockets, resources) you have opened (created, allocated, etc); in the program they can be integers or pointers.


Why array is a implicit pointer?

An array of pointers is exactly what it sounds like - one or more pointers arranged in order in memory, accessible through a common base name and indexed as needed. Philosophically, there is no difference between an array of pointers and an array of objects...int a[10]; // 10 integers, named a[0], a[1], a[2], ..., a[9]int *b[10]; // 10 pointers to int, named b[0], b[1], b[2], ..., b[9]If you initialize the array of pointers...int i;for (i = 0; i < 10; i++) b[i] = &a[i];... then *b[0] would be the same as a[0], etc.


What are void pointers?

They are pointers without type


Sort integer numbers in ascending order using pointers?

It's hardly the most efficient way to sort integers. Integers are primitive data types, so it's actually quicker to sort the integers directly rather than point at them. Pointers just add an unnecessary level of indirection. Pointers should only be used for complex data types for which copying/moving would result in greater inefficiency than would otherwise be incurred through pointer manipulation. #include&lt;iostream&gt; #include&lt;vector&gt; int main() { // instantiate a vector of unsorted integers std::vector&lt;int&gt; v = {7,3,5,2,9,4,1,6,8}; // instantiate a vector of pointers to the integers in the vector std::vector&lt;int*&gt; p; for (size_t i=0; i&lt;v.size(); ++i) p.push_back (&amp;v[i]); // sort the pointers (uses insertion sort algorithm): for (size_t i=1; i&lt;p.size(); ++i) { int* x=p[i]; size_t gap = i; size_t pre = i-1; while (gap &amp;&amp; *x&lt;*p[pre]) { p[gap--] = p[pre--]; } p[gap]=x; } // print to prove the sorting worked: std::cout &lt;&lt; "Original order:\t\t\t"; for (size_t i=0; i&lt;v.size(); ++i) std::cout &lt;&lt; v[i] &lt;&lt; '\t'; std::cout&lt;&lt;std::endl; std::cout &lt;&lt; "Sorted order (by pointer):\t"; for (size_t i=0; i&lt;p.size(); ++i) std::cout &lt;&lt; *p[i] &lt;&lt; '\t'; std::cout&lt;&lt;std::endl; }


Where the pointers are used?

POINTERS ARE USED TO STORE ADDRESS


What are the background pointers in java?

Java does not support pointers.


Pointers are replaced by what in java?

Nothing. Java does not have a concept that is equivalent to Pointers.


How do you get score 6?

3 two-pointers or 2 three-pointers


What are object oriented programming language's?

Languages where all types, including primitive types such as integers, are implemented as objects. Java is a pure object oriented language. C++ is not pure because integers, floating point values and pointers are primitive data types that are not implemented as objects. As a result, Java is easier to program, but C++ is more efficient.


Can labs be trained as pointers?

Yes, some labs are trained as pointers, and some as retrievers.