{"id":2145,"date":"2024-05-10T07:12:25","date_gmt":"2024-05-10T07:12:25","guid":{"rendered":"https:\/\/www.skillvertex.com\/blog\/?p=2145"},"modified":"2024-05-10T07:12:25","modified_gmt":"2024-05-10T07:12:25","slug":"c-hello-world-program","status":"publish","type":"post","link":"https:\/\/www.skillvertex.com\/blog\/c-hello-world-program\/","title":{"rendered":"C Hello World Program"},"content":{"rendered":"\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\" id=\"rank-math-toc\"><p>Table of Contents<\/p><nav><ul><li ><a href=\"#c-hello-world-program\">C Hello World Program<\/a><\/li><li ><a href=\"#c-program-to-print-hello-world\">C Program to Print \u201cHello World\u201d<\/a><\/li><li ><a href=\"#compiling-the-first-c-program\">Compiling the First C Program<\/a><\/li><li ><a href=\"#explanation-of-the-code\">Explanation of the Code<\/a><\/li><li ><a href=\"#faq-c-hello-world-program\">FAQ- C Hello World Program<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"c-hello-world-program\">C Hello World Program<\/h2>\n\n\n\n<p>The C programming language is known for its simplicity and power, and the &#8216;Hello World&#8217; program is the quintessential first step for anyone embarking on their journey into this versatile language. In this program, you&#8217;ll take your first steps into the world of C programming by learning how to display the classic &#8216;Hello World&#8217; message on the screen. It&#8217;s a fundamental starting point that introduces you to the essential concepts of C, setting the stage for your exploration of this language&#8217;s incredible capabilities.<\/p>\n\n\n\n<p>The &#8220;Hello World&#8221; program is the first thing you learn when starting to program in a new language. It&#8217;s a basic program where you make the computer show the words &#8220;Hello World&#8221; on the screen.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"c-program-to-print-hello-world\">C Program to Print \u201cHello World\u201d<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Simple C program to display \"Hello World\"\n \n\/\/ Header file for input output functions\n#include &lt;stdio.h&gt;\n \n\/\/ main function -\n\/\/ where the execution of program begins\nint main()\n{\n \n    \/\/ prints hello world\n    printf(\"Hello World\");\n \n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Hello World<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"compiling-the-first-c-program\">Compiling the First C Program<\/h2>\n\n\n\n<p>Before  Writing the first program, the user needs to set up a C program compiler, which works in compiling and executing the \u201cHello World\u201d program. Here we have used a Windows-based GCC compiler to compile and run the program<\/p>\n\n\n\n<p>Step 1 involves writing the &#8220;Hello World&#8221; program in a text editor and saving it with a <code>.c<\/code> file extension. Here&#8217;s the &#8220;Hello World&#8221; program written in C and saved as <code>HelloWorld.c<\/code><\/p>\n\n\n\n<p>Step 2 involves opening the Command Prompt (CMD) or Command Prompt window and navigating to the directory where the <code>HelloWorld.c<\/code> file is located, which is <code>C:\\Users\\Chin\\Sample<\/code> in this case<\/p>\n\n\n\n<p><strong>Step 3:<\/strong>&nbsp;We have to compile  the code in order to  execute the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gcc HelloWorld.c<\/code><\/pre>\n\n\n\n<p>Hence, this would enable us to create a C-executable file with a random name given by the compiler itself. We got the executable filename as&nbsp;a.<\/p>\n\n\n\n<p>To give a user-oriented name, run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gcc -o helloworld HelloWorld.c\/pre&gt;\n<\/code><\/pre>\n\n\n\n<p>Therefore, this can create a C-executable file by the name HelloWorld.<\/p>\n\n\n\n<p><strong>Step 4:<\/strong>&nbsp;To run the executable file and get the required result, run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>helloworld\n\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"explanation-of-the-code\">Explanation of the Code<\/h2>\n\n\n\n<p>Line 1:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Simple C program to display \u201cHello World\u201d\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Why We Use Comments<\/strong>: Comments are like little notes we write inside our program to help ourselves and other programmers understand what&#8217;s going on. They don&#8217;t tell the computer what to do; they&#8217;re just there for us to read.<\/li>\n\n\n\n<li><strong>What Comments Look Like in C<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Single-line comments start with <code>\/\/<\/code> and go until the end of the line. They&#8217;re good for short comments on one line.<\/li>\n\n\n\n<li>Multi-line comments are surrounded by <code>\/*<\/code> and <code>*\/<\/code>. They let us write longer comments that can span across multiple lines.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p><strong>Line 3:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include \n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>What Are Directives<\/strong>: In C, lines that start with a <code>#<\/code> sign are called directives. These lines are special instructions that are handled by a program called the preprocessor before the actual compilation by the compiler.<\/li>\n\n\n\n<li><strong>The #include Directive<\/strong>: One common directive is <code>#include<\/code>. When you see <code>#include<\/code> in your code, it&#8217;s like telling the preprocessor to grab another piece of code and put it here. For example, <code>#include &lt;stdio.h&gt;<\/code> tells the preprocessor to include a file called <code>stdio.h<\/code>, which contains information about standard input and output functions.<\/li>\n<\/ol>\n\n\n\n<p><strong>Line 6:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int main()\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>The <code>main<\/code> Function<\/strong>: In C, we use a line like this to declare a function called <code>main<\/code> that gives back a number (integer) when it&#8217;s done. A function is like a group of instructions that does a specific job.<\/li>\n\n\n\n<li><strong>Starting Point<\/strong>: Every C program starts running from the <code>main<\/code> function, no matter where it is in the program. So, every C program must have a <code>main<\/code> function, and this is where the program begins.<\/li>\n\n\n\n<li><strong>Curly Braces { }<\/strong>: These curly braces <code>{<\/code> and <code>}<\/code> mark the start and end of the <code>main<\/code> function. Everything inside these braces is the set of instructions that the <code>main<\/code> function will perform. We call this part between the braces a &#8220;block.&#8221;<\/li>\n<\/ol>\n\n\n\n<p><strong>Line 10:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>printf(\"Hello World\");\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Displaying &#8220;Hello World&#8221;<\/strong>: This line tells the computer to show the words &#8220;Hello World&#8221; on the screen. In C, this is called a &#8220;statement.&#8221; Every statement is like a little instruction for the computer.<\/li>\n\n\n\n<li><strong>Semi-colon<\/strong>: At the end of each statement, we put a semi-colon <code>;<\/code>. It&#8217;s like telling the computer, &#8220;Hey, this is the end of what I want you to do for this instruction.&#8221;<\/li>\n\n\n\n<li><strong>The <code>printf<\/code> Function<\/strong>: We use <code>printf<\/code> to print things on the screen. When we put something inside double quotes (<code>\" \"<\/code>), like &#8220;Hello World,&#8221; that&#8217;s what will be shown on the screen.<\/li>\n<\/ol>\n\n\n\n<p><strong>Line 12:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>return 0;\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>The <code>return<\/code> Statement<\/strong>: This line is also a command. It&#8217;s like telling the computer, &#8220;Okay, I&#8217;m done with my job, and here&#8217;s the result.&#8221; In C, we use <code>return<\/code> in functions to give back a value and indicate that the function is finished.<\/li>\n\n\n\n<li><strong>Indentation<\/strong>: You&#8217;ll notice that the <code>printf<\/code> and <code>return<\/code> lines are slightly pushed to the right (indented). We do this to make the code easier to read. In simple programs like &#8220;Hello World,&#8221; it might not seem important, but as programs get more complex, indentation helps us understand the structure and avoid mistakes<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"faq-c-hello-world-program\">FAQ- C Hello World Program<\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1695731147495\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q1. What is Hello World program in C?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. This line makes the computer display &#8220;Hello World&#8221; on the screen. It&#8217;s a statement in C, and we use a semicolon &#8216;;&#8217; to signal the end of the statement.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1695731154442\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q2. How to create Hello C?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. <strong>C Program:<\/strong><br \/>#include &lt;stdio. h><br \/>int main() {<br \/>printf(&#8220;Hello, world!\\ n&#8221;);<br \/>return 0;<br \/>}<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1695731160895\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q3. Why is Hello World used?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. A &#8220;Hello, world!&#8221; program is a common starting point for beginners learning a programming language. It&#8217;s also a quick way to test if a programming environment is set up correctly and the user knows how to use it.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>C Hello World Program The C programming language is known for its simplicity and power, and the &#8216;Hello World&#8217; program is the quintessential first step for anyone embarking on their journey into this versatile language. In this program, you&#8217;ll take your first steps into the world of C programming by learning how to display the &#8230; <a title=\"C Hello World Program\" class=\"read-more\" href=\"https:\/\/www.skillvertex.com\/blog\/c-hello-world-program\/\" aria-label=\"More on C Hello World Program\">Read more<\/a><\/p>\n","protected":false},"author":4,"featured_media":5320,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[378],"class_list":["post-2145","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-programming","tag-c-hello-world-program","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"_links":{"self":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/2145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/comments?post=2145"}],"version-history":[{"count":13,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/2145\/revisions"}],"predecessor-version":[{"id":10631,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/2145\/revisions\/10631"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media\/5320"}],"wp:attachment":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media?parent=2145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/categories?post=2145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/tags?post=2145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}