C programming: casting a void pointer to an int?

后端 未结 3 726
谎友^
谎友^ 2021-02-02 11:27

Say I have a void* named ptr. How exactly should I go about using ptr to store an int? Is it enough to write

ptr = (void *)5;

If I want to sav

3条回答
  •  不知归路
    2021-02-02 12:06

    A pointer always points to a memory address. So if you want to save a variable with pointer, what you wanna save in that pointer is the memory address of your variable.

提交回复
热议问题