void f(int(&p)[3]){} 和void f(int(*p)[3]){}的区别

#include<iostream>

using namespace std;

void f(int(&p)[3]){

cout<<p[0]<<endl;

cout<<p[2]<<endl;

}

int main(){

int a1[3]={1,2,3};

cout<<a1<<endl;

cout<<&a1<<endl;

f(a1);

}

编译后输出:

0xbfbb8eb4

0xbfbb8eb4

1

3

#include<iostream>

using namespace std;

void f(int(*p)[3]){

cout<<p[0]<<endl;

cout<<p[2]<<endl;

}

int main(){

int a1[3]={1,2,3};

cout<<a1<<endl;

cout<<&a1<<endl;

f(&a1);

}

编译后输出:

0xbff21e84

0xbff21e84

0xbff21e84

0xbff21e9c

由此比较可以看出,

void f(int(*p)[3]){}是个函数指针数组,指针数组属于二级指针

void f(int(&p)[3]){} 和void f(int(*p)[3]){}的区别,布布扣,bubuko.com

时间: 2024-08-02 15:12:45

void f(int(&p)[3]){} 和void f(int(*p)[3]){}的区别的相关文章

console.log((function f(n){return ((n &gt; 1) ? n * f(n-1) : n)})(5))调用解析

console.log((function f(n){return ((n > 1) ? n * f(n-1) : n)})(5)); 5被传入到函数,函数内部三元计算,5 > 1成立,运算结果是5*f(4),二次运算,5*4*f(3),依次类推,最终是5*4*3*2,最终返回结果是120. 如图:

&quot;int?&quot; 是什么类型?和&quot;int&quot;有何区别

int?:表示可空类型,就是一种特殊的值类型,它的值可以为null用于给变量设初值得时候,给变量(int类型)赋值为null,而不是0int??:用于判断并赋值,先判断当前变量是否为null,如果是就可以赋役个新值,否则跳过public int? a=null:public int b(){return this.a ?? 0;} 值类型后面加问号表示可为空null(Nullable 结构) Nullable是.NET 2.0中新提供的一种用于标明一个值类型是否可以为空的技术. 对于一个类型,如

解决warning: format ‘%x’ expects type ‘unsigned int’, but argument 2 has type ‘int *’

[[email protected] c]# gcc MemTest.c -o MemTest1 -WallMemTest.c: In function 'main':MemTest.c:24: warning: format '%x' expects type 'unsigned int', but argument 2 has type 'int *'MemTest.c:39: warning: format '%x' expects type 'unsigned int', but arg

C++中int转string与string转int

#include "stdafx.h" #include "string" #include "iostream" #include "vector" #include "sstream" using namespace std; int _tmain(int argc, _TCHAR* argv[]) { //string 转 int stringstream ss; string str; int i;

F#语言入门之什么是F#语言

F#是一种函数式编程语言,可以轻松编写正确且可维护的代码. F#编程主要涉及定义类型推断和自动泛化的类型和函数. 这使您可以将焦点保留在问题域上并操纵其数据,而不是编程的细节. open System // Gets access to functionality in System namespace. // Defines a function that takes a name and produces a greeting. let getGreeting name = sprintf

int a[5]={}, &amp;a+1与(int*)a+1的区别

#include <iostream> #include <typeinfo> using namespace std; int main() { int b, *pb; char *pb2; char *pb3; //&b = 0x001af74 pb = &b + 1; //0x001af78 int* pb2 = (char*)&b + sizeof(b); //0x001af78 char* pb3 = (char*)&b + 1; //0x

C#中(int)、Conver.Toint32()、int.Parse()三种类型转换方式的区别与联系--C#基础知识

自己也是刚学习C#程序设计语言,总结了一点知识点,想分享给大家.毕竟刚学习这门语言,学得不深,哪里如果有错误,请帮个忙指出一下哈,谢谢! 1.(int)可用于单精度.双精度等其他数值类型的转换(到整型int),不能用于转换string类型,例如: 这里用(int)转换string是不可以的,系统会报错,程序是不能运行. using System.Collections.Generic; using System.Linq; using System.Text; using System.Thre

关于Java编程,int和Integer有OA现金盘网站开发什么区别?

int是我们OA现金盘网站开发haozbbs.com Q1446595067常说的整型数字,是Java的8个原始数据类型之一.Java语言虽然号称一切都是对象,但原始数据类型是例外. Integer是int对应的包装类,它有一个int类型的字段存储数据,并且提供了基本操作,比如数学运算.int和字符串之间转换等.在Java 5中,引入了自动装箱和自动拆箱功能(boxing/unboxing),Java可以根据上下文,自动进行转换,极大地简化了相关编程. 知识扩展 1.理解自动装箱.拆箱 自动装箱

C++: string 转 int ;string转float;int 转string;double转char*

1.string转int std::string str1="700" int bid_v1 = atoi(str1.c_str()); 2.string转float std::string str2="6.78" float bid_p1 = atof(str2.c_str()); 3.int 转string int n =789; char t[256]; sprintf(t, "%d", n); string s(t) 4.double转c