Hello, world!: 두 판 사이의 차이

Gaon12 (토론 / 기여)
어셈블리, 몰랭 등 추가
내용 보강 및 코드 예시 추가
 
(다른 사용자 한 명의 중간 판 하나는 보이지 않습니다)
1번째 줄: 1번째 줄:
<syntaxhighlight lang='C'>
<syntaxhighlight lang="c">
#include <stdio.h>
#include <stdio.h>int main(void)
{
printf("Hello, world!\n");


int main()
return 0;
{
printf("Hello, world!");


return 0;
}
}
</syntaxhighlight>
</syntaxhighlight>


<syntaxhighlight lang='C'>
<syntaxhighlight lang="c">
#include <stdio.h>
#include <stdio.h>int main(void)
{
printf("안녕 세상아!\n");


int main()
return 0;
{
printf("안녕 세상아!");


return 0;
}
}
</syntaxhighlight>
</syntaxhighlight>


컴퓨터 언어들에서 가장 기본으로 배우는 내용인 '''Hello, world!'''에 대해 다룬다.
'''Hello, world!'''는 프로그래밍을 처음 배울 때 가장 널리 사용되는 예제 문장이다. 일반적으로 화면, 콘솔, 터미널, 로그 등에 짧은 문자열을 출력하는 프로그램을 작성함으로써 개발 환경이 정상적으로 설치되었는지, 소스 코드가 올바르게 실행되는지, 기본 입출력 문법을 이해했는지 확인하는 데 사용된다.
거의 모든 프로그래밍 책들은 국룰로 처음에 '''Hello, world!'''로 시작하며, 이는 데니스 리치가 쓴 책인 "The C Programming Language" 교재의 첫 번째 예제가 화면이 "Hello, world!"를 출력하는 것이었기 때문이었다.  


많은 프로그래밍 입문서와 튜토리얼은 첫 예제로 '''Hello, world!'''를 사용한다. 이 관례는 브라이언 커니핸(Brian W. Kernighan)이 작성한 B 언어 튜토리얼의 예제와, 브라이언 커니핸과 데니스 리치(Dennis Ritchie)가 함께 쓴 《The C Programming Language》의 C 언어 예제를 통해 널리 알려졌다.<ref name="bell-b">B. W. Kernighan, ''A Tutorial Introduction to the Language B'', Bell Laboratories.</ref><ref name="kr-c">Brian W. Kernighan, Dennis M. Ritchie, ''The C Programming Language''.</ref>
== 개요 ==
'''Hello, world!''' 프로그램은 보통 다음 목적을 가진다.
* 개발 환경이 정상적으로 설치되었는지 확인한다.
* 컴파일러, 인터프리터, 런타임, 셸, 브라우저 등의 실행 흐름을 확인한다.
* 문자열 출력, 함수 호출, 프로그램 진입점 등 가장 기본적인 문법을 익힌다.
* 새 언어의 코드 구조를 짧은 예제로 비교한다.
다만 언어마다 실행 방식은 다르다. 어떤 언어는 컴파일이 필요하고, 어떤 언어는 인터프리터로 바로 실행되며, 어떤 언어는 브라우저나 특정 런타임, 하드웨어 시뮬레이터가 필요하다.
== 역사 ==
'''Hello, world!'''라는 문구는 C 언어의 대표적인 첫 예제로 널리 알려져 있다. 다만 그 기원은 C 언어 책 하나로만 설명하기보다는, 벨 연구소(Bell Laboratories)에서 작성된 초기 언어 튜토리얼 문맥까지 함께 보는 편이 정확하다.
브라이언 커니핸은 B 언어 튜토리얼에서 외부 변수와 문자 출력을 설명하기 위해 비슷한 형태의 예제를 사용하였다. 이후 《The C Programming Language》에서 C 언어의 첫 예제로 간단한 문자열 출력 프로그램이 제시되면서, '''Hello, world!'''는 새 프로그래밍 언어를 배울 때 처음 작성하는 상징적인 예제가 되었다.
== 표현 차이 ==
언어마다 '''Hello, world!'''를 출력하는 방식은 다음과 같은 차이를 보인다.
== 각 언어로 표현한 Hello, world! ==


==각 언어로 표현한 Hello, world!==
=== Ada ===
=== Ada ===
<syntaxhighlight lang='bash'>
<syntaxhighlight lang="ada">
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Text_IO;
use Ada.Text_IO;


procedure Hello_World is
procedure Hello_World is
begin
begin
  Put_Line("Hello, world!");
Put_Line("Hello, world!");
end Hello_World;
end Hello_World;
</syntaxhighlight>
</syntaxhighlight>


=== ActionScript ===
=== ActionScript ===
<syntaxhighlight lang='actionscript'>
<syntaxhighlight lang="actionscript">
package {
package {
    import flash.display.Sprite;
import flash.display.Sprite;


    public class HelloWorld extends Sprite {
public class HelloWorld extends Sprite {
        public function HelloWorld() {
    public function HelloWorld() {
            trace("Hello, world!");
        trace("Hello, world!");
        }
     }
     }
}
}
}
</syntaxhighlight>
</syntaxhighlight>


=== Agda ===
=== Agda ===
<syntaxhighlight lang='agda'>
<syntaxhighlight lang="agda">
open import IO
open import IO


main = run (putStr "Hello, World!")
main = run (putStr "Hello, world!")
</syntaxhighlight>
</syntaxhighlight>


===Bash===
=== Assembly ===
<syntaxhighlight lang='bash'>
아래 예제는 32비트 리눅스 x86 환경에서 시스템 호출을 사용해 문자열을 출력하는 예이다.
#!/bin/bash


echo "Hello, world!"
<syntaxhighlight lang="nasm">
printf "Hello, world!"
</syntaxhighlight>
 
=== Assembly ===
<syntaxhighlight>
section .data
section .data
     hello:     db 'Hello, World!', 0Ah ; 'Hello, World!' plus a linefeed character
     hello:   db 'Hello, world!', 0Ah
     helloLen: equ $-hello              ; Length of the 'Hello, World!' string
     helloLen: equ $ - hellosection .text
 
global _start
section .bss
 
section .text
    global _start


_start:
_start:
    mov    edx, helloLen               ; Set the length of the string to be written
mov    edx, helloLen
    mov    ecx, hello                 ; Set the address of the string to be written
mov    ecx, hello
    mov    ebx, 1                     ; Set the file descriptor to stdout (1)
mov    ebx, 1
    mov    eax, 4                     ; System call number (sys_write)
mov    eax, 4
    int    80h                         ; Call the kernel
int    80h


    mov    eax, 1                     ; System call number (sys_exit)
mov    eax, 1
    xor    ebx, ebx                   ; Exit with return code 0 (no error)
xor    ebx, ebx
    int    80h                         ; Call the kernel
int    80h


</syntaxhighlight>=== AutoIt ===
<syntaxhighlight lang="autoit">
MsgBox(0, "Message", "Hello, world!")
</syntaxhighlight>
</syntaxhighlight>


=== AutoIT ===
=== Bash ===
<syntaxhighlight lang='autoit'>
<syntaxhighlight lang="bash">
MsgBox(0, "Message", "Hello, world!")
#!/bin/bash
 
echo "Hello, world!"
printf "Hello, world!\n"
</syntaxhighlight>
</syntaxhighlight>


=== Batch ===
=== Batch ===
<syntaxhighlight lang='batch'>
<syntaxhighlight lang="bat">
@echo off
@echo off
echo Hello, world!
echo Hello, world!
</syntaxhighlight>
</syntaxhighlight>


=== BrainFuck ===
=== B ===
<syntaxhighlight lang='brainfuck'>
초기 B 언어 튜토리얼에서는 다음과 같이 여러 외부 변수에 문자열 조각을 나누어 저장한 뒤 출력하는 예제가 사용되었다.
 
<syntaxhighlight lang="c">
main()
{
    extrn a, b, c;putchar(a);
putchar(b);
putchar(c);
putchar('!*n');
 
}
 
a 'hell';
b 'o, w';
c 'orld';
</syntaxhighlight>
 
=== Brainfuck ===
<syntaxhighlight lang="brainfuck">
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++++++++++++++.------------.<<+++++++++++++++.>.+++.------.--------.>+.
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++++++++++++++.------------.<<+++++++++++++++.>.+++.------.--------.>+.
</syntaxhighlight>
</syntaxhighlight>


===C===
=== C ===
<syntaxhighlight lang='C'>
<syntaxhighlight lang="c">
#include <stdio.h>
#include <stdio.h>


int main()
int main(void)
{
{
printf("Hello, world!");
printf("Hello, world!\n");
 
return 0;


return 0;
}
}
</syntaxhighlight>
</syntaxhighlight>


===C++===
=== C++ ===
<syntaxhighlight lang='c++'>
<syntaxhighlight lang="cpp">
#include <iostream>
#include <iostream>


int main(int argc, char* argv[]) {
int main()
    std::cout << "Hello, world!" << std::endl;
{
std::cout << "Hello, world!" << std::endl;
 
return 0;


    return 0;
}
}
</syntaxhighlight>
</syntaxhighlight>


===C#===
=== C# ===
<syntaxhighlight lang='c#'>
<syntaxhighlight lang="csharp">
using System;
using System;
using System.Collections.Generic;
 
using System.Linq;
namespace HelloWorld
using System.Text;
using System.Threading.Tasks;
namespace Hello_World
{
{
    class Program
internal class Program
    {
{
        static void Main(string[] args)
private static void Main(string[] args)
        {
{
            Console.WriteLine("Hello, world!");
Console.WriteLine("Hello, world!");
        }
}
    }
}
}
}
</syntaxhighlight>
=== Common Lisp ===
<syntaxhighlight lang="common-lisp">
(format t "Hello, world!~%")
</syntaxhighlight>
</syntaxhighlight>


=== CSS ===
=== CSS ===
<syntaxhighlight lang='css'>
CSS는 일반적인 프로그래밍 언어라기보다는 스타일시트 언어이다. 아래 예제는 문서의 <code>body</code> 앞에 문자열을 표시한다.
content: "Hello, world!";
 
<syntaxhighlight lang="css">
body::before {
    content: "Hello, world!";
}
</syntaxhighlight>
</syntaxhighlight>


=== D ===
=== D ===
<syntaxhighlight lang='d'>
<syntaxhighlight lang="d">
import std.stdio;
import std.stdio;


void main()
void main()
{
{
    writeln("Hello, world!");
writeln("Hello, world!");
}
}
</syntaxhighlight>
</syntaxhighlight>


===Dart===
=== Dart ===
<syntaxhighlight lang='dart'>
<syntaxhighlight lang="dart">
void main(){
void main() {
print("Hello, world!");
print("Hello, world!");
}
}
</syntaxhighlight>
</syntaxhighlight>


===Fortran===
=== Elixir ===
<syntaxhighlight lang='fortran'>
<syntaxhighlight lang="elixir">
program Helloworld
IO.puts("Hello, world!")
print *,"Hello, world!"
end program
</syntaxhighlight>
</syntaxhighlight>


===HTML===
=== Erlang ===
<syntaxhighlight lang='html'>
<syntaxhighlight lang="erlang">
<!DOCTYPE HTML>
-module(hello).
<html>
-export([main/0]).
<head>
 
<title>Hello!</title>
main() ->
</head>
io:format("Hello, world!~n").
<body>
</syntaxhighlight>
<p>Hello, world!</p>
 
</body>
=== F# ===
</html>
<syntaxhighlight lang="fsharp">
printfn "Hello, world!"
</syntaxhighlight>
 
=== Fortran ===
<syntaxhighlight lang="fortran">
program HelloWorld
print *, "Hello, world!"
end program HelloWorld
</syntaxhighlight>
 
=== Go ===
<syntaxhighlight lang="go">
package main
 
import "fmt"
 
func main() {
fmt.Println("Hello, world!")
}
</syntaxhighlight>
 
=== Groovy ===
<syntaxhighlight lang="groovy">
println "Hello, world!"
</syntaxhighlight>
 
=== Haskell ===
<syntaxhighlight lang="haskell">
main :: IO ()
main = putStrLn "Hello, world!"
</syntaxhighlight>
</syntaxhighlight>


===Java===
=== HTML ===
<syntaxhighlight lang='java'>
HTML은 프로그래밍 언어라기보다는 마크업 언어이다. 아래 예제는 웹 문서에 문자열을 표시한다.
 
<syntaxhighlight lang="html">
<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <title>Hello, world!</title>
</head>
<body>
    <p>Hello, world!</p>
</body>
</html>
</syntaxhighlight>=== Java ===
<syntaxhighlight lang="java">
public class HelloWorld {
public class HelloWorld {
    public static void main(String[] args) {
public static void main(String[] args) {
        System.out.println("Hello, world!");
System.out.println("Hello, world!");
    }
}
}
}
</syntaxhighlight>
</syntaxhighlight>


===JavaScript===
=== JavaScript ===
<syntaxhighlight lang='javascript'>
<syntaxhighlight lang="javascript">
document.write("Hello, world!")
console.log("Hello, world!");
 
document.body.textContent = "Hello, world!";
</syntaxhighlight>
</syntaxhighlight>


===Kotlin===
=== Kotlin ===
<syntaxhighlight lang='kotlin'>
<syntaxhighlight lang="kotlin">
fun main() {
fun main() {
    println("Hello, world!")
println("Hello, world!")
}
}
</syntaxhighlight>
</syntaxhighlight>


=== 몰랭(Mollang) ===
=== Lua ===
<syntaxhighlight>
<syntaxhighlight lang="lua">
몰????.??????????? 모올????.????.?? 모오올몰모올
print("Hello, world!")
아모오올!!!!루 모오올모올 아모오올!!!!!!!루 아모오올루 아모오올루
</syntaxhighlight>
아모오올???루 아몰루 아모올루 몰모올 아몰???????????????????????????????????????????루 아모오올???루
 
아몰모올??????루 아모오올루 아모오올!!!!!!!!루 아모올?루
=== Objective-C ===
<syntaxhighlight lang="objective-c">
#import <Foundation/Foundation.h>
 
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSLog(@"Hello, world!");
}
 
return 0;
 
}
</syntaxhighlight>
 
=== OCaml ===
<syntaxhighlight lang="ocaml">
print_endline "Hello, world!"
</syntaxhighlight>
</syntaxhighlight>


=== Pascal ===
=== Pascal ===
<syntaxhighlight lang='pascal'>
<syntaxhighlight lang="pascal">
program HelloWorld;
 
begin
begin
write('Hello, world!');
writeln('Hello, world!');
end.
end.
</syntaxhighlight>
</syntaxhighlight>


===PHP===
=== Perl ===
<syntaxhighlight lang='PHP'>
<syntaxhighlight lang="perl">
use strict;
use warnings;
 
print "Hello, world!\n";
</syntaxhighlight>
 
=== PHP ===
<syntaxhighlight lang="php">
 
<?php
<?php
echo "Hello, world!";
 
?>
echo "Hello, world!\n";
</syntaxhighlight>
</syntaxhighlight>


=== PowerShell(ps1) ===
=== PowerShell ===
<syntaxhighlight lang='ps1'>
<syntaxhighlight lang="powershell">
Write-Output "Hello, world!"
Write-Output "Hello, world!"
</syntaxhighlight>
</syntaxhighlight>


===Python===
=== Python ===
<syntaxhighlight lang='python'>
<syntaxhighlight lang="python">
print('Hello, world!')
print("Hello, world!")
</syntaxhighlight>
 
=== R ===
<syntaxhighlight lang="r">
cat("Hello, world!\n")
</syntaxhighlight>
 
=== Raku ===
<syntaxhighlight lang="raku">
say "Hello, world!";
</syntaxhighlight>
 
=== Ruby ===
<syntaxhighlight lang="ruby">
puts "Hello, world!"
print "Hello, world!\n"
</syntaxhighlight>
 
=== Rust ===
<syntaxhighlight lang="rust">
fn main() {
    println!("Hello, world!");
}
</syntaxhighlight>
 
=== Scala ===
<syntaxhighlight lang="scala">
object HelloWorld {
    def main(args: Array[String]): Unit = {
        println("Hello, world!")
    }
}
</syntaxhighlight>
 
=== Scheme ===
<syntaxhighlight lang="scheme">
(display "Hello, world!")
(newline)
</syntaxhighlight>
</syntaxhighlight>


=== SQL ===
=== SQL ===
<syntaxhighlight lang='sql'>
SQL은 일반적인 프로그래밍 언어라기보다는 데이터베이스 질의 언어이다. 아래 예제는 문자열 값을 하나의 결과 행으로 조회한다.
 
<syntaxhighlight lang="sql">
SELECT 'Hello, world!' AS greeting;
SELECT 'Hello, world!' AS greeting;
</syntaxhighlight>
</syntaxhighlight>


===Ruby===
=== Swift ===
<syntaxhighlight lang='ruby'>
<syntaxhighlight lang="swift">
puts "Hello, world!"
print("Hello, world!")
print "Hello, world!"
</syntaxhighlight>
 
=== TypeScript ===
<syntaxhighlight lang="typescript">
const message: string = "Hello, world!";
 
console.log(message);
</syntaxhighlight>
</syntaxhighlight>


=== Verilog ===
=== Verilog ===
<syntaxhighlight lang='verilog'>
<syntaxhighlight lang="verilog">
module main;
module main;
   initial begin
   initial begin
      $display("Hello, world!");
    $display("Hello, world!");
      $finish;
    $finish;
    end
  end
endmodule
endmodule
</syntaxhighlight>
</syntaxhighlight>


=== VHDL ===
=== VHDL ===
<syntaxhighlight lang='vhdl'>
<syntaxhighlight lang="vhdl">
use std.textio.all;
use std.textio.all;


275번째 줄: 434번째 줄:
         variable hello : line;
         variable hello : line;
     begin
     begin
         write (hello, String'("Hello, world!"));
         write(hello, String'("Hello, world!"));
         writeline (output, hello);
         writeline(output, hello);
         wait;
         wait;
     end process;
     end process;
end behaviour;
end behaviour;
</syntaxhighlight>
=== Visual Basic .NET ===
<syntaxhighlight lang="vbnet">
Module HelloWorld
    Sub Main()
        Console.WriteLine("Hello, world!")
    End Sub
End Module
</syntaxhighlight>
=== Zig ===
<syntaxhighlight lang="zig">
const std = @import("std");
pub fn main() !void {
    const stdout = std.io.getStdOut().writer();
    try stdout.print("Hello, world!\n", .{});
}
</syntaxhighlight>
== 난해한 프로그래밍 언어의 예시 ==
일부 난해한 프로그래밍 언어는 실용성보다는 표현 방식, 장난성, 언어 설계 실험 자체에 의미가 있다. 따라서 아래 예제들은 일반적인 입문용 예제라기보다는 '''Hello, world!'''가 여러 형태로 변형될 수 있음을 보여 주는 사례에 가깝다.
=== 몰랭(Mollang) ===
<syntaxhighlight lang="text">
몰????.??????????? 모올????.????.?? 모오올몰모올
아모오올!!!!루 모오올모올 아모오올!!!!!!!루 아모오올루 아모오올루
아모오올???루 아몰루 아모올루 몰모올 아몰???????????????????????????????????????????루 아모오올???루
아몰모올??????루 아모오올루 아모오올!!!!!!!!루 아모올?루
</syntaxhighlight>
</syntaxhighlight>


=== 엄랭 ===
=== 엄랭 ===
<syntaxhighlight>
<syntaxhighlight lang="text">
어떻게
어떻게


333번째 줄: 523번째 줄:
어어엄어어어,,,,,,
어어엄어어어,,,,,,
식어어어ㅋ
식어어어ㅋ
어어엄어어어,,,,,,,,
어엄어어어,,,,,,,,
식어어어ㅋ
식어어어ㅋ


344번째 줄: 534번째 줄:
</syntaxhighlight>
</syntaxhighlight>


==분기==
== 활용 ==
'''Hello, world!'''는 단순한 예제이지만 다음과 같은 상황에서 자주 사용된다.
 
* 새 프로그래밍 언어를 처음 배울 때
* 컴파일러 또는 인터프리터 설치를 확인할 때
* 개발 환경, 빌드 도구, 패키지 관리자 설정을 검증할 때
* 웹 서버, 런타임, 컨테이너, 배포 환경의 기본 동작을 확인할 때
* 임베디드 장치나 하드웨어 기술 언어에서 출력 또는 시뮬레이션 동작을 확인할 때
 
== 주의점 ==
'''Hello, world!''' 예제는 언어의 전체 특징을 보여 주지는 않는다. 예를 들어 메모리 관리, 오류 처리, 모듈 시스템, 비동기 처리, 객체 지향, 함수형 프로그래밍, 타입 시스템 같은 핵심 개념은 이 예제만으로 알기 어렵다.
 
또한 일부 예제는 실행 환경에 따라 수정이 필요할 수 있다. 예를 들어 Assembly 예제는 운영체제와 CPU 아키텍처에 따라 완전히 달라질 수 있으며, Verilog와 VHDL은 일반적인 콘솔 프로그램이 아니라 하드웨어 기술 언어의 시뮬레이션 예제로 보아야 한다.
 
== 같이 보기 ==
* [[C]]
* [[프로그래밍 언어]]
* [[컴파일러]]
* [[인터프리터]]
* [[표준 출력]]
* [[도움말:위키 문법/SyntaxHighlight]]
 
== 각주 ==
<references />
 
== 분기 ==
{{분기|도움말:위키 문법/SyntaxHighlight|85572||가온 위키}}
{{분기|도움말:위키 문법/SyntaxHighlight|85572||가온 위키}}
[[분류:프로그래밍]]
[[분류:프로그래밍 언어]]
[[분류:컴퓨터 과학]]
[[분류:예제 코드]]

2026년 5월 29일 (금) 12:33 기준 최신판

#include <stdio.h>int main(void)
{
printf("Hello, world!\n");

return 0;

}
#include <stdio.h>int main(void)
{
printf("안녕 세상아!\n");

return 0;

}

Hello, world!는 프로그래밍을 처음 배울 때 가장 널리 사용되는 예제 문장이다. 일반적으로 화면, 콘솔, 터미널, 로그 등에 짧은 문자열을 출력하는 프로그램을 작성함으로써 개발 환경이 정상적으로 설치되었는지, 소스 코드가 올바르게 실행되는지, 기본 입출력 문법을 이해했는지 확인하는 데 사용된다.

많은 프로그래밍 입문서와 튜토리얼은 첫 예제로 Hello, world!를 사용한다. 이 관례는 브라이언 커니핸(Brian W. Kernighan)이 작성한 B 언어 튜토리얼의 예제와, 브라이언 커니핸과 데니스 리치(Dennis Ritchie)가 함께 쓴 《The C Programming Language》의 C 언어 예제를 통해 널리 알려졌다.[1][2]

개요[편집 / 원본 편집]

Hello, world! 프로그램은 보통 다음 목적을 가진다.

  • 개발 환경이 정상적으로 설치되었는지 확인한다.
  • 컴파일러, 인터프리터, 런타임, 셸, 브라우저 등의 실행 흐름을 확인한다.
  • 문자열 출력, 함수 호출, 프로그램 진입점 등 가장 기본적인 문법을 익힌다.
  • 새 언어의 코드 구조를 짧은 예제로 비교한다.

다만 언어마다 실행 방식은 다르다. 어떤 언어는 컴파일이 필요하고, 어떤 언어는 인터프리터로 바로 실행되며, 어떤 언어는 브라우저나 특정 런타임, 하드웨어 시뮬레이터가 필요하다.

역사[편집 / 원본 편집]

Hello, world!라는 문구는 C 언어의 대표적인 첫 예제로 널리 알려져 있다. 다만 그 기원은 C 언어 책 하나로만 설명하기보다는, 벨 연구소(Bell Laboratories)에서 작성된 초기 언어 튜토리얼 문맥까지 함께 보는 편이 정확하다.

브라이언 커니핸은 B 언어 튜토리얼에서 외부 변수와 문자 출력을 설명하기 위해 비슷한 형태의 예제를 사용하였다. 이후 《The C Programming Language》에서 C 언어의 첫 예제로 간단한 문자열 출력 프로그램이 제시되면서, Hello, world!는 새 프로그래밍 언어를 배울 때 처음 작성하는 상징적인 예제가 되었다.

표현 차이[편집 / 원본 편집]

언어마다 Hello, world!를 출력하는 방식은 다음과 같은 차이를 보인다.

각 언어로 표현한 Hello, world![편집 / 원본 편집]

Ada[편집 / 원본 편집]

with Ada.Text_IO;
use Ada.Text_IO;

procedure Hello_World is
begin
Put_Line("Hello, world!");
end Hello_World;

ActionScript[편집 / 원본 편집]

package {
import flash.display.Sprite;

public class HelloWorld extends Sprite {
    public function HelloWorld() {
        trace("Hello, world!");
    }
}

}

Agda[편집 / 원본 편집]

open import IO

main = run (putStr "Hello, world!")

Assembly[편집 / 원본 편집]

아래 예제는 32비트 리눅스 x86 환경에서 시스템 호출을 사용해 문자열을 출력하는 예이다.

section .data
    hello:    db 'Hello, world!', 0Ah
    helloLen: equ $ - hellosection .text
global _start

_start:
mov     edx, helloLen
mov     ecx, hello
mov     ebx, 1
mov     eax, 4
int     80h

mov     eax, 1
xor     ebx, ebx
int     80h

=== AutoIt ===

MsgBox(0, "Message", "Hello, world!")

Bash[편집 / 원본 편집]

#!/bin/bash

echo "Hello, world!"
printf "Hello, world!\n"

Batch[편집 / 원본 편집]

@echo off
echo Hello, world!

B[편집 / 원본 편집]

초기 B 언어 튜토리얼에서는 다음과 같이 여러 외부 변수에 문자열 조각을 나누어 저장한 뒤 출력하는 예제가 사용되었다.

main()
{
    extrn a, b, c;putchar(a);
putchar(b);
putchar(c);
putchar('!*n');

}

a 'hell';
b 'o, w';
c 'orld';

Brainfuck[편집 / 원본 편집]

++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++++++++++++++.<hr>.<<+++++++++++++++.>.+++.<hr>.<hr>.>+.

C[편집 / 원본 편집]

#include <stdio.h>

int main(void)
{
printf("Hello, world!\n");

return 0;

}

C++[편집 / 원본 편집]

#include <iostream>

int main()
{
std::cout << "Hello, world!" << std::endl;

return 0;

}

C#[편집 / 원본 편집]

using System;

namespace HelloWorld
{
internal class Program
{
private static void Main(string[] args)
{
Console.WriteLine("Hello, world!");
}
}
}

Common Lisp[편집 / 원본 편집]

(format t "Hello, world!~%")

CSS[편집 / 원본 편집]

CSS는 일반적인 프로그래밍 언어라기보다는 스타일시트 언어이다. 아래 예제는 문서의 body 앞에 문자열을 표시한다.

body::before {
    content: "Hello, world!";
}

D[편집 / 원본 편집]

import std.stdio;

void main()
{
writeln("Hello, world!");
}

Dart[편집 / 원본 편집]

void main() {
print("Hello, world!");
}

Elixir[편집 / 원본 편집]

IO.puts("Hello, world!")

Erlang[편집 / 원본 편집]

-module(hello).
-export([main/0]).

main() ->
io:format("Hello, world!~n").

F#[편집 / 원본 편집]

printfn "Hello, world!"

Fortran[편집 / 원본 편집]

program HelloWorld
print *, "Hello, world!"
end program HelloWorld

Go[편집 / 원본 편집]

package main

import "fmt"

func main() {
fmt.Println("Hello, world!")
}

Groovy[편집 / 원본 편집]

println "Hello, world!"

Haskell[편집 / 원본 편집]

main :: IO ()
main = putStrLn "Hello, world!"

HTML[편집 / 원본 편집]

HTML은 프로그래밍 언어라기보다는 마크업 언어이다. 아래 예제는 웹 문서에 문자열을 표시한다.

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <title>Hello, world!</title>
</head>
<body>
    <p>Hello, world!</p>
</body>
</html>

=== Java ===

public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}

JavaScript[편집 / 원본 편집]

console.log("Hello, world!");

document.body.textContent = "Hello, world!";

Kotlin[편집 / 원본 편집]

fun main() {
println("Hello, world!")
}

Lua[편집 / 원본 편집]

print("Hello, world!")

Objective-C[편집 / 원본 편집]

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{
@autoreleasepool {
NSLog(@"Hello, world!");
}

return 0;

}

OCaml[편집 / 원본 편집]

print_endline "Hello, world!"

Pascal[편집 / 원본 편집]

program HelloWorld;

begin
writeln('Hello, world!');
end.

Perl[편집 / 원본 편집]

use strict;
use warnings;

print "Hello, world!\n";

PHP[편집 / 원본 편집]

<?php

echo "Hello, world!\n";

PowerShell[편집 / 원본 편집]

Write-Output "Hello, world!"

Python[편집 / 원본 편집]

print("Hello, world!")

R[편집 / 원본 편집]

cat("Hello, world!\n")

Raku[편집 / 원본 편집]

say "Hello, world!";

Ruby[편집 / 원본 편집]

puts "Hello, world!"
print "Hello, world!\n"

Rust[편집 / 원본 편집]

fn main() {
    println!("Hello, world!");
}

Scala[편집 / 원본 편집]

object HelloWorld {
    def main(args: Array[String]): Unit = {
        println("Hello, world!")
    }
}

Scheme[편집 / 원본 편집]

(display "Hello, world!")
(newline)

SQL[편집 / 원본 편집]

SQL은 일반적인 프로그래밍 언어라기보다는 데이터베이스 질의 언어이다. 아래 예제는 문자열 값을 하나의 결과 행으로 조회한다.

SELECT 'Hello, world!' AS greeting;

Swift[편집 / 원본 편집]

print("Hello, world!")

TypeScript[편집 / 원본 편집]

const message: string = "Hello, world!";

console.log(message);

Verilog[편집 / 원본 편집]

module main;
  initial begin
    $display("Hello, world!");
    $finish;
  end
endmodule

VHDL[편집 / 원본 편집]

use std.textio.all;

entity main is
end main;

architecture behaviour of main is
begin
    process
        variable hello : line;
    begin
        write(hello, String'("Hello, world!"));
        writeline(output, hello);
        wait;
    end process;
end behaviour;

Visual Basic .NET[편집 / 원본 편집]

Module HelloWorld
    Sub Main()
        Console.WriteLine("Hello, world!")
    End Sub
End Module

Zig[편집 / 원본 편집]

const std = @import("std");

pub fn main() !void {
    const stdout = std.io.getStdOut().writer();

    try stdout.print("Hello, world!\n", .{});
}

난해한 프로그래밍 언어의 예시[편집 / 원본 편집]

일부 난해한 프로그래밍 언어는 실용성보다는 표현 방식, 장난성, 언어 설계 실험 자체에 의미가 있다. 따라서 아래 예제들은 일반적인 입문용 예제라기보다는 Hello, world!가 여러 형태로 변형될 수 있음을 보여 주는 사례에 가깝다.

몰랭(Mollang)[편집 / 원본 편집]

몰????.??????????? 모올????.????.?? 모오올몰모올
아모오올!!!!루 모오올모올 아모오올!!!!!!!루 아모오올루 아모오올루
아모오올???루 아몰루 아모올루 몰모올 아몰???????????????????????????????????????????루 아모오올???루
아몰모올??????루 아모오올루 아모오올!!!!!!!!루 아모올?루

엄랭[편집 / 원본 편집]

어떻게

엄
어엄
어어엄
어어어엄
어어어어엄
어어어어어엄
어어어어어어엄
어어어어어어어엄

엄어..........
동탄어?준..... .....

어엄어어.......

어어엄어어어..........

어어어엄어어어어...

어어어어엄어어어어어.

엄어,
준.............

어엄어어..
식어어ㅋ

어어엄어어어.
식어어어ㅋ
어어엄어어어.......
식어어어ㅋ
식어어어ㅋ
어어엄어어어...
식어어어ㅋ

어어어엄어어어어..............
식어어어어ㅋ
어어어엄어어어어<sub></sub><sub></sub><sub></sub>
식어어어어ㅋ

어엄어어...............
식어어ㅋ

식어어어ㅋ
어어엄어어어...
식어어어ㅋ
어어엄어어어<sub></sub><sub>
식어어어ㅋ
어엄어어어</sub><sub></sub>,,
식어어어ㅋ

어어어엄어어어어.
식어어어어ㅋ

화이팅!.,

이 사람이름이냐ㅋㅋ

활용[편집 / 원본 편집]

Hello, world!는 단순한 예제이지만 다음과 같은 상황에서 자주 사용된다.

  • 새 프로그래밍 언어를 처음 배울 때
  • 컴파일러 또는 인터프리터 설치를 확인할 때
  • 개발 환경, 빌드 도구, 패키지 관리자 설정을 검증할 때
  • 웹 서버, 런타임, 컨테이너, 배포 환경의 기본 동작을 확인할 때
  • 임베디드 장치나 하드웨어 기술 언어에서 출력 또는 시뮬레이션 동작을 확인할 때

주의점[편집 / 원본 편집]

Hello, world! 예제는 언어의 전체 특징을 보여 주지는 않는다. 예를 들어 메모리 관리, 오류 처리, 모듈 시스템, 비동기 처리, 객체 지향, 함수형 프로그래밍, 타입 시스템 같은 핵심 개념은 이 예제만으로 알기 어렵다.

또한 일부 예제는 실행 환경에 따라 수정이 필요할 수 있다. 예를 들어 Assembly 예제는 운영체제와 CPU 아키텍처에 따라 완전히 달라질 수 있으며, Verilog와 VHDL은 일반적인 콘솔 프로그램이 아니라 하드웨어 기술 언어의 시뮬레이션 예제로 보아야 한다.

같이 보기[편집 / 원본 편집]

각주[편집 / 원본 편집]

  1. B. W. Kernighan, A Tutorial Introduction to the Language B, Bell Laboratories.
  2. Brian W. Kernighan, Dennis M. Ritchie, The C Programming Language.

분기[편집 / 원본 편집]

이 문서는 가온 위키도움말:위키 문법/SyntaxHighlight 문서 85572판에서 분기하였습니다.

최근 바뀜

더 보기