Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Understanding the void Pointers | Pointers
/
C Basics (copy)

bookUnderstanding the void Pointers

メニューを表示するにはスワイプしてください

When you first saw void, it referred to functions that return nothing. You can’t create a variable of type void, but you can declare a void* pointer that holds the address of any data type.

Note
Note

If you've worked through the pointer exercises in the section, you'll know that all pointers occupy 8 bytes. A void* pointer is no different.

A void* pointer isn't tied to any specific data type. This flexibility allows you to store the address of any data type in it. However, there's a catch: you can't dereference a void* pointer.

Note
Note

This limitation stems from the same reason you can't declare variables of the void type. Perform an explicit type conversion!

Main.c

Main.c

copy
1234567891011121314151617181920
#include <stdio.h> int main() { char c = 'F'; int i = 100; double d = 3.15; void* pV; pV = &c; printf("%c \n", *((char*)pV)); pV = &i; printf("%d \n", *((int*)pV)); pV = &d; printf("%.2f \n", *((double*)pV)); return 0; }

Congratulations on completing the C programming basics! To advance further, explore topics like macros, sorting algorithms, and data structures. Learning a Linux distribution will also help you grow as a skilled C programmer.

question mark

How do you retrieve the value of a void pointer?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 6.  6

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 6.  6
some-alt