AlphaCodingSkills

C - Syntax


Advertisements

Previous Page Next Page

Although the "Hello World!" program looks simple, it has all the fundamental concepts of C which is necessary to learn to proceed further. Lets break down "Hello World!" program to learn all these concepts.


//   Hello World! Example
#include <stdio.h>
 
int main ()
{
    printf("Hello, World!");
    return 0;
}

Output

Hello World!.

Line 1: This is a single line comment which starts with //. Generally, comments are added in programming code with the purpose of making the code easier to understand. It is ignored by compiler while running the code. Please visit comment page for more information.

Line 2: #include <stdio.h> is header file library. It allows program to perform input and output operations.

Line 3: Blank line has no effect. It is used to improve readability of the code.

Line 4: int main() - It declares of function main. A function is a block of code with a name. Please visit function page for more information.

Line 5 and 8: It consists of open curly bracket({) and close curly bracket (}). It is essential to keep all the code block of function main within curly bracket ({block of code}).

Line 6: printf("Hello, World!"); - printf() is standard character output device defined in <stdio.h> header file. It facilitates output from a program. Finally, ("Hello world!") is inserted into the printf() to get the output printed on the output device. Please note that, in C, every statement ends with semicolon (;).

Line 7: reurn 0; indicates ends of the main function.

line change ("\n"):

"\n" facilitates line change while performing output operation. "\n" tells the program to start a new line.


#include <stdio.h>

int main ()
{ 
    printf("Hello World!.\n")
    printf("Learning C is fun.")
    return 0;
}

Output

Hello World!.
Learning C is fun.

Previous Page Next Page