Monday, February 9, 2015

Hello World program in C

C hello world program: c programming language code to print hello world. This program prints hello world, printf library function is used to display text on screen, '\n' places cursor on the beginning of next line, stdio.h header file contains declaration of printf function. The code will work on all operating systems may be its Linux, Mac or any other and compilers. To learn a programming language you must start writing programs in it and may be your first c code while learning programming.

Hello world in C language

//C hello world example
#include <stdio.h>
 
int main()
{
  printf("Hello world\n");
  return 0;
}
Purpose of Hello world program may be to say hello to people or the users of your software or application.
Output of program:
We may store "hello world" in a character array as a string constant and then print it.

#include <stdio.h>
 
int main()
{
  char string[] = "Hello World";
 
  printf("%s\n", string);
 
  return 0;
}

Don't worry if you didn't understand above code as you may not be familiar with arrays yet.

Printing hello world indefinitely

Using loop we can print "Hello World" a desired number of time or indefinitely.

#include <stdio.h>
#define TRUE 1
 
int main()
{
  while (TRUE)
  {
    printf("Hello World\n");
  }
 
  return 0;
}
While loop will execute forever until it is terminated, to terminate press (Ctrl + C) in windows operating system.

Related Posts:

  • Input & Output in C Language When we are saying Input that means to feed some data into program. This can be given in the form of file or from command line. C programming language provides a set of built-in functions to read given input and feed it to t… Read More
  • Flow Control Statements in C. C provides two sytles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching: Branching is so called because the progra… Read More
  • Hello World program in C C hello world program: c programming language code to print hello world. This program prints hello world, printf library function is used to display text on screen, '\n' places cursor on the beginning of next line, stdio.… Read More

3 comments: