Starting int main ()

0

Good evening, I have a question about this initialization of the main (), our professor of this subject gave it to us like that. Can someone explain to me what is it for? The topics we are looking at are files (binaries and text) and links with nodes

int main (int argc, char* argv[]){
    for (int i=1; i < argc; i++){
    cout << argv[i] << endl;
}
    
asked by Uso Compartido 24.10.2017 в 02:32
source

1 answer

2

I get the feeling that you have several misunderstood concepts or that you do not know how to express them well.

  

This initialization of the main ()

The main function is not initialized. The function main is the entry point of the application, as a function can be declared and defined. Initialization is something reserved for objects and variables, not functions.

  

Can anyone explain to me what is it for?

The code you show is so simple that it should be self explanatory, I summarize it:

    for (int i=1; i < argc; i++){
    cout << argv[i] << endl;
}

It is a for loop that defines a variable of type integer ( int ) and name i that gets as initial value 1 ( int i=1 ) and that will increase its value one by one ( i++ ) to be strictly less than the variable argc ( i < argc ) that has been received as a parameter of main .

In the body of the loop, two bit offset operators << are linked to the cout object applied to the pointer argv (received as a parameter) that is being indexed by the variable i ( argv[i] ) and on the object endl .

Documentation.

Errors.

The code you have shared does not compile.

  • Lack of inclusion <iostream> .
  • You use objects from the namespace std without a using .
  • The main function has no return (although this does not prevent it from compiling).
  • The closing key of the function main is missing.

Council.

Review the basics of C ++.

    
answered by 24.10.2017 в 09:09