初版 2026/02/01
改訂


array2.c

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

uint8_t array8[] = {10, 50, 100, 200};
uint16_t array16[] = {1000, 5000, 10000, 20000};

void main() {
    printf("pointer:\n");

    uint8_t *array8_p = array8;
    for (uint8_t i = 0; i < 4; i++) {
        printf("array8[%u] : 0x%p\n", i, array8_p++);
    }

    uint16_t *array16_p = array16;
    for (uint8_t i = 0; i < 4; i++) {
        printf("array16[%u]: 0x%u\n", i, array16_p++);
    }

    return;
}
  • 代入先のポインタ変数は、変数名の先頭、または型の後に*を付け、型は代入する配列の型に合わせる。
  • ポインタ変数への代入は、通常の変数は&を付ける必要があるが、配列の場合は元々先頭アドレスのみを持っているため、&は不要。


コンパイル

compile.sh

#!/bin/sh
zcc +msx -lmsxbios --list -subtype=msxdos $1.c -o $1.com


$ ./compile.sh ./array2


実行結果

2026-02-01-z88dk-c-array2_01.png

※MSXDOS.SYSとCOMMAND.COM、コンパイルして作成した.COMを配置したディレクトリをopenMSXでマウント、MSXDOSから実行