typedef int arr5[5];
typedef arr5 * p_arr5;
typedef p_arr5 arrp10[10];
arr5 togs;
p_arr5 p2;
arrp10 ap;
问题: p2, ap 是什么?怎么解释?
5 个解决方案
#1
typedef int arr5[5];
typedef arr5 * p_arr5;
typedef p_arr5 arrp10[10];
arr5 togs;
p_arr5 p2;
arrp10 ap;
arr5 : int [5]
p_arr5 : int (*)[5]
arrp10 : int (*[10])[5]
#2
它为什么不是:
arr5 : int [5]
p_arr5 : int *[5]
arrp10 : int *[10][5]
arr5 : int [5]
p_arr5 : int *[5]
arrp10 : int *[10][5]
#3
int *[5] 一个数组,数组的元素是int指针
int (*)[5] 一个指针,指向的内容是有五个int的数组
int *[10][5] 一个10*5的数组,数组的元素是int指针
int (*[10])[5] 一个大小为5的数组,数组的元素是有10个int指针的数组
int (*)[5] 一个指针,指向的内容是有五个int的数组
int *[10][5] 一个10*5的数组,数组的元素是int指针
int (*[10])[5] 一个大小为5的数组,数组的元素是有10个int指针的数组
#4
你说的这个我知道,我的意思是typedef之后为什么不是
arr5 : int [5]
p_arr5 : int *[5]
arrp10 : int *[10][5]
arr5 : int [5]
p_arr5 : int *[5]
arrp10 : int *[10][5]
#5
不要迷信书、考题、老师、回帖;
要迷信CPU、编译器、调试器、运行结果。
并请结合“盲人摸太阳”和“驾船出海时一定只带一个指南针。”加以理解。
任何理论、权威、传说、真理、标准、解释、想象、知识……都比不上摆在眼前的事实!
以下内容仅供参考:
Run-Time Type Information
Run-time type information (RTTI) is a mechanism that allows the type of an object to be determined during program execution. RTTI was added to the C++ language because many vendors of class libraries were implementing this functionality themselves. This caused incompatibilities between libraries. Thus, it became obvious that support for run-time type information was needed at the language level.
For the sake of clarity, this discussion of RTTI is almost completely restricted to pointers. However, the concepts discussed also apply to references.
There are three main C++ language elements to run-time type information:
The dynamic_cast operator.
Used for conversion of polymorphic types. See dynamic_cast Operator for more information.
The typeid operator.
Used for identifying the exact type of an object.
The type_info class.
Used to hold the type information returned by the typeid operator.
要迷信CPU、编译器、调试器、运行结果。
并请结合“盲人摸太阳”和“驾船出海时一定只带一个指南针。”加以理解。
任何理论、权威、传说、真理、标准、解释、想象、知识……都比不上摆在眼前的事实!
以下内容仅供参考:
Run-Time Type Information
Run-time type information (RTTI) is a mechanism that allows the type of an object to be determined during program execution. RTTI was added to the C++ language because many vendors of class libraries were implementing this functionality themselves. This caused incompatibilities between libraries. Thus, it became obvious that support for run-time type information was needed at the language level.
For the sake of clarity, this discussion of RTTI is almost completely restricted to pointers. However, the concepts discussed also apply to references.
There are three main C++ language elements to run-time type information:
The dynamic_cast operator.
Used for conversion of polymorphic types. See dynamic_cast Operator for more information.
The typeid operator.
Used for identifying the exact type of an object.
The type_info class.
Used to hold the type information returned by the typeid operator.
//char (*(*x[3])())[5];//x是什么类型的变量?
//
//分析C语言声明,关键是搞清楚这个变量是个什么东西(函数、指针、数组),
//是函数那么剩下的就是他的参数和返回值,
//是指针那剩下部分是说明他指向什么,
//是数组剩下的部分就是说明数组的成员是什么类型。
//解析C语言声明规则:
//从左侧第一个标识符开始,按照优先级进行结合。*表示是..的指针,const表示只读的,volatile表示可变的,[]表示是数组,()表示是函数。
//
//x和[3]结合说明是一个大小为3的数组,该数组指向了一个指针,该指针指向一个函数,该函数的无参数,返回一个指针,该指针指向一个大小为5的char型数组
#include <stdio.h>
#include <typeinfo.h>
char num[5];
char (*x00())[5] {
return #
}
int main() {
char (*x000)[5];//返回值
char (*(x00)())[5];//函数原型,参数为空,返回值为指针
char (*(*x0)())[5];//数组的元素,是个函数指针
char (*(*x[3])())[5];//是个数组,大小为3
x0 = x00;
x[0] = x0;
x[1] = x0;
x[2] = x0;
printf("typeid(x).name() is %s\n",typeid(x).name());
return 0;
}
//typeid(x).name() is char (* (__cdecl**)(void))[5]
#1
typedef int arr5[5];
typedef arr5 * p_arr5;
typedef p_arr5 arrp10[10];
arr5 togs;
p_arr5 p2;
arrp10 ap;
arr5 : int [5]
p_arr5 : int (*)[5]
arrp10 : int (*[10])[5]
#2
它为什么不是:
arr5 : int [5]
p_arr5 : int *[5]
arrp10 : int *[10][5]
arr5 : int [5]
p_arr5 : int *[5]
arrp10 : int *[10][5]
#3
int *[5] 一个数组,数组的元素是int指针
int (*)[5] 一个指针,指向的内容是有五个int的数组
int *[10][5] 一个10*5的数组,数组的元素是int指针
int (*[10])[5] 一个大小为5的数组,数组的元素是有10个int指针的数组
int (*)[5] 一个指针,指向的内容是有五个int的数组
int *[10][5] 一个10*5的数组,数组的元素是int指针
int (*[10])[5] 一个大小为5的数组,数组的元素是有10个int指针的数组
#4
你说的这个我知道,我的意思是typedef之后为什么不是
arr5 : int [5]
p_arr5 : int *[5]
arrp10 : int *[10][5]
arr5 : int [5]
p_arr5 : int *[5]
arrp10 : int *[10][5]
#5
不要迷信书、考题、老师、回帖;
要迷信CPU、编译器、调试器、运行结果。
并请结合“盲人摸太阳”和“驾船出海时一定只带一个指南针。”加以理解。
任何理论、权威、传说、真理、标准、解释、想象、知识……都比不上摆在眼前的事实!
以下内容仅供参考:
Run-Time Type Information
Run-time type information (RTTI) is a mechanism that allows the type of an object to be determined during program execution. RTTI was added to the C++ language because many vendors of class libraries were implementing this functionality themselves. This caused incompatibilities between libraries. Thus, it became obvious that support for run-time type information was needed at the language level.
For the sake of clarity, this discussion of RTTI is almost completely restricted to pointers. However, the concepts discussed also apply to references.
There are three main C++ language elements to run-time type information:
The dynamic_cast operator.
Used for conversion of polymorphic types. See dynamic_cast Operator for more information.
The typeid operator.
Used for identifying the exact type of an object.
The type_info class.
Used to hold the type information returned by the typeid operator.
要迷信CPU、编译器、调试器、运行结果。
并请结合“盲人摸太阳”和“驾船出海时一定只带一个指南针。”加以理解。
任何理论、权威、传说、真理、标准、解释、想象、知识……都比不上摆在眼前的事实!
以下内容仅供参考:
Run-Time Type Information
Run-time type information (RTTI) is a mechanism that allows the type of an object to be determined during program execution. RTTI was added to the C++ language because many vendors of class libraries were implementing this functionality themselves. This caused incompatibilities between libraries. Thus, it became obvious that support for run-time type information was needed at the language level.
For the sake of clarity, this discussion of RTTI is almost completely restricted to pointers. However, the concepts discussed also apply to references.
There are three main C++ language elements to run-time type information:
The dynamic_cast operator.
Used for conversion of polymorphic types. See dynamic_cast Operator for more information.
The typeid operator.
Used for identifying the exact type of an object.
The type_info class.
Used to hold the type information returned by the typeid operator.
//char (*(*x[3])())[5];//x是什么类型的变量?
//
//分析C语言声明,关键是搞清楚这个变量是个什么东西(函数、指针、数组),
//是函数那么剩下的就是他的参数和返回值,
//是指针那剩下部分是说明他指向什么,
//是数组剩下的部分就是说明数组的成员是什么类型。
//解析C语言声明规则:
//从左侧第一个标识符开始,按照优先级进行结合。*表示是..的指针,const表示只读的,volatile表示可变的,[]表示是数组,()表示是函数。
//
//x和[3]结合说明是一个大小为3的数组,该数组指向了一个指针,该指针指向一个函数,该函数的无参数,返回一个指针,该指针指向一个大小为5的char型数组
#include <stdio.h>
#include <typeinfo.h>
char num[5];
char (*x00())[5] {
return #
}
int main() {
char (*x000)[5];//返回值
char (*(x00)())[5];//函数原型,参数为空,返回值为指针
char (*(*x0)())[5];//数组的元素,是个函数指针
char (*(*x[3])())[5];//是个数组,大小为3
x0 = x00;
x[0] = x0;
x[1] = x0;
x[2] = x0;
printf("typeid(x).name() is %s\n",typeid(x).name());
return 0;
}
//typeid(x).name() is char (* (__cdecl**)(void))[5]