大å¦ã®ãªãã¬ã¼ãã£ã³ã°ã·ã¹ãã è«ã¨ããè¬ç¾©ã§ãããã»ã¹ãè¤è£½ãããæ¶æ» ãããããã話ãèãã¦ããã¨ãã«ã大å¦ã«å ¥ã£ã¦ã¯ããã¦Cè¨èªãæ¸ããã¨ãã®ãã¨ãæãåºããã®ã§å°ãã ãæ¸ãã¾ãã
#include <stdio.h> int main (void) { printf("Hello, world.\n"); return 0; }
æ £ããã°ãªãã¨ããªãå ¥éã®æ¨æ¶ããã°ã©ã ã§ãã
printf
ã£ã¦ãã使ãã®ã«ãããã<stdio.h>ãincludeããªãã¨ãããªããã ãªã¨ãæããªãããããªãã¨ãªãé°å²æ°ãã¤ããã§ãé¡é¡ãé£åãæ¸ãã¦ãããã¡ã«ããµã¨çåã«æã£ããã¨ãããã¾ããã
æå¾ã®é¨åã«ã¤ãã¦ãããªã㧠0 ãªããè¿ãã¦ãããã ããããæ£å¸¸çµäºãªã®ã«0ã£ã¦false
ã£ã½ããã1ãè¿ããããããããããªãã§æ´æ°è¿ãã¦ãã®ã ããããè¿ãå¤voidã«ãã¦ãã¾ããããã¨ãããµãã«æããå®éã«
void main (void) { printf("Hello, world.\n"); return; }
ãæ¸ãã¦ã³ã³ãã¤ã«ãã¦ã¿ã¾ããã
ããã¨ãgccã¯
warning: return type of 'main' is not 'int'
ã¨æ³¨æãã¦ãã¾ããããã®æ¼ç¿ã®ã¨ãã«ã¯ããããããã®ãªã®ããã¨ããæ°æã¡ã§ãã¨ããããæ¸ã¾ããæ°ããã¾ãã
ãã®çåãæã£ã¦ããã©ããã®æ¬ã§
ã主役ã£ã½ãè¦ããmainé¢æ°ãå®éã¯èª°ãã«å¼ã³åºããã¦ãã身ã§ãå¼ã³åºãå´ã¯è¿ãå¤ã¨ãã¦æ´æ°ãæå¾ ãã¦ããããã®è¿ãå¤ã¯ exité¢æ°ã®å¼æ°ã«ãªã£ã¦ãããã
ã¨ãããã¨ãç¥ãã¾ãããç¶ã㦠exit ã調ã¹ãã¨ãå¼æ°ã«0ãåãåã£ãå ´åã¯æ£å¸¸çµäºã§ã1ãªã©ã®0以å¤ãåãåãã¨ç°å¸¸ãªçµäºã¨ãªãã¨ãããã¨ãåããã¾ããã
ããããvoidã«ããã注æãããããªãã¨ç´å¾ãã¾ããã
ããã°ã©ãã³ã°ã«éãã¾ãããããã®ãããªå°ããªçåãç¡è¦ããã«èª¿ã¹ã¦ã¿ããã¨ã¯æ¡å¤æ¥½ããä½æ¥ã ã£ãããã¾ããèªåãçåã«æã£ãé ã«åå¼·ãé²ããã¨ãããã¹ãã®ç« ç«ã¦ããç解ãããããã¨ãå¤ã
ããã¾ãã
趣å³ã®åå¼·ãªã©æéã«å¶éããªãå ´åã¯ç¹ã«ããããã§ãã