Похожие чаты

Why do we type cast malloc into int*? the instructor

said malloc returns a void* pointer. can someone explain the difference. how can a memory location be void type?

8 ответов

17 просмотров

void* isn't a pointer of void variables Because void variable does not exist (you cannot have an variable of void - "void name;") void* is a pointer to anything It could be int or int[] or char[] or int[][] or anything So for using that variable which void* is pointing to, you have to cast void* to something else

skalpasi- Автор вопроса
Prince Of Persia [field = CE,DM = BLOCK]
void* isn't a pointer of void variables Because vo...

but i don't understand why we cast pointers to the data type of the variable it is pointing to. for ex- char msg[10] = "hello"; char *ptr = &msg; why do we use char data type for pointer when *ptr will always store an integral memory address. memory address are in hex/int format right? i might sound annoying but I'm studying this pointer concept for first time and is very confusing :(

What's a void type according to you?

skalpasi- Автор вопроса
The prodigal ᥀
What's a void type according to you?

in functions, it's a type which doesn't return anything but i don't think there is something called void data type

skalpasi
in functions, it's a type which doesn't return an...

Ok then, void* is a special thing then.. isn't it?

skalpasi
but i don't understand why we cast pointers to the...

there's mostly two reasons: 1. to maintain some form of type safety 2. alignment info for the type so you can do simple pointer arithmetic.

skalpasi
but i don't understand why we cast pointers to the...

it's fine. Your questions aren't annoying, it's just whoever taugh you pointers probably didn't do a good job at it when

skalpasi
but i don't understand why we cast pointers to the...

As i remember, array is Pointer. You dont have to take its addr (&).

Похожие вопросы

Обсуждают сегодня

а через ESC-код ?
Alexey Kulakov
29
30500 за редактор? )
Владимир
47
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
Привет)) уже кажется эту тему перемусолили, но вот я так и не понял. Я сейчас сижу на 27дюймов 2к мониторе. На Актуальной макоси, если я куплю 27д 4к монитор: - будет ли изобр...
Vladislav Piskunov
15
Hi guys, any problem with Pulsebrige? Trying to transfer from wETH to ETH. First it tells me to connect my metamask "through mobile app" not desktop. Then I did and confirmed ...
Snowflakecrypto
13
any reference of this implementation?
BitBuddha
29
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
13
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
&"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.42.34433\bin\Hostx64\x64\dumpbin.exe" /EXPORTS C:\Users\Yeet\Tauon\vcpkg\installed\x64-window...
Martin Rys
6
Карта сайта