Write Hello, world on Mac using Terminal

Source: Internet
Author: User

No matter which language you want to learn, there are almost no exceptions starting with hello and world. Today I am no exception.

Write this articleArticleThe purpose is to use xcode or vs to writeCodeAlmost all are compiled, linked, and run using graphical tools. For a long time, I have no idea what these graphic tools have helped us, and I have no idea what to do after some system environment setup problems.

Mac is a graphical Operating System Based on the Unix kernel.So using terminal for programming is actually a programming in Unix. Here we only demonstrate one of the simplest methods.

1. First open the terminal application and run the CD command to the location where you want to create the file.

2. Then open the nano Editor, such as nano helloworld. C. Then open the nano editor and automatically name the file to be written as helloworld. C.

3. In the nano Editor, enter

# Include <stdio. h>

Int main ()

{

Printf ("jackysay Hello to you \ n ");

Return 0;

}

4. Press the shortcut key "Control + X" in the nano editor to exit the nano editor. The Nano will prompt you to save the file and enter "Y ".

5. Input GCC helloworld. C-o XXX in terminal to generate a xxx that can run.Program

6. Input./xxx to run the program. You can see that "Jacky say hello to you" is output on the terminal screen.

I have two questions)

1. As for # include <stdio. h>, this line of code contains this file, but I did not find the stdio. h file in my Mac. Why?

2. Even if the stdio. h file is found above, where is the implementation file of the function called printf in the following code? It is estimated that it should be a library file. Where is the library file? Or is there no library file, just like the Java Virtual Machine Concept, the user must ensure that the library file corresponding to stdio. H will be installed on the machine running the program? Thus, the compiled program contains library files and the size of the compiled program is omitted?

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.