3 Answers
New Answer"I want to use **trip" #include <stdio.h> #include <stdlib.h> int main() { char **trip = malloc(3 * sizeof(char *)); // Dynamic allocation for 3 pointer to char trip[0] = "suitcase"; trip[1] = "passport"; trip[2] = "ticket"; printf("Please bring the following:\n"); for (int i = 0; i < 3; i++) { printf("%s\n", *(&trip[0] + i) ); // dereference the base address of each string } free(trip); // Free up the memory return 0; }
#include <stdio.h> int main() { char *trip[3] = { // char **trip --> char *trip[3] -- trip is a pointer of 3 chars "suitcase", "passport", "ticket" }; printf("Please bring the following:\n"); for (int i = 0; i < 3; i++) { printf("%s\n", trip[i]); // trip --> trip[i] } return 0; }