char[] doesnt end with '/0'?

May 9, 2013 at 6:14pm
Hi I am brushing back up on char arrays, in the c++ primer it says that is you declare and char array like this, the compiler adds a null terminate to the end:
 
   char cstr[]{"test"};


should be equal to:
 
char cstr[]{"'t','e','s','t','/0'}; 


However when I do a for loop like this, it results in a infinite loop never finding the null terminate character:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <vector>


using namespace std;

int main()
{

 char cstr[]{"test"};

 for(char *i = begin(cstr); *i != '/0';++i)
    cout << *i << " ";
}


I understand other methods to loop thru an array, but I wanna know whats going on. Thank you to anyone that helps.
May 9, 2013 at 6:20pm
Null character is '\0' not '/0'

Last edited on May 9, 2013 at 6:20pm
May 9, 2013 at 6:20pm
'\0'
May 9, 2013 at 6:21pm
lol sometimes it just takes a fresh pair of eyes, thanks guys/girls..
Topic archived. No new replies allowed.