Rules for Initializing Strutures in C

原创 2012年03月30日 18:58:37

       以前没怎么注意这个问题,因为学习c语言的时候不是很用心,基本是混日子,根本没有意识的在c语言里,struct有多么的重要。现在我学了c++,java等,然后回过来看c,就发觉struct相当重要,很多时候就承担了在面向对象里的类的功能,只不过它没有继承,没有多态,没有重载。

      今天看了一些,发现有些规则相当重要:

There is a few rules to keep in mind while initializing structure variable at compile-time:

1.We cannot initialize individual members inside the structure template;

2.The order of values enclosed in braces must match the order of menmbers in the structure definition;

3.It is permitted to have a partial initialization. We can initialize only the first few members and leave the remaining blank.The uninitialized members should be only at the end of the list.

4.The uninitialized members will be assigned default values as follows:

         1).Zero for integer and floating point numbers.

         2).'\0'for characters and strings.



版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

UDEV SCSI Rules Configuration for ASM in Oracle Linux 5 and 6

http://www.oracle-base.com/articles/linux/udev-scsi-rules-configuration-in-oracle-linux-5-and-6.php ...

UDEV SCSI Rules Configuration for ASM in Oracle Linux 5, 6 and 7

从oracle-base中看到这篇文章,写的比较详细,分享一下For Oracle Automatic Storage Manager (ASM) to use disks, it needs to ...

Improved Methods for Initializing R-Q Model

  • 2011年04月24日 16:42
  • 368KB
  • 下载

tomcat启动不了——Error initializing endpoint——java.net.BindException: Address already in use: JVM_Bind <n

信息: The APR based Apache Tomcat Native library which allows optimal performance in production enviro...

Effective Objective-C(第47-52条)系统架构,foundation、for-in、NSTimer

第47条:熟悉系统框架         若是不了解系统架构所提供的内容,那么就可能会把其中已经实现的东西再写一遍。将一系列代码封装为动态库(dynamic library),并在其中放入描述其接口的头...
  • hherima
  • hherima
  • 2014年08月10日 15:13
  • 1747

《Effective Objective-C 2.0》—(第47-52条)—系统架构,foundation、快速遍历for-in、NSTimer

collection使用无缝桥接 快速遍历for-in的使用 谨慎NSTimer的循环引用
  • hherima
  • hherima
  • 2014年08月10日 15:07
  • 675

UDP Server Client Implementation in C for Unix/Linux

Here's a simple UDP Server Client Implementation in C for Unix/Linux. As UDP is a connection-less pr...
  • no_mame
  • no_mame
  • 2013年12月08日 09:20
  • 796

HowTo compile native C codes to a library for iOS development in Xcode – take Mosquitto as an exampl

HowTo compile native C codes to a library for iOS development in Xcode – take Mosquitto as an exampl...

Strategies for Using C++ in Objective-C Projects (and vice versa)

Update (May 2012): while nothing in this article is incorrect, there have been some changes to Objec...
  • weiqubo
  • weiqubo
  • 2012年08月22日 15:10
  • 1976
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Rules for Initializing Strutures in C
举报原因:
原因补充:

(最多只允许输入30个字)