LoginSignup
6
2

More than 5 years have passed since last update.

C言語のmainの型はvoidじゃなくてintに

Last updated at Posted at 2013-09-04

タイトルで言い切った。

久々にC言語で遊ぼうと思って下記コードをgccでコンパイル。

test.c
#include <stdio.h>

void main(void) {
    printf("Hello World!\n");
}

するとワーニングが・・・

warning: return type of 'main' is not 'int'

え、voidだめなの?昔々こう書けと教わった気が・・・

おとなしくintに書き直しました。

test.c(修正後)
#include <stdio.h>

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

    return 0;
}

ISOの規格(よくわかってない)ではintじゃないとダメとなっているっぽい。知らなかった。


Blog URL : http://www.utano.jp/ (Syntax Error.)

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2