Basic C Programs : C Hello World Program

See first basic C program, don’t worry about terms used in the program, you will understand all them latter in details:

When you will run above C program, you will get below output:

Output

Hello World!!!

Important

In above program, all word (like include, main, printf etc.) have their special meanings except “ Hello world” we will understand all those words meanings in upcoming chapters.

Running C Program

There are three steps involve to run a C program:

  • Type program
  • Compile program
  • Run program

Typing program

Open text editor and type below code and save file anywhere in your computer with .c extension for example myprogram1.c

Compile Program

To compile program fallow the below steps

  • Open command prompt or terminal
  • Locate folder (folder where you have saved your program) directory in command prompt or in terminal
  • Now, type gcc file_name.c and press enter. It will start compilation of your program and if there is no error in your program then it will generate a new .exe file at same location.

Note: If you are getting any syntax error, after removing error again fallow above steps and try to compile the program.

Run Program

After successful compilation to run the program we have to locate same folder directory in CMD or terminal and then type gcc new_generated_file_name.exe and press enter, now you will get output of your program.

Extra Information

There are some good text editors who have direct compile and run button, if you don’t want to use command prompt or terminal then you can use those text editor. VS Code is a good text editor who provides such facility.

Terms used in program

#include

The line start with # symbol in C program are processed by processor. The processor generally takes our program and produces other program which is also the output.

stdio.h

In C program .h file is used to import some other externa libraries/functions which are required to support our program. For example we are using printf() function which is defined in stdio.h library. It is called as header file.

main()

The main() function is used to inform processor where the program starts. Every C program must have exactly one main() function. If there are more than one main() function in a program then compiler will become confused in deciding that which main() function is for starting point of program, and it will give an error. So always use exactly one main() function.

{}

The { is used to define starting of scope of a function and } is used to define end of a function’s scope. Within these two {} bracket we can type all code of the function.

printf()

It is a special function used to print anything as output. Suppose if we want to print "hello world" then we have to type like printf(“hello world”), always type content within “ ” in printf() function. Never forget to type (;) at the end of printf() function.

return 0

Since we have define main() function return type as int, then the function main() will expect a return value of int type, for that we are using return 0; it can return other than 0

Symbol ;

The symbol ; is used to terminate a line in program.

C Language is Case Sensitive

C is case sensitive between uppercase and lowercase letter. For example printf is different from PRINTF. Always remember that, in c programming everything is written in lowercase however we can use uppercase letter to represent variable name or we can use in output string.

The main Function

The main function in c programming is very important because it defines the start point of c program and every c program can have only one main function. In c programing main function can be defined in various formats, possible formats for main functions are listed below.

  • main()
  • int main()
  • void main()
  • main(void)
  • int main(void)
  • void main(void)

Note: From next chapter you will start to know terms used in C programming in details and also you learn how to use them in efficient way to write a good c program.

Email Us: advertise@gdatamart.com

Donate Us: Support to GDATAMART

© 2023 GDATAMART.COM (All Rights Reserved)