The "first attempt" doesn't compile while the second does. Why? What's the difference?
First attempt:
#include <iostream> int main() { constexpr const char text2[] = "hello"; constexpr const char * b = &text2[4]; // error: '& text2[4]' is not a constant expression std::cout << b << std::endl; } Second attempt:
#include <iostream> int main() { constexpr const char * text1 = "hello"; constexpr const char * a = &text1[4]; std::cout << a << std::endl; return 0; } I compile with (g++ version 4.9.2)
g++ -std=c++11 -o main *.cpp which gives following error
main.cpp: In function 'int main()': main.cpp:7:40: error: '& text2[4]' is not a constant expression constexpr const char * b = &text2[4]; // error: '& text2[4]' is not a constant expression