Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8880965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:15:16+00:00 2026-06-14T20:15:16+00:00

Say you have a program like this #include <stdio.h> int main (void) { char

  • 0

Say you have a program like this

#include <stdio.h>

int
main (void)
{
  char **foo;
  foo = malloc (100);
  foo[0] = "cat";
  foo[1] = "dog";
  foo[2] = "bird";
  return 0;
}

How could you iterate the array, for example printing all the elements, without hard coding the upper bound?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:15:17+00:00Added an answer on June 14, 2026 at 8:15 pm

    Since you want to do :

    foo[0] = "cat";
    

    which stores the address of string literal into the elements of array foo, each element of the array must be of type char pointer. But you are doing:

    foo = malloc (100);
    

    which makes each element of foo a char and not char pointer.

    What you need it:

    foo = malloc (100 * sizeof(char*));
    

    To iterate over the filled elements of the array, you can keep an explicit counter equal to the number of elements filled

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say, that I have a program code like this: #include <iostream> #include <Windows.h>
Lets say I have hierarchy like this (This is just a test program. Please
So we have code like: #include cpptk.h #include <stdio.h> using namespace Tk; void hello()
I have a program that call a function with undefined arguments, like this: #include
Lets say have this immutable record type: public class Record { public Record(int x,
Let's say I have this Hello.scala. object HelloWorld { def main(args: Array[String]) { println(Hello,
Okay so my question is this. Say I have a simple C++ code: #include
Say I have some program-wide information, like the root directory of the program or
The following program gives a signed/unsigned mismatch warning: #include <iostream> int main() { unsigned
Say I have simple program that emulates a board game with a number of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.