How To Write Hello World Program In C++ Programming Language

Image
  How To Write a Hello World Program In C++ Programming Language In this post we will look at how a C++ program works. We will try make the example as simple as possible for the beginners so they can easily understand the basics of C++. We will write a simple C++ hello world program in C++ programming language which is considered as the very first program in almost every programming language. A Brief Introduction to the C++ Programming Language C++ is an object oriented programming language and it is an extension to C programming language. C++ is a general purpose programming language and it is also a case-sensitive language. C++ is very powerful programming language it has features of both low level and high level programming languages, and that is why it is called mid level programming language. Hello World program in C++ programming language Above is an example of a simple Hello World program in C++ programming language. Now let us look at the code, and I will take you...

How to use functions in C programming Language

 Functions in C Programming Language






In programming languages, there is a concept of functions that we use to implement some functionality in our code. Functions help us reuse the code and enhance its performance, as they are written once and tested again and again.

In C  programming we can use functions to break the code into smaller pieces that are easily maintainable. A function is a piece of code that is enclosed in curly brackets, and a function only runs and executes when it is called within a main program in C programming language.

We can also pass data from our main program or function to any user-defined function. As we already discussed, the main advantage or benefit of functions is reusability. In functions, we can define the code once, and after that, we can use the function code many times, which enhances the reusability of the code.

We can also refer to functions as procedures or sub-routines in some programming languages. Basically when we run a C program the execution of the program starts from a function that is declared as void main(), compilers in programming languages look for this main() function and the execution of the program from this main function. 

In C programming we can say that different functions are combined to make a single program.


Syntax of declaring and defining a function in C programming:



As in the above code image the first line in which we write void Hello(); is called function declaration. In the other part of the code where we mentioned void Hello() again with opening and closing curly brackets {} is called defining a function or function definition.

After declaring and defining a function the next step is to call a specific function within a main program or main() function.


Example of a simple user-defined function that prints Hello World C Function!




Explanation of the function coding example:

This is a simple piece of code in which we have declared and defined a function named Hello(). This function simply prints a message "Hello World C Function!"

Now there are basically three steps taken, which are considered good practice, the first step is to declare a function, and after that define a function in which the code is written inside the function body.

The last step is to call a function inside the main program or main() function.

Like in the above code we already discussed about function declaration and definition previously. Now we are going to look at function calling or calling a function within main() function.

Inside the void main() function we call the function like this Hello(); this is a simple way to call a function within the main program by simply writing the function name with opening and closing round brackets and ending it with a semicolon (;) symbol.

And when we execute the program and call the function it simply prints the message "Hello World C Function!" 

Congratulations we have successfully implemented the function in our C Program.









Comments

Popular posts from this blog

How if else-if else ladder statement works in C program.

How to add two numbers in C programming language