Learn from various program written in programming language like- C, C++, Java, Python etc.
#1 Hello World! program in C Language | C Language Programming
Get link
Facebook
Twitter
Pinterest
Email
Other Apps
By
Aryansh Gupta
|
In this Tutorials, you will learn to print "Hello World!" on the screen in C programming. This is the first step towards learning any programming language and also one of the simplest programs you will learn. All one needs to do is display the message "Hello World" on the screen. To print any text on screen in C Language you need to use output functions such as printf(). This function displays the content that user write to console screen. Let’s look at the program and try to understand the terminologies involved in it.
C Program to Display "Hello World!"
// Simple C program to display "Hello World" // Header file for input output functions #include<stdio.h> // main function - // where the execution of program begins intmain() {
// printf() function displays the string // written inside quotation
printf("Hello World!"); return0; }
Output:
Hello World!
Explanation:
// Simple C program to display "Hello World" –This is a single comment line. A comment is used to display additional information about the program. A comment does not contain any programming logic as it is not read by the compiler. When a comment is encountered by a compiler, the compiler simply skips that line of code. Any line beginning with ‘//’ without quotes OR in between /*…*/ in C is a comment.
#include <stdio.h> –In C, all lines that start with pound (#) sign are called directives. These statements are processed by preprocessor program invoked by the compiler. The #include directive tells the compiler to include a file and #include <stdio.h> tells the compiler to include the header file for Standard Input Output file which contains declarations of all the standard input/output library functions. This is a standard input output file that contains the definitions of common input output functions such as scanf() and printf(). In the above program we are using printf() function.
int main() –Here main() is the function name and int is the return type of this function. A function is a group of statements that are designed to perform a specific task. Execution of every C program begins with the main() function, no matter where the function is located in the program. So, every C program must have a main() function and this is the function where the execution of program begins. The 0 return value of this function represents successful execution of program while the return value 1 represents the unsuccessful execution of program. This is the reason we have return 0; statement at the end of this main function.
{ and } –The opening braces '{' indicates the beginning of the main function and the closing braces '}' indicates the ending of the main function. Everything between these two comprises the body of the main function and are called the blocks.
printf("Hello World"); –This line tells the compiler to display the message "Hello World" on the screen. This line is called a statement in C. Every statement is meant to perform some task. A semi-colon ';' is used to end a statement. Semi-colon character at the end of the statement is used to indicate that the statement is ending there. The printf() function is used to print character stream of data on stdout console. Everything within " " is displayed to the output device.
return 0; –This is also a statement. This statement is used to return a value from a function and indicates the finishing of a function. This statement is basically used in functions to return the results of the operations performed by a function. As mentioned above, the value 0 means successful execution of main() function.
Comments
Post a Comment