Skip to main content

C "Hello, World!" Program

C "Hello, World!" Program

A simple C program to display "Hello, World!" on the screen. Since, it's a very simple program, it is often used to illustrate the syntax of a programming language.
 
C program to print
To understand this example, you should have the knowledge of following C programming topics:

Program to Display "Hello, World!"

#include <stdio.h>
int main()
{
   // printf() displays the string inside quotation
   printf("Hello, World!");
   return 0;
}
Output
Hello, World!
How "Hello, World!" program works?
  • The #include <stdio.h> is a preprocessor command. This command tells compiler to include the contents of stdio.h (standard input and output) file in the program.
    The stdio.h file contains functions such as scanf() and print() to take input and display output respectively.
    If you use printf() function without writing #include <stdio.h>, the program will not be compiled.
  • The execution of a C program starts from the main() function.
  • The printf() is a library function to send formatted output to the screen. In this program, the printf() displays Hello, World! text on the screen.
  • The return 0; statement is the "Exit status" of the program. In simple terms, program ends with this statement.

Comments

Popular posts from this blog

C Program to Find all Roots of a Quadratic Equation

C Program to Find all Roots of a Quadratic Equation This program accepts coefficients of a quadratic equation from the user and displays the roots (both real and complex roots depending upon the discriminant ).   To understand this example, you should have the knowledge of following C programming topics: C Programming Operators C if...else Statement The standard form of a quadratic equation is: ax 2 + bx + c = 0, where a, b and c are real numbers and a ≠ 0 The term b 2 -4ac is known as the discriminant of a quadratic equation. The discriminant tells the nature of the roots. If discriminant is greater than 0, the roots are real and different. If discriminant is equal to 0, the roots are real and equal. If discriminant is less than 0, the roots are complex and different. Example: Program to Find Roots of a Quadratic Equation #include <stdio.h> #include <math.h> int main () ...

C Program to Check Whether a Number is Positive or Negative

C Program to Check Whether a Number is Positive or Negative In this example, you will learn to check whether a number (entered by the user) is negative or positive.    To understand this example, you should have the knowledge of following C programming topics: C Programming Operators C if...else Statement This program takes a number from the user and checks whether that number is either positive or negative or zero. Example #1: Check if a Number is Positive or Negative Using if...else #include <stdio.h> int main () { double number ; printf ( "Enter a number: " ); scanf ( "%lf" , & number ); if ( number <= 0.0 ) { if ( number == 0.0 ) printf ( "You entered 0." ); else printf ( "You entered a negative number." ); } else printf ( "You entered a positive num...

C Program to Print an Integer (Entered by the User)

C Program to Print an Integer (Entered by the User) In this program, integer entered by the user is stored in a variable. Then, that variable is displayed on the screen using printf() function.   To understand this example, you should have the knowledge of following C programming topics: C Programming Constants and Variables C Programming Data Types C Input Output (I/O) Program to Print an Integer #include <stdio.h> int main () { int number ; // printf() dislpays the formatted output printf ( "Enter an integer: " ); // scanf() reads the formatted input and stores them scanf ( "%d" , & number ); // printf() displays the formatted output printf ( "You entered: %d" , number ); return 0 ; } Output Enter a integer: 25 You entered: 25 In this program, an integer variable  number is declared. ...