0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

cf2.c THe C Puzzle book

Last updated at Posted at 2025-05-28

職業訓練
https://qiita.com/kaizen_nagoya/items/95368b63fa21d64271ec

Programmer, Day 6
https://qiita.com/kaizen_nagoya/items/632d8f191268e88eb86a

C Puzzle Bookの有り難み5つ、C言語規格及びCコンパイラの特性を認識, error(21), coding(28)
https://qiita.com/kaizen_nagoya/items/d89a48c1536a02ecdec9

The C Puzzle Book
https://efrei.poupa.net/Programmation%20en%20C/Cours/The_C_Puzzle_Book.pdf

defs.h "The C Puzzle Book"
https://qiita.com/kaizen_nagoya/items/6d284651ac1244963bd9

cf2.c
#include "defs.h" //ヘッダーファイルの中身少しいじりました

int main(void)
{
        int x, y, z;

        x = y = 0;
        while (y < 10)
        {
                ++y;
        }
        x += y;
        PRINT2("d", x, y);  // OUTPUT: x = 10, y = 10

        x = y = 0;
        while (y < 10)
        {
                x += ++y;
        }
        PRINT2("d", x, y);  // OUTPUT: x = 55, y = 10

        x = y = z = 0;
        y = 1;
        while (y < 10)
        {
                x = y++;
                z = ++y;
        }
        PRINT3("d", x, y, z);  // OUTPUT: x = 9, y = 11, z = 11

        for (y = 1; y < 10; y++)
        {
                x = y;
        }
        PRINT2("d", x, y);  // OUTPUT: x = 9, y = 10

        for (y = 1; (x = y) < 10; y++)
        {
                // ループ実行のみ、x, y の最終値を確認
        }
        PRINT2("d", x, y);  // OUTPUT: x = 10, y = 10

        for (x = 0, y = 1000; y > 1; x++, y /= 10)
        {
                PRINT2("d", x, y);  // 出力が複数行:1000, 100, 10
        }

        return 0;
}
bash
value = 10      value = 10
value = 55      value = 10
value = 9       value = 11      value = 11
value = 9       value = 10
value = 10      value = 10
value = 0       value = 1000
value = 1       value = 100
value = 2       value = 10
defs.h
// https://qiita.com/kaizen_nagoya/items/6d284651ac1244963bd9
// Type by Dr. Kiyoshi Ogawa
#include <stdio.h>

#define PR(format, value) printf("value = %" format "\t", (value))
#define NL putchar('\n')

#define PRINT1(f, x1) PR(f, x1), NL
#define PRINT2(f, x1, x2) PR(f, x1), PRINT1(f, x2)
#define PRINT3(f, x1, x2, x3) PR(f, x1), PRINT2(f, x2, x3)
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?