/ *
C99增加的特性,复合字面量(composite literal)。一旦熟悉并使用,便会体会到简洁强大的表达
对,复合字面量,就是可以随时定义,随时赋值的数组字面量。两步构建出来。
形如(type [])表示需要构建的数组类型,如:(int []),(int * p),还能是自定义的类型(MyType [])
2。跟着{}表示数组内容
* /
https://blog.youkuaiyun.com/c1194758555/article/details/80897459
#include <stdio.h>
typedef struct TEST {
int a;
int b;
char str [64];
} st_TEST,* pst_TEST;
void showPst(pst_TEST pst_test)
{
if(NULL == pst_test){
return;
}
printf(“%d \ n”,pst_test-> a);
的printf( “%d \ n”个,pst_test-> b)的
的printf( “%S \ n \ n”个,pst_test-> STR);
}
空隙showArry(INT * ARRY,INT NUM)
{
对于(INT I = 0;我<NUM;我++){
的printf( “%d \ n”个,ARRY [I]);
}
printf(“\ n”);
}
static st_TEST myTest = {
。a = 0,
.b = 1,
.str =“song”
};
static int * pst =(int *)&(int []){0,1,2,3,4,5};
int main(void)
{
/ *常规写法* /
showPst(&myTest);
//复合字面量写法
showPst(&(st_TEST){。a = 2,.b = 3,.str =“song2”});
/ *常规写法* /
int myArry [5] = {1,3,5,7,9};
showArry(myArry,5);
//复合字面量写法
showArry((int [5]){2,4,6,8,10},5);
showArry(PST,5);
}
C99增加的特性,复合字面量(composite literal)。一旦熟悉并使用,便会体会到简洁强大的表达
对,复合字面量,就是可以随时定义,随时赋值的数组字面量。两步构建出来。
形如(type [])表示需要构建的数组类型,如:(int []),(int * p),还能是自定义的类型(MyType [])
2。跟着{}表示数组内容
* /
https://blog.youkuaiyun.com/c1194758555/article/details/80897459
#include <stdio.h>
typedef struct TEST {
int a;
int b;
char str [64];
} st_TEST,* pst_TEST;
void showPst(pst_TEST pst_test)
{
if(NULL == pst_test){
return;
}
printf(“%d \ n”,pst_test-> a);
的printf( “%d \ n”个,pst_test-> b)的
的printf( “%S \ n \ n”个,pst_test-> STR);
}
空隙showArry(INT * ARRY,INT NUM)
{
对于(INT I = 0;我<NUM;我++){
的printf( “%d \ n”个,ARRY [I]);
}
printf(“\ n”);
}
static st_TEST myTest = {
。a = 0,
.b = 1,
.str =“song”
};
static int * pst =(int *)&(int []){0,1,2,3,4,5};
int main(void)
{
/ *常规写法* /
showPst(&myTest);
//复合字面量写法
showPst(&(st_TEST){。a = 2,.b = 3,.str =“song2”});
/ *常规写法* /
int myArry [5] = {1,3,5,7,9};
showArry(myArry,5);
//复合字面量写法
showArry((int [5]){2,4,6,8,10},5);
showArry(PST,5);
}