`
yaojingguo
  • 浏览: 202765 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

C array initialization

 
阅读更多

For fewer initializers, refer to 4.9 Initialization in K&R and 6.7.8 Initialization in C99 standard.

 

 

#include <stdio.h>

// in bss section. static storage. initialized to 0
int global_array[10];

void global() {
	int i;

	printf("=== global ===\n");
	for (i = 0; i < 10; i++)
		printf("array[%d] = %d\n", i, global_array[i]);
}

void range() {
	int i;
	int array1[] = { [0 ... 1] = 10, [7 ... 9] = 8 };	
	printf("=== range ===\n");
	for (i = 0; i < 10; i++)
		printf("array[%d] = %d\n", i, array1[i]);
}

void no_initializers_for_array_on_stack() {
	int i;
	int array2[3];

	printf("=== no_initializers_for_array_on_stack ===\n");
	for (i = 0; i < 3; i++)
		printf("array2[%d] = %d\n", i, array2[i]);
}

void fewer_initializers() {
	int i;
	// Sames as int array2[] = { [0] = 1} };
	int array2[3] = {1}; // 

	printf("=== fewer_initializers ===\n");
	for (i = 0; i < 3; i++)
		printf("array2[%d] = %d\n", i, array2[i]);
}

int main(int argc, const char *argv[]) {
	global();
	no_initializers_for_array_on_stack();
	range();
	fewer_initializers();
	return 0;
}
 
分享到:
评论

相关推荐

    H.265/HEVC标准白皮书(2013年1月)

    6.5.3 Up-right diagonal scan order array initialization process 26 6.5.4 Horizontal scan order array initialization process 27 6.5.5 Vertical scan order array initialization process 27 7 Syntax and ...

    Turbo C 2.00[DISK]

    WELCOME TO TURBO C 2.0 ---------------------- This README file contains important, last minute information about Turbo C 2.0. The HELPME!.DOC file on the COMMAND LINE/UTILITIES disk also answers ...

    Turbo C 2.01[DISK]

    WELCOME TO TURBO C 2.01 ----------------------- This README file contains important, last minute information about Turbo C 2.01. The HELPME!.DOC file on the COMPILER/UTILITIES disk also answers many...

    GObject Reference Manual

    Value arrays - A container structure to maintain an array of generic values III. Tools Reference glib-mkenums - C language enum description generation utility glib-genmarshal - C code marshaller ...

    CapSense_Tuning

    //scan all sensors in array (buttons and sliders) CSD_UpdateAllBaselines(); //Update all baseline levels; //detect if any sensor is pressed if(CSD_bIsAnySensorActive()){ // Add user code ...

    深入java虚拟机(inside the java virtual machine)

    java虚拟机的运行机理的详细介绍 Inside the Java Virtual Machine ...Appendix C. Opcode Mnemonic by Opcode Appendix D. Slices of Pi: A Simulation of the Java Virtual Machine Index About the Author

    Microsoft Library MSDN4DOS.zip

    BOUND Check Array Index Against Bounds BSF Bit Scan Forward BSR Bit Scan Reverse BT Bit Test BTC Bit Test and Complement BTR Bit Test and Reset BTS Bit Test and Set CALL Call Procedure CBW/CWDE ...

    《深度探索C++对象模型》(Stanley B·Lippman[美] 著,侯捷 译)

    如果你是一位C++程序员,渴望对于底层知识获得一个完整的了解,那么Inside TheC++ Object Model正适合你。 目录: 本立道生(侯捷 译序) 前言(Stanley B.Lippman) 第0章 导读(译者的话) 第1章 关于对象...

    Nucleus C++ v1.3 Upgrade

    support for the newer C++ array operators, new[] and delete[]. “C” callable allocation routines are supplied, including malloc()/free(). These routines are compatible in real-time with the C++ new ...

    带优先级的多任务管理模块(C)

    2. Call the initialization of step HashTaskList InitTaskList 3. StartTaskManager started calling the task manager ***** For a HashTaskList, the above two functions called only once 4. Call ...

    银行家算法

    #include&lt;stdio.h&gt; #define M 4 //资源数目A,B,C #define N 3//进程数目P1,P2,P3 #define Stacksize N*M*N//堆栈的大小此处数组的第一个数是堆栈指针,只是当前的...void Matrix_Initialization(int array1[][N]);

    C# 语言规格说明(English Edition第五版)

    7.6.10.4 Array creation expressions 176 7.6.10.5 Delegate creation expressions 178 7.6.10.6 Anonymous object creation expressions 180 7.6.11 The typeof operator 181 7.6.12 The checked and unchecked ...

    Rad Studio Delphi C++builder XE 10.4 Patch2

    RSP-29299 CODEGEN bug in managed fields initialization, associated with new management operators. RSP-29271 [DelphiLSP] Code Insight adds unneeded () when changing procedures/functions RSP-29256 ...

    [精典材料]Patran的PCL用户手册.doc

    mth_array_search(…) 175 mth_sort(…) 176 mth_sort_row(…) 177 mth_sort_column(…) 177 fem_geom_edge_length(…) 178 fem_geom_face_area(…) 178 fem_geom_elem_volume(…) 178 fem_geom_elem_location(…) ...

    linux驱动学习去开发入门

    在大二学习C语言时,老师就建议不要使用“goto”,并说很少会用到。在这里也是我碰到的第一个建议使用“goto”的地方。“在追求效率的代码中使用goto语句仍是最好的错误恢复机制。”--《Linux设备驱动程序(第3版...

    acpi控制笔记本风扇转速

    Disassembly of raw data buffers with byte initialization data now prefixes each output line with the current buffer offset. Disassembly of ASF! table now includes all variable-length data fields at ...

    servlet2.4doc

    A B C D E F G H I J L P R S U V -------------------------------------------------------------------------------- A addCookie(Cookie) - Method in class javax.servlet.http.HttpServletResponseWrapper ...

    matlab写的小游戏-猜数字

    % Hints: contents = get(hObject,'String') returns popupmenu contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu handles.bushu = get(hObject,'value'); %获得...

    python3.6.5参考手册 chm

    PEP 489: Multi-phase extension module initialization Other Language Changes New Modules typing zipapp Improved Modules argparse asyncio bz2 cgi cmath code collections collections.abc ...

    LCTF软件备份VariSpec™ Liquid Crystal Tunable Filters

    In prior revisions, VsGui would not report no filter found if a filter was present but still going through its power-up initialization. Now, a message box is posted to indicate that a filter was ...

Global site tag (gtag.js) - Google Analytics