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,

header
return_type main(void) {
body;
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 use 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.

SHUFFLED :   how to disable and / or enable ICMP ping from linux host

 

Android Android Commands Android Java Applications Application Libraries Bash / Shell Scripts Bluetooth driver Build Frameworks Commands and Packages Core Kernel C Programs Development Environment Setup Documents / Books Errors & Failures File Systems Framebuffer / Display Driver git Go Language Programs Hardware Platforms Home JAVA Programs Kernel & Device Drivers Kernel Booting and Porting Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL NDK / Middleware / HAL Network Driver OS Concepts PHP Procfs Filesystem Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Userspace Utilities Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply