How to compile, run C, C + + programs under Linux?

Source: Internet
Author: User
The most important software development tool in Linux is GCC. GCC is the GNU C and C + + compiler. In fact, GCC can compile three kinds of C, C + +, and object C (an object-oriented extension of the C language). Use the GCC command to compile and connect both C and C + + source programs at the same time.

#DEMO #: HELLO.C

If you have two or a few C sources, you can also easily compile, connect, and build executables using GCC. For example, suppose you have two source files Main.c and factorial.c two source files, now you want to compile a program that generates a factorial calculation.

-----------------------
List FACTORIAL.C
-----------------------
#include <stdio.h>
#include <stdlib.h>

int factorial (int n)
{
if (n <= 1)
return 1;

Else
return factorial (n-1) * n;
}
-----------------------

-----------------------
List MAIN.C
-----------------------
#include <stdio.h>
#include <stdlib.h>

int factorial (int n);

int main (int argc, char **argv)
{
int n;

if (ARGC < 2) {
printf ("Usage:%s n\n", argv [0]);
return-1;
}
else {
                           n & nbsp  =    atoi     (argv[1]);  

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.