Question is in the title, how do I initialize a char*[] and give values to it in C++, thank you.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Though you’re probably aware, char*[] is an array of pointers to characters, and I would guess you want to store a number of strings. Initializing an array of such pointers is as simple as:
…or if you’re allocating memory on the stack:
You would then probably want to fill the array with a loop such as:
As noted in the comments for this answer, if you’re allocating the array with new (dynamic allocation) remember to delete your array with: