0

Usage of *p[ ]

How can I use a pointer *p[3] without using any array to store multiple strings in C program?

24th Nov 2018, 8:17 AM
Abdus Samee
Abdus Samee - avatar
3 Respostas
+ 6
`char *p[3]` says "p is an array of 3 pointer to char" which indicates it's already an array and you're gonna store some C-string on that like so char *p[3] = {"First", "Second", "Third"};
24th Nov 2018, 8:37 AM
Babak
Babak - avatar
0
How will you use it without assigning strings beforehand ?
24th Nov 2018, 2:34 PM
Abdus Samee
Abdus Samee - avatar
0
You have to either set a size for each char* (with malloc or as static arrays) and set the first character to 0 (so that it is a string and not only a char*) Then, it depends on what you want to do after that. With malloc solution, you may want to use it after some user inputs
24th Nov 2018, 2:55 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar