C Language Learning 011: main Function with parameters, language learning 011

Source: Internet
Author: User

C Language Learning 011: main Function with parameters, language learning 011

Directly Add code

1 # include <stdio. h> 2 3 int main (int argc, char * argv []) {4 printf ("% I \ n", argc); 5 int I; 6 for (I = 0; I <argc; I ++) {7 printf ("% s \ n", argv [I]); 8} 9 10 return 0; 11}

In the above main method, the first parameter argc represents the number of elements in the array, and the second parameter * argv represents the parameter array, that is, argc represents the length of * argv; interestingly, * the first element of argv is the program name.

 

The parameters must be separated by spaces. Otherwise, the parameters will be connected to each other.

At the same time, the program cannot contain the main function without parameters and the main function with parameters at the same time. During compilation, a prompt will be prompted to redefine the main function, as shown in

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.