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 8821413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:50:54+00:00 2026-06-14T05:50:54+00:00

Possible Duplicate: argc and argv in main I’m having difficulty understanding the notation used

  • 0

Possible Duplicate:
argc and argv in main

I’m having difficulty understanding the notation used for the general main function declaration, i.e. int main(int argc, char *argv[]). I understand that what is actually passed to the main function is a pointer to a pointer to char, but I find the notation difficult. For instance:

Why does **argv point to the first char and not the whole string? Likewise, why does *argv[0] point to the same thing as the previous example.

Why does *argv point to the whole first string, instead of the first char like the previous example?

This is a little unrelated, but why does *argv + 1 point a string ‘minus the first char’ instead of pointing to the next string in the array?

  • 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-14T05:50:56+00:00Added an answer on June 14, 2026 at 5:50 am

    Consider a program with argc == 3.

       argv
         |
         v
    +---------+         +----------------+
    | argv[0] |-------->| program name\0 |
    +---------+         +-------------+--+
    | argv[1] |-------->| argument1\0 |
    +---------+         +-------------+
    | argv[2] |-------->| argument2\0 |
    +---------+         +-------------+
    |    0    |
    +---------+
    

    The variable argv points to the start of an array of pointers. argv[0] is the first pointer. It points at the program name (or, if the system cannot determine the program name, then the string for argv[0] will be an empty string; argv[0][0] == '\0'). argv[1] points to the first argument, argv[2] points to the second argument, and argv[3] == 0 (equivalently argv[argc] == 0).

    The other detail you need to know, of course, is that array[i] == *(array + i) for any array.

    You ask specifically:

    • Why does **argv point to the first char and not the whole string?

    *argv is equivalent to *(argv + 0) and hence argv[0]. It is a char *. When you dereference a char *, you get the ‘first’ character in the string. And **argv is therefore equivalent to *(argv[0]) or *(argv[0] + 0) or argv[0][0].

    (It can be legitimately argued that **argv is a character, not a pointer, so it doesn’t ‘point to the first char’. It is simply another name for the 'p' of "program name\0".)

    • Likewise, why does *argv[0] point to the same thing as the previous example.

    As noted before, argv[0] is a pointer to the string; therefore *argv[0] must be the first character in the string.

    • Why does *argv point to the whole first string, instead of the first char like the previous example?

    This is a question of convention. *argv points at the first character of the first string. If you interpret it as a pointer to a string, it points to ‘the whole string’, in the same way that char *pqr = "Hello world\n"; points at ‘the whole string’. If you interpret it as a pointer to a single character, it points to the first character of the string. Think of it as like wave-particle duality, only here it is character-string duality.

    • Why does *argv + 1 point a string ‘minus the first char’ instead of pointing to the next string in the array?

    *argv + 1 is (*argv) + 1. As already discussed, *argv points at the first character of the first string. If you add 1 to a pointer, it points at the next item; since *argv points at a character, *argv+1 points to the next character.

    *(argv + 1) points to the (first character of the) next string.

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

Sidebar

Related Questions

Possible Duplicate: Why no switch on pointers? int main(int argc, char** argv) { void*
Possible Duplicate: Why does printf print wrong values? #include<stdio.h> int main(int argc, const char
Possible Duplicates: main(int argc, char *argv[]) Main's Signature in C++ If i write: int
Possible Duplicate: Is array name a pointer in C? #include <stdlib.h> int main(int argc,
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: What is the proper declaration of main? I am working on my
Possible Duplicate: Why is the type of the main function in C and c++
Possible Duplicate: Standard way to define parameter-less function main() in C Can I use
Possible Duplicate: std::bind a bound function void foo0(int val) { std::cout << val <<
Possible Duplicates: What are the arguments to main() for? What does int argc, char

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.