J
Jess
Hi,
If I have an array of pointer like:
char* a[] = {"a","b","c"};
then it works fine. Since "a" is effectively "a" char**, I tried the
following, which doesn't work:
char** a = {"a","b","c"};
What's wrong here?
I also tried the following program:
#include<iostream>
#include<string>
using namespace std;
void f1(char* a[]){
cout << "in f1" << endl;
for (size_t i = 0; i < 3; i++)
cout << *(a) << endl;
}
void f2(char** a){
cout << "in f2" << endl;
for (size_t i = 0; i < 3; i++)
cout << *(a) << endl;
}
int main(){
char* a[] = {"a","b","c"};
for (size_t i = 0; i < 3; i++)
cout << *(a) << endl;
f1(a);
f2(a);
return 0;
}
Then it works fine. So, when I pass an array to an function, I can
treat it as char**, but not when I define it?
Thanks,
Jess
If I have an array of pointer like:
char* a[] = {"a","b","c"};
then it works fine. Since "a" is effectively "a" char**, I tried the
following, which doesn't work:
char** a = {"a","b","c"};
What's wrong here?
I also tried the following program:
#include<iostream>
#include<string>
using namespace std;
void f1(char* a[]){
cout << "in f1" << endl;
for (size_t i = 0; i < 3; i++)
cout << *(a) << endl;
}
void f2(char** a){
cout << "in f2" << endl;
for (size_t i = 0; i < 3; i++)
cout << *(a) << endl;
}
int main(){
char* a[] = {"a","b","c"};
for (size_t i = 0; i < 3; i++)
cout << *(a) << endl;
f1(a);
f2(a);
return 0;
}
Then it works fine. So, when I pass an array to an function, I can
treat it as char**, but not when I define it?
Thanks,
Jess