Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

513
Views
How to loop through double pointers without knowing size. (C)

How can I loop through this double pointer without knowing it's size.

char *arr[] = {"ant", "bat", "cat", "dog", "egg", "fly"}; 
char **ptr = arr; // Double pointer 

I tried this but I get an error

while (*ptr){
   printf("%s\n",*ptr);
   ptr+=1;
}

I wan't something similar to this but with double pointers.

char *word = *ptr;
for (int i = 0; *(word + i) != '\0'; i++)
{
   printf("%c", *(word + i));
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The reason you can determine the end of a string with \0 is because when you assign one to a pointer a null byte is automatically placed at the end, note that the definition of string is a null terminated array of characters. You can mimic this behavior in an array of strings by adding a NULL element at the end:

char *arr[] = {"ant", "bat", "cat", "dog", "egg", "fly", NULL};
char **ptr = arr;  // Double pointer

while (*ptr) {
    printf("%s\n", *ptr);
    ptr += 1;
}

This is what is called a sentinel.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!