C99标准新特性的说明
#include <stdio.h> int main(int argc, char *argv[])
{
int a1 = 10;
printf("a1 = %d\n", a1);
int a2 = 20;
printf("a2 = %d\n", a2); return 0;
}
2.2 长度可变的数组variable-length arrays
-------------------------------------------------
数组在C语言中定义时,只能用常量表达式来指定其长度,可变长度的数组在定义时可以使用变量来指定数组的长度,这样以来,就可以定义必须等到运行时才能知道大小的数组。
#include <stdbool.h> int main(int argc, char *argv[])
{
int size;
scanf("%d", &size);
int arr[size]; //使用运行时才能确定其值的变量作为数组长度来定义数组
for (int i = 0; i < size; i++)
{
scanf("%d", &arr[i]);
} for (int i = 0; i < size; i++)
{
printf("%d ", arr[i]);
}
printf("\n"); return 0;
}
2.3 支持单行注释one-line comments
------------------------------------------
support for one-line comments beginning with //, as in BCPL, C++ and Java.
#include <stdio.h> int main(int argc, char *argv[])
{
//this a one line comment return 0;
}
2.4 for语句内的变量声明
----------------------------
C99中,可以在for语句的初始化部分定义一个或多个变量,这些变量的作用域仅于本for语句所控制的循环体内。
#include <stdio.h> int main(int argc, char *argv[])
{
int arr[5] = {1, 2, 3, 4, 5};
for (int i = 0; i < sizeof(arr)/sizeof(arr[0]); i++)
{
printf("%d ", arr[i]);
}
printf("\n"); return 0;
}
#include <stdio.h> inline int add(int a, int b)
{
return (a + b);
} int main(int argc, char *argv[])
{
printf("%d + %d = %d\n", 10, 20, add(10, 20)); return 0;
}
several new data types, including long long int, optional extended integer types, an explicit boolean data type, and a complex type to represent complex numbers
1 long long int
C99标准中引进了long long int(-(2e63 - 1)至2e63 - 1)和unsigned long long int(0 - 2e64 - 1)。long long int能够支持的整数长度为64位。
2 _Bool
_Bool是作为关键字引入的。_Bool类型的变量的值是0或1。
C99中增加了头文件夹<stdbool.h>,在其中定义bool、true以及false宏的, 以便程序员能够编写同时兼容于C与C++的应用程序。在编写新的应用程序时,应该包含<stdbool.h>头文件,并且使用bool宏来定义_Bool类型的变量,通过用true和false这两个宏来为_Bool类型的变量赋值。
3 _Complex和_Imaginary
_Complex关键字用来代表复数类型,_Imaginary关键字用来代表虚数类型。虚数单位可以是i、I、j、J。
这两个关键字和float、double以及long double组合,可以形成如下的六种类型:
float _Complex : 实部和虚部都是float类型的复数 float _Imaginary double _Complex : 实部和虚部都是double类型的复数 double _Imaginary long double _Complex : 实部和虚部都是long double类型的复数 long double _Imaginary
同时,C99新增了<complex.h>头文件,在其中定义了complex和imaginary宏,它们可以扩展为_Complex和_Imaginary。因此在编写新的应用程序时,应该在程序中包含<complex.h>头文件,并且使用中的complex和imaginary来定义复数变量和虚数变量。
_Imaginary关键字gcc暂时不支持。
#include <stdio.h>
#include <stdbool.h>
#include <complex.h> int main(int argc, char *argv[])
{
long long ll = 10;
printf("ll = %d\n", ll); _Bool b1 = true;
printf("b1 = %d\n", b1);
bool b2 = true;
printf("b2 = %d\n", b2); float complex fc = 1.0f + 2.0j;
double complex dc = 3.0 + 4.0j;
long double complex ldc = 5.0 + 6.0i; //下面的代码在gcc无法编译通过
//float imaginary fi = 2.0j;
//double imaginary di = 3.0j;
//long double imaginary = 4.0i; return 0;
}
以上六个特性是非常常用,而且有用的特性。
2.7 其余用到再写
---------------
C99标准新特性的说明的更多相关文章
- 【转】C++11 标准新特性: 右值引用与转移语义
VS2013出来了,对于C++来说,最大的改变莫过于对于C++11新特性的支持,在网上搜了一下C++11的介绍,发现这篇文章非常不错,分享给大家同时自己作为存档. 原文地址:http://www.ib ...
- C++11 标准新特性: 右值引用与转移语义
文章出处:https://www.ibm.com/developerworks/cn/aix/library/1307_lisl_c11/ 新特性的目的 右值引用 (Rvalue Referene) ...
- 【转】C++11 标准新特性:Defaulted 和 Deleted 函数
原文链接http://www.ibm.com/developerworks/cn/aix/library/1212_lufang_c11new/ 本文将介绍 C++11 标准的两个新特性:defaul ...
- [转]C++11 标准新特性:Defaulted 和 Deleted 函数
http://www.ibm.com/developerworks/cn/aix/library/1212_lufang_c11new/
- C99标准的新特性
C语言标准的发展 C语言的发展历史大致上分为4个阶段:Old Style C.C89.C99和C11. C89是最早的C语言规范,于1989年提出,1990年先由ANSI(美国国家标准委员会,Amer ...
- C99新特性:变长数组(VLA)
C99标准引入了变长数组,它允许使用变量定义数组各维.例如您可以使用下面的声明: ; ; double sales[rows][cols]; // 一个变长数组(VLA) 变长数组有一些限制,它必须是 ...
- C99新特性
c99标准允许使用变长数组,变的意思是可以根据变量的值来指定数组的维数,如根据用户的输入值指定数组的大小,印象中以前是不可以的.现在在gcc中是可以的(PS:ansi c标准是C90标准): ==== ...
- 适应c++ 新特性 - 与我 - 多年传统方式开发(新特性参考微软标准:https://msdn.microsoft.com/zh-cn/library/hh279654.aspx)
公司同事都在积极使用c++的新特性,并对其赞不绝口,而自己一直做着传统的c++开发方式,到底这些新特性如何,又是怎么提高开发效率的,我依然在疑问当中,从同事的说法和实际代码操练里,确实在减少代码量,集 ...
- C++ 11学习和掌握 ——《深入理解C++ 11:C++11新特性解析和应用》读书笔记(一)
因为偶然的机会,在图书馆看到<深入理解C++ 11:C++11新特性解析和应用>这本书,大致扫下,受益匪浅,就果断借出来,对于其中的部分内容进行详读并亲自编程测试相关代码,也就有了整理写出 ...
随机推荐
- Python基础学习(第5天)
第3课 模块 1.模块(module) Python中一个.py文件就是一个模块,可以调用其它文件中的程序. 例:first.py def laugh(): print '哈哈哈哈哈' second ...
- 剑指offer--29.从上往下打印二叉树
层序遍历,队列 ------------------------------------------------------------------------------------- 时间限制:1 ...
- New Concept English three (39)
26w/m 70errors The rough across the plain soon became so bad that we tried to get Bruce to drive bac ...
- Drools7在Intellij IDEA下的引入静态方法错误提示
问题 在Intellij IDEA 2016下,默认安装了Drools的插件,但使用Drools7(其他版本应该也有问题)时发现,在DRL文件中引入的静态方法IDEA会提示"Cannot r ...
- 5.linux目录结构介绍
目录: 1.linux系统的目录结构特点?为何会形成这样的目录结构? 2.基本目录内容详解! 3.重要目录详解! 1.linux系统的目录结构特点? A.Linux系统的目录结构是一棵倒挂的大树,”/ ...
- ADO.Net入门(2)
(转载) 作者:可米小子 出处:http://liuhaorain.cnblogs.com 1. 什么是连接池? 在上篇文章<你必须知道的ADO.NET(四) 品味Connection对象> ...
- poj 1159 最长回文
方法 LCS #include<iostream> #include<cstring> #include<algorithm> #include<stdio ...
- BZOJ - 3224 Tyvj 1728 普通平衡树 (treap/树状数组)
题目链接 treap及树状数组模板题. treap版: #include<bits/stdc++.h> using namespace std; typedef long long ll; ...
- 2.2 web工程的目录结构
[转] 一个最简单的Web应用的目录结构如下所示: Web应用的结构定义在Servlet的规范中,目前最新版本为3.1. 下载地址:https://jcp.org/aboutJava/communit ...
- 十六、python沉淀之路--迭代器
一.迭代器 1.什么是迭代器协议:对象必须提供一个next方法,执行该方法要返回迭代中的下一项,要么就引起一个StopIteration异常,以终止迭代(只能往后走,不能往前走). 2.可迭代对象:实 ...