Questions tagged [argc]

The number of arguments given to the program, found as a parameter to main in some languages, notably C.

argc stands for argument count, and represents the number of arguments given to the program, or main, in a command-line. It is used in conjunction with .

Keep in mind that argc also counts the program name.

Notable Stack Overflow questions:

243 questions
679
votes
13 answers

What does int argc, char *argv[] mean?

In many C++ IDE's and compilers, when it generates the main function for you, it looks like this: int main(int argc, char *argv[]) When I code C++ without an IDE, just with a command line compiler, I type: int main() without any parameters. What…
Greg Treleaven
  • 8,124
  • 7
  • 30
  • 30
108
votes
7 answers

Why is argc not a constant?

int main( const int argc , const char[] const argv) As Effective C++ Item#3 states "Use const whenever possible", I start thinking "why not make these 'constant' parameters const"?. Is there any scenario in which the value of argc is modified in a…
Dinushan
  • 2,067
  • 6
  • 30
  • 47
104
votes
8 answers

Regarding 'main(int argc, char *argv[])'

Possible Duplicates: What are the arguments to main() for? What does int argc, char *argv[] mean? Every program is starting with the main(int argc, char *argv[]) definition. I don't understand what it means. I would be very glad if somebody…
user379888
30
votes
5 answers

Why does MPI_Init accept pointers to argc and argv?

this is how we use MPI_Init function int main(int argc, char **argv) { MPI_Init(&argc, &argv); … } why does MPI_Init use pointers to argc and argv instead of values of argv?
Rohit Banga
  • 18,458
  • 31
  • 113
  • 191
13
votes
2 answers

Handle argc equal to 0

I recently saw something curious. In the HHVM source code, the very first 3 lines of the main() function read as follows: if (!argc) { return 0; } It's a bit silly, but still, I just can't help wondering... why return 0!? It's not that I think…
Praxeolitic
  • 22,455
  • 16
  • 75
  • 126
11
votes
3 answers

executing a process with argc=0

Is it possible to execute a process whose argc = 0? I need to execute a program but it is extremely important for its argc to be equal to 0. Is there a way to do that? I tried to put 2^32 arguments in the command line so that it appears as if argc =…
Keeto
  • 4,074
  • 9
  • 35
  • 58
10
votes
2 answers

Why does main(int argc, char* argv[]) take two argument?

I always thought that argc was required to mark the end of argv but I just learned that argv[argc] == NULL by definition. Am I right in thinking that argc is totally redundant? If so, I always thought C made away with redundancy in the name of…
elik
  • 180
  • 1
  • 9
10
votes
5 answers

Process argc and argv outside of main()

If I want to keep the bulk of my code for processing command line arguments out of main (for organization and more readable code), what would be the best way to do it? void main(int argc, char* argv[]){ //lots of code here I would like to move…
Joey Huggins
  • 125
  • 1
  • 1
  • 6
9
votes
2 answers

create argc argv in the code

Hi very newbie question but I just can't figure it out: I have a function named bar class foo { public: bool bar(int argc, char** argv); } argv is supposed to contain "--dir" and "/some_path/" How do I create argv and argc so that I…
KKsan
  • 147
  • 1
  • 1
  • 8
8
votes
1 answer

Argc and Argv in Bash

I written the following script which gets name of a file and then assemble and link the file. But it doesn't work. What is the problem with it? EXPECTED_ARGS=2 if [ $# -ne $EXPECTED_ARGS ] then echo "[+] Assembling with Nasm." nasm…
user7995295
8
votes
2 answers

How to override register_argc_argv in PHP?

I'm using a shared host (fasthostingdirect) and for some reason they have this flag turned off by default. This means I'm unable to access PHP command line parameters... unless I use the -n (= --no-php-info) flag after php.exe. Have tried…
Steve Chambers
  • 37,270
  • 24
  • 156
  • 208
6
votes
1 answer

Using argc and argv in Eclipse?

I have a working program but now I have to use the int argc and char *argv[] parameters to main. Whenever I try to do this it gives me errors that it cannot save. Is there any way to make argc and argv work in Eclipse?
gamergirl22
  • 149
  • 1
  • 4
  • 16
6
votes
4 answers

Notation of **argv in main function

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…
hcaulfield57
  • 431
  • 1
  • 5
  • 10
5
votes
2 answers

FreeBSD/amd64 assembly - how to read "ARGC" from _start?

Sometimes the correct argc value is returned, sometimes 0, and sometimes (seemingly)random numbers... all from the same executable. .section .text .global _start _start: movq $1, %rax popq %rdi syscall For example: %as -o this.o…
timmmay
  • 125
  • 7
5
votes
2 answers

Segmentation fault before entering main

I recently made minor changes to previously-working code, and the program now immediately encounters a segmentation fault upon execution. In fact, it doesn't even make it to the first line in main. Here is the beginning of the code: int main (int…
moosefoot
  • 133
  • 3
  • 11
1
2 3
16 17