A
A
Alexey Gaponyuk2016-06-05 13:29:02
C++ / C#
Alexey Gaponyuk, 2016-06-05 13:29:02

What is the difference between char* and int*, float* and others in C?

Programming is something new for me, I learn the basics from lectures. And, I don’t understand, if the asterisk (*) is a pointer, then how does a pointer to int differ from a pointer to char? Yes, they [char and int] differ from each other. But if the file is only a pointer, then how will a pointer to char differ from a pointer to int? It will still be something like 0xXXXXXX...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
res2001, 2016-06-05
@Volfreim

The pointer size is the same, if that's what you mean.
char* differs from int* in that the former points to a memory area of ​​sizeof(char) bytes, and the latter to sizeof(int) bytes. This is important, for example, for address arithmetic.
For example we have:

int ival[] = {0,1,2,3};
char* pc = "This is a string";
int* pi = &ival;

If we do pc++, then sizeof(char) is added to pc, and in the case of pi++, sizeof(int) is added to pi.
And also, when we do denaming, we get the corresponding type as a result:
*pc - gives char
*pi - gives int
If there were no pointer typing, then there would be no address arithmetic and denaming. See, for example, what can be done with a pointer to void.

A
abcd0x00, 2016-06-06
@abcd0x00

A pointer is a variable that stores the address of one byte in memory. Often the address itself is called a pointer, because the address itself is usually not used and only implies what is at this address (therefore, they became synonymous).
By one address, you cannot tell how many bytes there can be considered as a whole, since the address itself provides information about only one byte. Therefore, the pointer has a type, which means that at that address there are so many bytes that must be considered as a single whole.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question