本文へスキップ
製品デスクトップツールTASTECAD図面の確認TASTEFILESファイル管理TASTEFTPファイル転送TASTESSHリモートワークスペースTASTEZIP圧縮と展開TASTEWINMファイル管理開発ツールTASTECODERust 統合開発環境TASTESTUDIO統合開発・テスト環境TASTEETLデータ統合(ETL)サーバーTASTEREMOTEリモートデスクトップサーバーTASTEGEO空間情報サーバーTASTEMAILメールワークスペース投資TASTESTOCK株式自動売買デスクトップアプリはじめるダウンロードドキュメント購入すべての製品
マーケットプレイス
ニュース
技術ニュース今日の開発ニュース開発ドキュメントプログラミング言語RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWebフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngularサーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Expressアプリ・デスクトップ フレームワークTauriFlutterReact NativeElectronアルゴリズムアルゴリズムの基礎主要アルゴリズム発展アルゴリズム実務のアルゴリズム
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケースコミュニティガイド
協業技術移転ウェブサイト構築デスクトップアプリ構築リリース・決済パイプライン販売パートナーお問い合わせ
サービスリモートデスクトップインストールパッケージのカスタマイズ
TASTEDEV
製品

デスクトップツール

TASTECAD複雑な図面を、軽やかにひらくTASTEFILES必要なファイルだけを、最速でTASTEFTPファイルが行き交う、いちばん端正な道TASTESSHサーバーとあなたを、より確かにつなぐTASTEZIPより速くまとめ、より安全にひらくTASTEWINM2つの画面で整理する、キーボード中心のファイルマネージャー

開発ツール

TASTECODERust アプリの編集・ビルド・デバッグ・テストまでひとつのウィンドウでTASTESTUDIO編集からリモートテスト、承認した AI 修正までTASTEETL値を見ながら、データを運ぶ

サーバー

TASTEREMOTE自社サーバーで運用するリモートデスクトップTASTEGEOGeoServer 互換の空間情報サーバーを Rust で作り直しますTASTEMAILメールの主導権を、もう一度自分の手に

投資

TASTESTOCKいつ・何を。自分で決めたルールどおりに動く株式自動売買

はじめる

ダウンロード全製品の最新版ドキュメント各製品の使い方購入サブスクリプション・永久ライセンスすべての製品全製品を一覧で
すべての製品
マーケットプレイスニュース
技術

ニュース

今日の開発ニュース言語・フレームワーク・GitHub・AI の公式発表開発ドキュメント言語・フレームワーク・アルゴリズムのガイド

プログラミング言語

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

フレームワーク

Webフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngular
サーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
アプリ・デスクトップ フレームワークTauriFlutterReact NativeElectron

アルゴリズム

アルゴリズムの基礎計算量解析 · ソート · 探索 · 基本データ構造 · 木構造とヒープ主要アルゴリズムグラフ探索 · 最短経路と最小全域木 · 動的計画法 · 貪欲法 · 分割統治法 · バックトラッキング発展アルゴリズム文字列アルゴリズム · 数学と整数論 · ビット演算 · セグメント木 · Union-Find実務のアルゴリズムコーディング面接対策 · LRUキャッシュ · レート制限 · コンシステントハッシュ法
開発ドキュメントをすべて見る
コミュニティ
プロジェクトビルダーと作品を探す開発ログ決定と試行錯誤プロンプト再利用できる指示AIツールの問題Claude・Codex・Gemini の問題と回避策ショーケース完成した成果コミュニティガイドオープンにつくる方法
協業
技術移転Rust・egui でネイティブアプリを作るウェブサイト構築10言語、アカウント、ドキュメントとダウンロードデスクトップアプリ構築Rust・egui、WebView なしリリース・決済パイプライン署名・MSI・deb・rpm・AppImage・ハッシュ販売パートナー紹介して決済額の30%お問い合わせ構築・提携・投資のご相談
サービス
リモートデスクトップブラウザから自分のパソコンへインストールパッケージのカスタマイズ必要な機能だけ、設定は事前に
購入
JA
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
ログイン
ログイン
TASTEDEV

小さなツールから、より良い開発へ。

support@tastedev.netTASTEDEVを支援
製品製品ラインナップ購入ドキュメントダウンロードマーケットプレイスサポート
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケース
ポリシー会社概要プライバシーポリシー利用規約サブスクリプション規約返金ポリシーコミュニティガイドライン
アカウントログイン新規登録
訪問者
今日
昨日
累計閲覧
商号
GXSOFT
代表者
CHOI YOUNG GU
事業者登録番号
853-44-00368
所在地
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
電話
+82-10-4404-1523
メール
whitecalvin@tastedev.net
個人情報保護責任者
CHOI YOUNG GU

© 2026 TASTEDEV製品情報は検証済みの開発ソースに基づいています。リリース・改善中

C ドキュメント
C
Getting StartedSyntax BasicsTypes and DataModules and LibrariesErrors and TestingKey Concepts: Pointers and Memory
ディスカッション

C ガイド · 3/6

Types and Data

この章は現在、英語でのみ提供しています。

In C, a type decides how many bytes a value occupies and how those bytes are interpreted. This chapter walks through integer and floating-point types, arrays, strings as character arrays, and the tools for grouping data: structs, unions, enums, and typedef.

Integer and floating-point types

The standard does not fix the exact size of integer types; it only guarantees minimum widths. Real sizes depend on the platform.

TypeGuaranteed minimum64-bit Linux and macOS64-bit Windows
char8 bits8 bits8 bits
short16 bits16 bits16 bits
int16 bits32 bits32 bits
long32 bits64 bits32 bits
long long64 bits64 bits64 bits

The long column is the one that bites people when code moves between systems. When you need an exact width, use the fixed-width types from <stdint.h> such as int8_t, int32_t, and uint64_t. For object sizes and array indexes, use size_t from <stddef.h>, which is unsigned.

Unsigned integers wrap around modulo their range, which is well defined. Signed integer overflow, on the other hand, is undefined behavior. For floating point you have float, double, and long double; double is the usual default.

#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <limits.h>

int main(void) {
    printf("int: %zu bytes, max %d\n", sizeof(int), INT_MAX);
    printf("long: %zu bytes\n", sizeof(long));

    uint8_t small = 255;
    small++;                      /* unsigned values wrap to 0 */
    printf("small = %u\n", (unsigned)small);

    int64_t big = INT64_C(9000000000);
    printf("big = %" PRId64 "\n", big);   /* format macro for fixed-width types */

    double avg = 10 / 4;          /* 2.0: integer division happens first */
    double ok = 10 / 4.0;         /* 2.5 */
    printf("%.1f %.1f\n", avg, ok);
    return 0;
}

Arrays

An array is a fixed number of same-typed elements laid out contiguously. Its size is set at declaration and never changes. If you provide fewer initializers than elements, the rest are zero.

int scores[5] = {90, 85, 77};               /* last two elements are 0 */
size_t n = sizeof scores / sizeof scores[0];  /* element count: 5 */

for (size_t i = 0; i < n; i++) {
    printf("%zu: %d\n", i, scores[i]);
}

int grid[2][3] = {{1, 2, 3}, {4, 5, 6}};    /* two-dimensional array */
printf("%d\n", grid[1][2]);                 /* 6 */

C does no bounds checking. Reading scores[5] compiles and may even appear to work, but it is undefined behavior. Also, when you pass an array to a function it decays into a pointer to its first element, so sizeof inside the function no longer gives you the element count. The convention is to pass the length alongside the array.

Strings are char arrays

There is no dedicated string type. A string is a char array terminated by a null character, '\0'. The literal "hi" takes three bytes: h, i, and the terminator.

#include <stdio.h>
#include <string.h>

int main(void) {
    char name[16] = "Kim";          /* a writable array */
    const char *lang = "C";         /* a string literal: never modify it */

    printf("%zu\n", strlen(name));  /* 3: the terminator is not counted */
    printf("%zu\n", sizeof name);   /* 16: the whole array */

    char buf[32];
    snprintf(buf, sizeof buf, "%s loves %s", name, lang);  /* never writes past buf */
    puts(buf);

    if (strcmp(name, "Kim") == 0) { /* compare contents with strcmp, not == */
        puts("same string");
    }
    return 0;
}

strcpy and strcat never check the destination size, which makes overflows easy. Reaching for snprintf, which takes the buffer size, is a safer habit. Comparing strings with == compares addresses rather than contents, so use strcmp.

Structs, unions, enums, and typedef

A struct groups values of different types. Access members with ., or with -> through a pointer. C99 designated initializers (.x = 1) let you initialize members by name, in any order.

An enum defines a set of named integer constants. A union overlays all its members on the same storage, so it holds only one of them at a time; it is normally paired with a tag that records which member is active. typedef gives a type a new name.

#include <stdio.h>

typedef enum { SHAPE_CIRCLE, SHAPE_RECT } ShapeKind;

typedef struct {
    double x, y;
} Point;

typedef struct {
    ShapeKind kind;            /* tag: which union member is valid */
    Point origin;
    union {
        double radius;                  /* SHAPE_CIRCLE */
        struct { double w, h; } size;   /* SHAPE_RECT */
    } u;
} Shape;

double area(const Shape *s) {
    switch (s->kind) {
    case SHAPE_CIRCLE: return 3.14159265 * s->u.radius * s->u.radius;
    case SHAPE_RECT:   return s->u.size.w * s->u.size.h;
    }
    return 0.0;
}

int main(void) {
    Shape c = { .kind = SHAPE_CIRCLE, .origin = { .x = 0, .y = 0 }, .u.radius = 2.0 };
    Shape r = { .kind = SHAPE_RECT, .u.size = { .w = 3.0, .h = 4.0 } };
    printf("%.2f %.2f\n", area(&c), area(&r));
    printf("sizeof(Shape) = %zu\n", sizeof(Shape));
    return 0;
}

Passing a struct by value copies the whole thing, so pass large structs by pointer and add const when the function only reads. A struct can be larger than the sum of its members because the compiler inserts padding for alignment.

Summary

  • Integer sizes vary by platform; use <stdint.h> for exact widths and size_t for sizes and indexes.
  • Signed overflow is undefined behavior; unsigned arithmetic wraps.
  • Arrays have no bounds checks and decay to pointers when passed, so pass the length too.
  • Strings are '\0'-terminated char arrays; handle them with snprintf and strcmp.
  • Group data with structs, use tagged unions, name constants with enum, and shorten type names with typedef.
この章について質問がありますか?
前の章Syntax Basics次の章Modules and Libraries

コメント 0件

人気のコメント順新しい順

ログイン · ログインするとコメントできます。