My first c program in Ubuntu (with the installation of gcc and g ++ in Ubuntu)

Source: Internet
Author: User
My first c program under Ubuntu (with the gcc and g ++ installation methods under Ubuntu)-General Linux technology-Linux programming and kernel information. The following is a detailed description. The Code is as follows:
Open the text editor and run the following code:
# Include
Main ()
{
Int k;
For (k = 0; k <3; k ++)
Add ();

}

Add ()
{
Static int x = 0;
X ++;
Printf ("x = % d \ n", x );
}
Save the file as z. c.

Then, open the command line window. After entering the directory where z. c is located
Type: $ gcc-o z. c
I found that I could not get the normal result. I searched the internet and found that ubuntu didn't install the C language compiler by default.

However, to install gcc, you only need to run the following command:
Sudo apt-get install build-essential
The sudo command is very important. If you skip it, the system will prompt that your permissions are insufficient.
Press enter, enter the password, and then hand it over to the system. It takes some time to download the package from the Internet and install it later.

Then
Type: $ gcc-o z. c
You can open a file named c in the corresponding folder.
Enter./z.
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.