A
arnuld
this works fine, any advice for improvement:
------------- PROGRAMME ------------------
/* Stroustrup, 5.9, exercise 10
STATAMENT:
define an array of strings,where strings contains the names months
.. Print those strings. Pass the array to a function that prints those
strings.
SOLUTION:
1.) 1st, i will print array int he "main" using "for" loop
and array indexing.
2.) then i wil print he array using a function and passing the array
to the function as argument(pass by reference).
NOTICE: this post contains only implementation of (1)
*/
#include<iostream>
void print_arr(const char**, size_t);
int main()
{
const char* arr[] = {"january", "february", "march", "april", "may",
"june",
"july", "august", "september", "october", "november",
"december"};
const size_t arr_size = sizeof(arr) / sizeof(*arr);
for(unsigned int i=0; i < arr_size; ++i)
std::cout << '\t' << arr << std::endl;
return 0;
}
------------ OUTPUT --------------------------
[arch@voodo tc++pl]$ g++ -ansi -pedantic -Wall -Wextra test.cpp
[arch@voodo tc++pl]$ ./a.out
january
february
march
april
may
june
july
august
september
october
november
december
[arch@voodo tc++pl]$
------------- PROGRAMME ------------------
/* Stroustrup, 5.9, exercise 10
STATAMENT:
define an array of strings,where strings contains the names months
.. Print those strings. Pass the array to a function that prints those
strings.
SOLUTION:
1.) 1st, i will print array int he "main" using "for" loop
and array indexing.
2.) then i wil print he array using a function and passing the array
to the function as argument(pass by reference).
NOTICE: this post contains only implementation of (1)
*/
#include<iostream>
void print_arr(const char**, size_t);
int main()
{
const char* arr[] = {"january", "february", "march", "april", "may",
"june",
"july", "august", "september", "october", "november",
"december"};
const size_t arr_size = sizeof(arr) / sizeof(*arr);
for(unsigned int i=0; i < arr_size; ++i)
std::cout << '\t' << arr << std::endl;
return 0;
}
------------ OUTPUT --------------------------
[arch@voodo tc++pl]$ g++ -ansi -pedantic -Wall -Wextra test.cpp
[arch@voodo tc++pl]$ ./a.out
january
february
march
april
may
june
july
august
september
october
november
december
[arch@voodo tc++pl]$