Похожие чаты

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 ответов

4 просмотра

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- Автор вопроса
Yamikani ᥀
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 (&).

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

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

We heading to 1.1$ 🤔?
CryptoBo$$
35
Anyone here suffers from unexplained aural migraines, who would be up for talking for a bit? Doesn't *have* to be aural, but I am not asking about headaches, I mean actual mi...
Martin Rys
55
A couple thoughts from a random internet stranger: 1. If you want this project to gain traction you cannot keep being negative. If I just came here after finding out about Kd...
Eric Wild
45
Сonst magicTgHTML = (text, entities) => { let processedText = text; let offsetShift = 0; entities.forEach(entity => { const { offset, length, type, url, ...
Андрей
1
Здравствуйте товарищи! решил всё таки поставить линукс. Порядок создание разделов /boot/efi 200МиБ; /boot 1000; подсистему / 80000; swap 8Гб Будет норм?
K2
19
Koi bata sakata hai yaha ? Is baar shot open karna theek rahega kya ?
Hakuna Matata
13
Can you help a noob? I know LTC was one of the early alt coins. But what is the benefit of it today? What are its attributes? Why should I be bullish on it this bull run?
CryptoNoobian ($PEPI)
14
How Will #Monero Be Attacked? First of all I want to tell you that this is not teaching the network attackers, the central regulators. They already know how to attack the net...
Li₿ΞʁLiøη
3
#wazirx 15 May my account has fund of rupees 10000 but 16 May my balance is showing 8200 why?? Without any withdrawal
Learnwi
12
подскажите пожалуйста, как мне освободить результат записанный в переменную result? в чем проблема подскажите если МОЖЕТЕ?
Михаил Helper
28
Карта сайта