几种编程语言的主要格式

本文收录整理几种我自己接触过的编程语言的格式,包括
c
c++
c#
java
python

记录于此,以免以后要使用的时候,连helloworld都写不出来,让人笑话

[c]

#include <stdio.h>

int main() {

   printf("Hello, World! \n");

   return 0;
}

[c++]

#include <iostream>

int main()
{ std::cout << "Hello World!"; }
#include <iostream>
using namespace std;

int main ()
{
  cout << "Hello World! ";
  cout << "I'm a C++ program";
}

[c#]

using System;
namespace HelloWorld {
    class Hello {
        static void Main() 
        {
            Console.WriteLine("Hello World!");

            // Keep the console window open in debug mode.
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
    }
}

java

//import *
public class HelloWorld {

    public static void main(String[] args) {
        // Prints "Hello, World" to the terminal window.
        System.out.println("Hello, World");
    }

}

python

# coding: utf-8

import sys

def foo():
    print "Hello World"
    pass

if __name__ == '__main__':
    foo()

附上一张很好的结构图:

几种编程语言的主要格式_第1张图片

你可能感兴趣的:(几种编程语言的主要格式)