Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#include <stdio.h>
char (*func(void))[20] {
static char foo[10][20];
return foo;
}
/* The syntax can be a bit tricky, a typedef simplifies this */
typedef char (*twod)[20];
twod func2(void) {
static char foo[10][20];
return foo;
}
int main(void) {
char (*arr)[20] = func();
twod ar2 = func2();
int r, c;
for ( r = 0 ; r < 10 ; r++ ) {
for ( c = 0 ; c < 20 ; c++ ) {
arr[r][c] = 0;
ar2[r][c] = 0;
}
}
return 0;
}
#include <cstring>
#include <iostream>
using std::cout;
using std::endl;
class CCharArray
{
public:
CCharArray()
{
strcpy( m_String[0], "One" );
strcpy( m_String[1], "Two" );
strcpy( m_String[2], "Three" );
strcpy( m_String[3], "Four" );
strcpy( m_String[4], "Five" );
}
virtual ~CCharArray() {};
const char* Get( unsigned int index )
{
return m_String[index];
}
void Get2( const char* pszArray[5] )
{
for ( int nCount = 0; nCount < 5; ++nCount )
{
pszArray[nCount] = m_String[nCount];
}
}
private:
char m_String[5][20];
};
int main( void )
{
CCharArray cArray;
const char* pszArray[5];
cArray.Get2( pszArray );
cout << endl << pszArray[0] << endl << pszArray[1] << endl << pszArray[2]
<< endl << pszArray[3] << endl << pszArray[4] << endl;
cout << endl << cArray.Get(0) << endl << cArray.Get(1) << endl << cArray.Get(2)
<< endl << cArray.Get(3) << endl << cArray.Get(4) << endl;
return 0;
}
#include<iostream>
char **foo()
{
static char *bas[] ={
"Hello 1",
"Hello 2",
"Hello 3"
};
std::cout<<"bas = "<<&bas<<std::endl;
return bas;
}
int main()
{
char **bar = foo();
std::cout<<"bar here = "<<bar<<std::endl;
for(int i=0;i<3;i++)
std::cout<<bar[i]<<std::endl;
return 0;
}
#include <iostream>
#include <cstring>
class CTest
{
public:
CTest()
{
strcpy( m_String[0], "one" );
strcpy( m_String[1], "two" );
strcpy( m_String[2], "three" );
}
char **foo()
{
std::cout << "bas = " << &m_String << std::endl;
return m_String;
}
private:
char* m_String[3];
};
int main()
{
CTest test;
char **bar = test.foo();
std::cout << "bar here = " << bar << std::endl;
for( int i=0; i<3; i++ )
{
std::cout << bar[i] << std::endl;
}
return 0;
}