Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

Compound Literals ในภาษา C (C99)

Compound Literals (มาตรฐาน C99) สร้าง Unnamed Object ได้โดยไม่ต้องประกาศตัวแปร

ตัวอย่าง

#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}); // Compound Literal
    return 0;
}

ผลลัพธ์

(10,20)