C 中的复合字面量


在这一部分中,我们将了解 C 中的复合字面量。复合字面量在 C 标准中于 C99 中引入。使用此功能,可以创建未命名对象。在以下示例中,我们将了解如何在不使用任何名称的情况下使用复合字面量来生成对象。

示例

#include<stdio.h>
struct point {
   int x;
   int y;
};
void display_point(struct point pt) {
   printf("(%d,%d)
", pt.x, pt.y); } main() {    display_point((struct point) {10, 20}); }

输出

(10,20)

更新时间:2019 年 7 月 30 日

488 次浏览

开启您的职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.