J
jeff_hann
Hi everyone. I'm a newbie in c++ and I have a question related to the
an exercise in Stroustrup's book, namely
5.9/8. It's about iterations in a given array using pointers vs using
indexes. The indexes one I managed to write, but when I try to execute
the pointer variant (it compiles ok on BSD and Linux also) , I get the
string I wanted to see plus lots of gibberish and a segfault. What's
wrong? Here's the code :
1 #include <iostream>
2
3 using namespace std;
4
5
6
7 int main()
8 {
9 int i;
10 char *p;
11 char v[] = "Testing...";
12
13 for(p = v; p != 0; p++)
14 cout << *p << endl;
15
16 return 0;
17 }
an exercise in Stroustrup's book, namely
5.9/8. It's about iterations in a given array using pointers vs using
indexes. The indexes one I managed to write, but when I try to execute
the pointer variant (it compiles ok on BSD and Linux also) , I get the
string I wanted to see plus lots of gibberish and a segfault. What's
wrong? Here's the code :
1 #include <iostream>
2
3 using namespace std;
4
5
6
7 int main()
8 {
9 int i;
10 char *p;
11 char v[] = "Testing...";
12
13 for(p = v; p != 0; p++)
14 cout << *p << endl;
15
16 return 0;
17 }