Can we use function on left side of an expression in C and C++?
In C, it might not be possible to have function names on left side of an expression, but it’s possible in C++.
1 #include<iostream>
2 using namespace std;
3
4 /* such a function will not be safe if x is non static variable of it */
5 int &fun()
6 {
7 static int x;
8 return x;
9 }
10
11 int main()
12 {
13 fun() = 10;
14
15 /* this line prints 10 on screen */
16 printf(" %d ", fun());
17
18 getchar();
19 return 0;
20 }
不过,貌似C语言中也是可以的,比如下面的例子。
1 #include<stdio.h>
2 int* fun()
3 {
4 static int x;
5 return &x;
6 }
7
8 int main()
9 {
10 *(fun()) = 10;
11 /* this line prints 10 on screen */
12 printf(" %d ", *(fun()));
13 return 0;
14 }
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
转载请注明:http://www.cnblogs.com/iloveyouforever/
2013-11-27 12:23:57
Can we use function on left side of an expression in C and C++?的更多相关文章
- React报错之Expected an assignment or function call and instead saw an expression
正文从这开始~ 总览 当我们忘记从函数中返回值时,会产生"Expected an assignment or function call and instead saw an express ...
- Named function expressions demystified
Introduction Surprisingly, a topic of named function expressions doesn't seem to be covered well eno ...
- Oracle Function:COUNT
Description The Oracle/PLSQL COUNT function returns the count of an expression. The COUNT(*) functio ...
- 深入理解 JavaScript Function
1.Function Arguments JavaScript 函数的参数 类型可以是 复杂类型如 Object or Array 和简单类型 String Integer null undefin ...
- ESLint 规则
ESLint由 JavaScript 红宝书 作者 Nicholas C.Zakas 编写, 2013 年发布第一个版本. ESLint是一个以可扩展.每条规则独立的,被设计为完全可配置的lint工具 ...
- SSIS 参数的值
一,SSIS Parameter Value 的type 一个Parameter的Value共有三种类型,分别是Design Value,Server Value,Execution Value. D ...
- (转载)SQL Reporting Services (Expression Examples)
https://msdn.microsoft.com/en-us/library/ms157328(v=SQL.100).aspx Expressions are used frequently in ...
- JSLint检测Javascript语法规范
前端javascript代码编写中,有一个不错的工具叫JSLint,可以检查代码规范化,压缩JS,CSS等,但是他的语法规范检查个人觉得太“苛刻”了,会提示各种各样的问题修改建议,有时候提示的信息我们 ...
- jq 弹半透明遮罩层
jquery制作点击按钮弹出遮罩半透明登陆窗口 // )[^>]*$|^#([\w-]+)$/,M=/^.[^:#\[\.,]*$/,ka=/\S/,$= /^(\s|\u00A0)+|(\s| ...
随机推荐
- SpringMVC配置版到注解版
什么是springmvc? 1.1.什么是MVC MVC是模型(Model).视图(View).控制器(Controller)的简写,是一种软件设计规范. 是将业务逻辑.数据.显示分离的方法来组织代码 ...
- 西邮Linux兴趣小组第一次技术分享会
2016年10月30日晚,西邮Linux兴趣小组技术分享会在西安邮电大学长安校区东区逸夫教学楼FF305室成功举办.200多名来自全校不同专业的15,16级同学参加了此次分享会. 分享会于20:00正 ...
- 为 Android 编译并集成 FFmpeg 的尝试与踩坑
前言与环境说明 随着 FFmpeg.NDK 与 Android Studio 的不断迭代,本文可能也会像我参考过的过期文章一样失效(很遗憾),但希望本文中提到的问题排查以及步骤说明能够帮到你,如果发现 ...
- Part 33 Angular nested scopes and controller as syntax
Working with nested scopes using $scope object : The following code creates 3 controllers - country ...
- Spark性能调优——9项基本原则
原则一:避免创建重复的RDD 通常来说,我们在开发一个Spark作业时,首先是基于某个数据源(比如Hive表或HDFS文件)创建一个初始的RDD:接着对这个RDD执行某个算子操作,然后得到下一个RDD ...
- Java设计模式之(二)——工厂模式
1.什么是工厂模式 Define an interface for creating an object,but let subclasses decide which class toinstant ...
- [atARC071F]Infinite Sequence
注意到当$a_{i}\ne 1$且$a_{i+1}\ne 1$,那么$\forall i<j,a_{j}=a_{i+1}$(证明的话简单归纳就可以了) 令$f_{i}$表示在题中条件下,还满足$ ...
- [bzoj1037]生日聚会
dp,用f[i][j][x][y]表示i个男孩,j个女孩,以i+j为结尾的子序列男-女最多为x,女-男最多为y的合法方案数,转移到f[i+1][j][x+1][max(y-1,0)]和f[i][j+1 ...
- 关于PHP的==运算符比较规则
==是比较运算,它不会去检查比较的具体类型是否相等,只是单纯的根据php内置的转换规则来比较 ===是全等运算,相对来说它的要求更为严格,比较过程不会进行类型转换,从类型到内容都要求相等 ===运算符 ...
- Docker 急速入门
1. 概述 之前聊了很多 SpringCloud 相关的话题,今天我们来聊聊服务容器 Docker. 2. 在 CentOS7 安装 Docker 2.1 卸载旧版本的Docker # yum re ...