Struct Array Initialization and String Literals

Posted by Christian Ammer on Stack Overflow See other posts from Stack Overflow or by Christian Ammer
Published on 2010-05-05T07:34:20Z Indexed on 2010/05/05 7:38 UTC
Read the original article Hit count: 248

Filed under:

Is following array initialization correct? I guess it is, but i'm not really sure if i can use const char* or if i better should use std::string. Beside the first question, do the char pointers point to memory segments of same sizes?

struct qinfo
{
    const char* name;
    int nr;
};
qinfo queues[] = {
    {"QALARM", 1},
    {"QTESTLONGNAME", 2},
    {"QTEST2", 3},
    {"QIEC", 4}
};

© Stack Overflow or respective owner

Related posts about c++