Stroustrup 5.9, exercise 1
------ PROGRAMME -----------
/* Stroustrup, 5.9, exercises
to write some declarations (with initializers)
comments explain what we intend to do
*/
#include<iostream>
int main()
{
// a pointer to a character
char c1 = 'a';
char* pc1 = &c1;
// an array of 10 integers
const int arr_size = 10;
char arr_int[arr_size];
// a reference to an array of 10 integers
char& r_arr_int = arr_int;
// a pointer to an array of character strings
/* SORRY but i do not know how to present an array
of character strings */
// a pointer to a pointer to a char
char c;
char* pc = &c;
char* ppc = pc;
// a constant integer
const int ci = 7;
// a pointer to a constant integer
const int* pci = &ci;
// a constant pointer to an integer
int j = 8;
int *const cpi = &j;
return 0;
}
--------- OUTPUT ---------------
[arch@voodo tc++pl]$ g++ 5.9_ex-01.cpp
5.9_ex-01.cpp: In function 'int main()':
5.9_ex-01.cpp:23: error: invalid initialization of non-const reference
of type 'char&' from a temporary of type 'char*'
[arch@voodo tc++pl]$
-----------------------------------
i did not use "-ansi -W" flags as they were emitting warnings i did
not need to correct at this moment. i know that this is an error:
// a reference to an array of 10 integers
char& r_arr_int = arr_int;
i dont find any way to create a reference to an integer. BTW, are all
declarations fine ?