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

  • SEARCH
  • Home
  • 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 8367387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:08:38+00:00 2026-06-09T13:08:38+00:00

This may be because I’m new to C programming, but if I recall my

  • 0

This may be because I’m new to C programming, but if I recall my lecturer correctly

PART 1)
execvp(2) takes 2 arguments (obv), the first being the command, and the second being an array of strings such as

char *args[] = {"ls", "-l", "-a", NULL};

Can I please have an explanation of how char *args[] would make this an array of strings rather than an array with chars in it (a C null terminated string)?

PART 2)

How can I make it so that I can add to this array string by string? Could I possibly do

int i;
char *args[255];

for(i = 0; i < strlen(lol); i++)
{
    args[i] = //new string being passed in at runtime
}

and would it work like that? Say I was breaking up input from stdin and I wanted to put arguments into args[i].

  • 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-09T13:08:40+00:00Added an answer on June 9, 2026 at 1:08 pm

    This declaration char *args[] can be deciphered as “args is an array of pointers to char”.
    This means that each entry of an array is pointing to some location where one or more chars are located.

    When you do a static initialization declaring args, compiler reserves the space for exactly the number of initializers you have, each having pointer to char type (in your case, there are 4 pointer in the array).

    For each of the initializing strings a compiler reserves space (typically in read-only data segment) and puts individual characters there with the null being the last character. The array args contains the pointers to this locations. Thus, you have a level of indirection there.

    args[0] ---- points at memory location where 3 chars are -----> 'l', 's', '\0'
    

    Regarding 2), you can do that since args as an array of pointers (and not a 2D array). However you should assign the correct memory locations where the null-terminated sequences of characters are. But you have to be sure that you args array is of an appropriate size. In case one when no size is given during array declaration, compiler allocates enough space only for the supplied initializers and it won’t be possible to change the size later.

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

Sidebar

Related Questions

This may be the wrong place but this is new to me. I did
This may sound like a noob question, because it is. I have tried for
I may get some heat for this question because there are a lot out
Disclaimer : I kept this because some things may be useful to others, however,
This may be a stupid question but I have a code with the following
This may be have a better name than custom tab completion, but here's the
This may be a simple question but I can;t find the answer anywhere. Here
this may sound a newbie question anyway Im new to GCD, I'm creating and
This may sound like a very generic question but here it goes. I have
This may be because I am just unfamiliar with xcode as I am just

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.