Writing and Understanding First C program – helloworld.c

Lets write a first C program which normally would be “helloworld” as,
 $ vim helloworld.c 
#include <stdio.h>

int main(void) {
        printf("Hello World \n");
        return 0;

Above we written simple and first C program, the standard structure of this C program normally is like below,

return_type main(void) {
       return success/failure;

Every C program contains minimum 3 sections as,
– Header
– main
– Body

Header – is where all the header .h files are included.
.h header files contains the declarations of the functions using in the program. Here, we used function “printf” which is declared in stdio.h and defined in c library libc.

main – is the entry point of every C program.
Every C program should contain one main for program execution.

The syntax adjacent to main is like below,
return data type” main (void)
– return data type for main is “int” and it is used to indicate success or failure of the program execution. In above program “return 0″ is related to return data type” which returns integer 0.

void inside main(void) indicates main doesn’t accept any parameters right now from command line, but there are ways to accept command
line arguments using argc & argv to main which we will see later.

body – body of a “C” program can be anything from a single printf to a complex program which is defined in side open&close
curly brace { … body … }
NOTE: Every statement inside body ends with “semicolon” “;”

printf(“Hello World \n”);
here, this function “printf” prints the string “Hello World” on to the terminal.
“\n” – indicates go to new line, so using within printf it prints strings and goes to new line, which makes displaying of output on terminal look good.

Related :   How to check if your machine is Little Endian or Big Endian using C program in Linux



Android Android Commands Android Java Applications Application Libraries Application Stack / User Interface Bash / Shell Scripts Commands and Packages Compilation Content Management System - CMS Core Kernel C Programs Development & Build Development Environment Setup Errors & Failures Flutter git Go Language Programs Hardware Platforms HTML JAVA Programs Kernel & Device Drivers Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Monetization / Google AdSense Multimedia - Audio, Video, Images NDK / Middleware / HAL OS Concepts PHP Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized User Interface Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply / Ask Question