Hello world C | First Program example with printf

  • by

You have very curious about how to Make the first “Hello world C” program. It’s very easy to print a sentence in the console or display. If you any prior experience in programming in another programming language then it’s very easy. If you are just starting your programming career today then this tutorial will help you a lot. Let’s start a tutorial on How to do the First Hello World Program in C Language.

Hello world C First Program example with printf

Don’t be in Hurry 

As this is your first program so we suggest don’t try too fast because it’s not the same write first program in Java and Python.

Follow this step in the first program in c.

  1. Write a program ( we assume you already an install IDE for C)
  2. Compile – After Writing “Hello world program in c”, You have to Compile program.
  3. Run – Last step you have to Run the program, the output will show in console display.

Note – if you are using an IDE for the program then you can use a “Compile & Run“.

Hello world c example

Now coming to Our first Hello world c program. you need to include a <studo.h>, it contains standard input/output functions like printf. Without including this file we can use a printf function and not able to read and write input from the console display.

Look at below example and follow the steps to run program.

#include<stdio.h>
 
int main(){  
printf("Hello World C Language is here!");  
return 0; 
}

Output: Hello World C Language is here!

How a Hello World program in C works?

Here is how simple C program work and its important terms.

  • include<studo.h> – Tell to compile include this file for (standard input and output) file in the program.
  • main() function – The program will start from the main function.
  • printf() function – It will send the standard output to the console. You can see the output “Hello World C …etc”.
  • return 0 – Last statement in the program, will end up the program.

Note: if you are using a printf() without including a studo.h then program will now compile and show error.

error: [Error] ‘printf’ was not declared in this scope

Question: How to “print hello world” in c without using printf?

Answer: Is it possible to print a message in console or display without using a printf function in c?

Yes possible with different many ways for an example using put, while loop etc. See below example print “print hello world” in c without using printf program.

#include<stdio.h>
int main (void)
{
    puts("Hello, Without printf!");
    return 0;
}

With While loop

#include <stdio.h>
int main(void){
  char *s="hello world\n";
  while (*s) putchar(*s++);
}

Question: Is possible for a C Program to print hello without a semicolon “;”?

Answer: Yes you can print a “Hello” or other any sentence in c without using a semicolon. Some ways are using if, switch and loop etc.

See one example for it.

#include<stdio.h>  
 int main()    
{    
 	if(printf("hello world")){}    
	return 0;  
}

Sidenote: As you see the first Hello world program in c with different approaches. There is always recommend the use printf() function and semicolon for print statement and messages in console or display. Using another way like if, while loop, not required. Its make your app is critical and long.

Note: This example (Project) is developed in Dev-C++ and Version 5.11

Download link for IDE – Dev-C++

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.