{"id":24256,"date":"2020-10-14T10:35:10","date_gmt":"2020-10-14T17:35:10","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=24256"},"modified":"2022-08-05T12:44:34","modified_gmt":"2022-08-05T19:44:34","slug":"c-hello-world","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/c-hello-world\/","title":{"rendered":"C Hello World: Step-By-Step Guide"},"content":{"rendered":"\n<p>To get started with your very first program in C, you must first be sure a C compiler is installed on your machine. Our article on <a href=\"https:\/\/careerkarma.com\/blog\/c-compilers\/\">C Compilers and How to Set Them Up<\/a> will help you get started.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Hello World! in C<\/h2>\n\n\n\n<p>Getting your first program off the ground is simple once you have the correct tools installed. First, open your preferred code editor and start and save a new file called hello.c.&nbsp;<br><\/p>\n\n\n\n<p>The makeup of any file in C is going to be two things:&nbsp;&nbsp;<br><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Your preprocessing commands \u2013 indicated by a hash symbol plus the word include, you can list headers that are needed to operate your code here.&nbsp;<\/li><li>Main function \u2013 int main () {&lt;program goes here&gt;} is your program. As indicated by the type it expects to return an integer. If successful, it will return 0 and execute. If an error is thrown, it will return an exit status code and show the error in the compiler.<\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Preprocessor<\/h3>\n\n\n\n<p>Let\u2019s start with the preprocessor section:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>#include &lt;stdio.h&gt;<\/pre><\/div>\n\n\n\n<p>The <code>&lt;stdio.h&gt;<\/code> (standard input\/output) header is in the standard library packaged with your compiler. This header defines variables, rules, and various functions for performing input and output. We need the <code>&lt;stdio.h&gt;<\/code> header file to access the functions we need to print out \u201cHello, World\u201d to our terminal.&nbsp;<br><\/p>\n\n\n\n<p>The C preprocessor will take a look at the #include statement as well as any other definitions that begin with <code>#<\/code> on the first pass through the code before compilation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Main Function<\/h3>\n\n\n\n<p>All C files will have a <code>main()<\/code> function that expects to return an integer indicating if the function succeeded or not in executing. Here\u2019s our code to print out \u201cHello, World\u201d:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>int main(void)\n{\n   printf(\"Hello, world!\\n\");\n \n   return 0;\n}<\/pre><\/div>\n\n\n\n<p>The void statement in between the parentheses simply means the function is not expecting any arguments.&nbsp;<br><\/p>\n\n\n\n<p>The printf function comes from the <code>&lt;stdio.h&gt;<\/code> header where it is defined. It is the function that will display the message on the terminal.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p>How you compile your file depends on which compiler you are using. Follow the instructions for your compiler when it comes to compiling C code. Once compiled, you can then run it. That\u2019s all there is to it! Congrats \u2013 you have just written your first C program!&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"To get started with your very first program in C, you must first be sure a C compiler is installed on your machine. Our article on C Compilers and How to Set Them Up will help you get started. Hello World! in C Getting your first program off the ground is simple once you have&hellip;","protected":false},"author":77,"featured_media":17510,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[50470],"tags":[],"class_list":{"0":"post-24256","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-tech-guides"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Coding","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>C Hello World | Career Karma<\/title>\n<meta name=\"description\" content=\"Learn how to write the famous &quot;Hello, World!&quot; program in C in this article from Career Karma.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/c-hello-world\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C Hello World: Step-By-Step Guide\" \/>\n<meta property=\"og:description\" content=\"Learn how to write the famous &quot;Hello, World!&quot; program in C in this article from Career Karma.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/c-hello-world\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-10-14T17:35:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-05T19:44:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/05\/nasa-Q1p7bh3SHj8-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"666\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Christina Kopecky\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Christina Kopecky\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-hello-world\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-hello-world\\\/\"},\"author\":{\"name\":\"Christina Kopecky\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/ae0cdc4a5d198690d78482646894074e\"},\"headline\":\"C Hello World: Step-By-Step Guide\",\"datePublished\":\"2020-10-14T17:35:10+00:00\",\"dateModified\":\"2022-08-05T19:44:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-hello-world\\\/\"},\"wordCount\":378,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-hello-world\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/nasa-Q1p7bh3SHj8-unsplash.jpg\",\"articleSection\":[\"Tech Guides\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-hello-world\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-hello-world\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-hello-world\\\/\",\"name\":\"C Hello World | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-hello-world\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-hello-world\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/nasa-Q1p7bh3SHj8-unsplash.jpg\",\"datePublished\":\"2020-10-14T17:35:10+00:00\",\"dateModified\":\"2022-08-05T19:44:34+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/ae0cdc4a5d198690d78482646894074e\"},\"description\":\"Learn how to write the famous \\\"Hello, World!\\\" program in C in this article from Career Karma.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-hello-world\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-hello-world\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-hello-world\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/nasa-Q1p7bh3SHj8-unsplash.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/nasa-Q1p7bh3SHj8-unsplash.jpg\",\"width\":1000,\"height\":666,\"caption\":\"View of cities lit up on Earth captured from outer space\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-hello-world\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tech Guides\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/tech-guides\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"C Hello World: Step-By-Step Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/ae0cdc4a5d198690d78482646894074e\",\"name\":\"Christina Kopecky\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/image-3-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/image-3-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/image-3-150x150.jpg\",\"caption\":\"Christina Kopecky\"},\"description\":\"Christina is an experienced technical writer, covering topics as diverse as Java, SQL, Python, and web development. She earned her Master of Music in flute performance from the University of Kansas and a bachelor's degree in music with minors in French and mass communication from Southeast Missouri State. Prior to joining the Career Karma team in June 2020, Christina was a teaching assistant, team lead, and section lead at Lambda School, where she led student groups, performed code and project reviews, and debugged problems for students. Christina's technical content is featured frequently in publications like Codecademy, Repl.it, and Educative.\",\"sameAs\":[\"http:\\\/\\\/www.linkedin.com\\\/in\\\/cmvnk\"],\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/christina-kopecky\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"C Hello World | Career Karma","description":"Learn how to write the famous \"Hello, World!\" program in C in this article from Career Karma.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/c-hello-world\/","og_locale":"en_US","og_type":"article","og_title":"C Hello World: Step-By-Step Guide","og_description":"Learn how to write the famous \"Hello, World!\" program in C in this article from Career Karma.","og_url":"https:\/\/careerkarma.com\/blog\/c-hello-world\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-10-14T17:35:10+00:00","article_modified_time":"2022-08-05T19:44:34+00:00","og_image":[{"width":1000,"height":666,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/05\/nasa-Q1p7bh3SHj8-unsplash.jpg","type":"image\/jpeg"}],"author":"Christina Kopecky","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"Christina Kopecky","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/c-hello-world\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/c-hello-world\/"},"author":{"name":"Christina Kopecky","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e"},"headline":"C Hello World: Step-By-Step Guide","datePublished":"2020-10-14T17:35:10+00:00","dateModified":"2022-08-05T19:44:34+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/c-hello-world\/"},"wordCount":378,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/c-hello-world\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/05\/nasa-Q1p7bh3SHj8-unsplash.jpg","articleSection":["Tech Guides"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/c-hello-world\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/c-hello-world\/","url":"https:\/\/careerkarma.com\/blog\/c-hello-world\/","name":"C Hello World | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/c-hello-world\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/c-hello-world\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/05\/nasa-Q1p7bh3SHj8-unsplash.jpg","datePublished":"2020-10-14T17:35:10+00:00","dateModified":"2022-08-05T19:44:34+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e"},"description":"Learn how to write the famous \"Hello, World!\" program in C in this article from Career Karma.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/c-hello-world\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/c-hello-world\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/c-hello-world\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/05\/nasa-Q1p7bh3SHj8-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/05\/nasa-Q1p7bh3SHj8-unsplash.jpg","width":1000,"height":666,"caption":"View of cities lit up on Earth captured from outer space"},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/c-hello-world\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Tech Guides","item":"https:\/\/careerkarma.com\/blog\/tech-guides\/"},{"@type":"ListItem","position":3,"name":"C Hello World: Step-By-Step Guide"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e","name":"Christina Kopecky","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg","caption":"Christina Kopecky"},"description":"Christina is an experienced technical writer, covering topics as diverse as Java, SQL, Python, and web development. She earned her Master of Music in flute performance from the University of Kansas and a bachelor's degree in music with minors in French and mass communication from Southeast Missouri State. Prior to joining the Career Karma team in June 2020, Christina was a teaching assistant, team lead, and section lead at Lambda School, where she led student groups, performed code and project reviews, and debugged problems for students. Christina's technical content is featured frequently in publications like Codecademy, Repl.it, and Educative.","sameAs":["http:\/\/www.linkedin.com\/in\/cmvnk"],"url":"https:\/\/careerkarma.com\/blog\/author\/christina-kopecky\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/24256","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/77"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=24256"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/24256\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/17510"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=24256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=24256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=24256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}