0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[C言語] argument type 'void' is incomplete

Last updated at Posted at 2025-03-09

間違い

sample.c
#include <stdio.h>

int main(void)
{
    int a = 70;

    void *addr = (void *)&a;
    printf("変数addrのアドレスは「%p」です\n", addr);
    printf("p番値の値は「%d」です", *addr);

    return 0;
}
$ gcc sample.c -o sample && ./sample
error: argument type 'void' is incomplete
    printf("p番値の値は「%d」です", *addr);
                                    ^
1 error generated.

正解

sample.c
#include <stdio.h>

int main(void)
{
    int a = 70;

    void *addr = (void *)&a;
    printf("変数addrのアドレスは「%p」です\n", addr);
    //printf("p番値の値は「%d」です", *addr);
    printf("p番値の値は「%d」です", *(int *)addr);

    return 0;
}
$ gcc sample.c -o sample && ./sample
変数addrのアドレスは「0x12345678」です
p番値の値は「70」です%   
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?