Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Lập Trình C

Compound Literals (Hằng hợp thành) trong C

Ở đây ta xem Compound Literals trong C. Được giới thiệu trong chuẩn C99. Tạo đối tượng vô danh (unnamed objects).

Ví dụ

#include <stdio.h>

struct point {
    int x;
    int y;
};

void display_point(struct point pt) {
    printf("(%d,%d)\n", pt.x, pt.y);
}

int main() {
    display_point((struct point){10, 20});
    return 0;
}

Kết quả

(10,20)