Stroustrup 5.9,练习3 [英] Stroustrup 5.9, exercise 3
问题描述
我做了我能在Best做的事来解决这个练习,这就是我想要的
:
----- ------计划--------------
/ * Stroustrup 5.9,练习3
声明:
使用typedef定义类型:
unsigned char
const unsigned char
指向整数
指向char的指针
指向char数组的指针
指针到指向iint的7个指针的数组
8个数组,每个指向7个指针的数组
* /
#include< iostream>
int main()
{
typedef unsigned char Uchar;
typedef const unsigned char CUchar;
typedef int * Pi;
typedef char ** PPi;
//定义一个类型指向char数组的指针
//使用typedef
const int arr_size = 10;
char arr [arr_size ];
char * pac =& arr;
typedef pac PAchar;
//为...定义类型;指向int的7个指针的数组>
//使用typedef
const int arr_size2 = 7;
typedef int * arr2 [arr_size2] Arr7Pint ;
//定义
的类型//指向指向int的7个指针数组的指针
//使用typedef
int ** ppi = arr2;
typedef ppi PPint;
//定义类型for
//8个指向init的7个指针数组的数组
//使用typedef
const int arr_size3 = 8;
PPint arr3 [arr_size3];
返回0;
}
- -----------输出----------------
[arch @ voodo tc ++ pl] $ g ++ 5.9_ex- 03.cpp
5.9_ex-03.cpp:在函数''int main()''中:
5.9_ex-03.cpp:31:错误:无法转换''char(*)[10]''到'char *''在
初始化
5.9_ex-03.cpp:32:错误:''pac''没有命名类型
5.9_ex-03.cpp:37:错误:预期的初始化程序之前''Arr7Pint''
5.9_ex-03.cpp:42:错误:''arr2''未在此范围内声明
5.9_ex-03.cpp: 43:错误:''ppi''没有命名类型
5.9_ex-03.cpp:49:错误:''PPint''未在此范围内声明
5.9_ex-03.cpp:49:错误:预期`;''在''arr3'之前''
[arch @ voodo tc ++ pl] $
i did what i could do at Best to solve this exercise and this i what i
have come up with:
----------- PROGRAMME --------------
/* Stroustrup 5.9, exercise 3
STATEMENT:
Use typedef to define the types:
unsigned char
const unsigned char
pointer to integer
pointer to pointer to char
pointer to array of char
array of 7 pointers to int
pointer to an array of 7 pointers to iint
array of 8 arrays of 7 pointers to int
*/
#include<iostream>
int main()
{
typedef unsigned char Uchar;
typedef const unsigned char CUchar;
typedef int* Pi;
typedef char** PPi;
// to define a type for "pointer to an array of char"
// using typedef
const int arr_size = 10;
char arr[arr_size];
char* pac = &arr;
typedef pac PAchar;
// to define a type for "array of 7 pointers to int"
// using typedef
const int arr_size2 = 7;
typedef int* arr2[arr_size2] Arr7Pint;
// to define a type for
// "a pointer to an array of 7 pointers to int"
// using typedef
int** ppi = arr2;
typedef ppi PPint;
// to define a type for
// "array of 8 arrays of 7 pointers to init"
// using typedef
const int arr_size3= 8;
PPint arr3[arr_size3];
return 0;
}
------------ OUTPUT ----------------
[arch@voodo tc++pl]$ g++ 5.9_ex-03.cpp
5.9_ex-03.cpp: In function ''int main()'':
5.9_ex-03.cpp:31: error: cannot convert ''char (*)[10]'' to ''char*'' in
initialization
5.9_ex-03.cpp:32: error: ''pac'' does not name a type
5.9_ex-03.cpp:37: error: expected initializer before ''Arr7Pint''
5.9_ex-03.cpp:42: error: ''arr2'' was not declared in this scope
5.9_ex-03.cpp:43: error: ''ppi'' does not name a type
5.9_ex-03.cpp:49: error: ''PPint'' was not declared in this scope
5.9_ex-03.cpp:49: error: expected `;'' before ''arr3''
[arch@voodo tc++pl]$
推荐答案
g ++ 5.9_ex-03.cpp
5.9_ex-03.cpp:在函数''int main()''中:
5.9_ex-03.cpp:31:错误:无法将''char(*)[10]''转换为''char *''
初始化
5.9_ex-03.cpp:32:错误:''pac''没有命名类型
5.9_ex-03.cpp:37:错误:预期的初始化程序之前''Arr7Pint''
5.9_ex-03.cpp:42:错误:''arr2''不是de在这个范围内进行了抨击
5.9_ex-03.cpp:43:错误:''ppi''没有命名类型
5.9_ex-03.cpp:49:错误:''PPint''未在此范围内声明
5.9_ex-03.cpp:49:错误:预期`;''在''arr3'之前''
[arch @ voodo tc ++ pl]
g++ 5.9_ex-03.cpp
5.9_ex-03.cpp: In function ''int main()'':
5.9_ex-03.cpp:31: error: cannot convert ''char (*)[10]'' to ''char*'' in
initialization
5.9_ex-03.cpp:32: error: ''pac'' does not name a type
5.9_ex-03.cpp:37: error: expected initializer before ''Arr7Pint''
5.9_ex-03.cpp:42: error: ''arr2'' was not declared in this scope
5.9_ex-03.cpp:43: error: ''ppi'' does not name a type
5.9_ex-03.cpp:49: error: ''PPint'' was not declared in this scope
5.9_ex-03.cpp:49: error: expected `;'' before ''arr3''
[arch@voodo tc++pl]
" arnuld" < ge ********* @ gmail.comwrote in message
news:11 ********************* @ y66g2000hsf.googlegro ups.com ...
"arnuld" <ge*********@gmail.comwrote in message
news:11*********************@y66g2000hsf.googlegro ups.com...
>我做了我能在Best做的事来解决这个练习,这个我是什么我
想出了:
------------ OUTPUT ----------------
[arch @ voodo tc ++ pl]
>i did what i could do at Best to solve this exercise and this i what i
have come up with:
------------ OUTPUT ----------------
[arch@voodo tc++pl]
这篇关于Stroustrup 5.9,练习3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!