C hello world program (JNNC Technologies)



C hello world program: C language program to print "hello world," printf library function is used to display text on the screen, '\n' places the cursor at the beginning of next line, "stdio.h" header file contains the declaration of printf function. To learn a programming language, you must start writing programs in it, and this could be your first C program.

Hello world C program



#include <stdio.h>
 
int main()
{
  printf("Hello world\n");
  return 0;
}
Purpose of this program is to get familiar with the syntax of C programming language. In this program we have printed a particular set of words, to print whatever you want to, see C program to print a string.
Output of program:
Hello world C program output
Download Hello world C program.

C hello world progam using character variables

#include <stdio.h>
 
int main()
{
  char a = 'H', b = 'e', c = 'l', d = 'o';
  char e = 'w', f = 'r', g = 'd';
 
  printf("%c%c%c%c%c %c%c%c%c%c", a, b, c, c, d, e, d, f, c, g);
 
  return 0;
}
As you can see we have used seven character variables in the program and '%c' is used to display a character variable, it is just another method. See easy and efficient ways to do the same in the following programs.

Hello world program in C language

We may store "hello world" in a string (A character array) and then print it.
#include <stdio.h>
 
int main()
{
  char s[] = {'H','e','l','l','o',' ','w','o','r','l','d','\0'};
 
  printf("%s\n", s);
 
  return 0;
}
Output of program:
Hello world
If you didn't understand this program don't worry as you may not be familiar with the strings yet.

C program to print hello world a number of times

Using a for loop we can display it a number of times.
#include <stdio.h>
 
int main()
{
  int c, n;
 
  printf("How many times you want to display hello world?\n");
  scanf("%d", &n);
 
  for (c=1; c<=n; c++)
     printf("Hello world!\n");
 
  return 0;
}

Displaying hello world indefinitely

#include <stdio.h>
 
int main()
{
  while (1)
    printf("Hello World\n");
 
  return 0;
}
While loop will execute forever as while(1) is always true. To terminate the program press (Ctrl + C)/(Ctrl + Q).

0 Comments

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();