C programming for beginners

What is C Programming ?

What is c programming | C programming for beginners

C programming is a general purpose programming language and it is a machine independent language. C is in the fourth position In the Spectrum ranking. The founder of C is Dennis Richie and it was created from the “BCPL” and “B” programming languages. C initially became widely for the operating systems. C programming language is High Level Programming Language.

What is C Programming - How to write a simple C program | C programming for beginners
How to write a simple C program

In the above image displayed the format of a simple C program. In the black area displayed the output. You can use repl.it , Atom , Eclipse CDT or the terminal in the fedora operating system.

Start Coding in C Programming 

If you want to comment something, you can use  //  symbol to comment in a one line or you can starting from  /*  and ending it till  */  for the multiple lines. Comment are used to document the programs to more user-friendly. Let’s think a program is coding by a team. You have a part in this program. After you finishing your part, next teammate start his part. If you comment your part to understand what this is, it will very important to other members to continue their parts. So keep going with comments.

Other part is header files. What are header file? Header files means “stdio.h” , “math.h” like wise. It is very helpful to process your program. starting from the # means processing before compiling the program. stdio.h means standard input/output library function.

Another one is main function. Every c program has the main function. because the program begins executing at main function. We can use “void” as a return type. But in void there is no return type. We can use “int” to return integer value.

Let’s see a simple C program.

01) First number is 35 and the second number is 20. Get the total and the average. After that print the values.

Long Answer for the simple question 01
Long Answer for the simple question 01

This is answer and its very big. It has 25 lines. Let’s code with the limited lines. You can use one line to create same type variables. for an example there are two variables called “no1” and “no2″. those two are integer type variables. you can create in a one line. It is ” int no1, no2; “. So let’s code with the limited lines.

Short answer for the question 01
Short answer for the question 01

See!!! It has only 17 lines. Let’s see the output in this program.

Output for the Question 01
Output for the Question 01

But there is an error in this program. The output says the average is 27. But it is wrong right? Because 55/2 = 27.5 . That because we assign our variable avg as integer. we must assign this variable as float or double. Yeah.. right!! I never told you that. Isn’t it? Okay let’s learn about variables.

Let’s learn Variables in C Programming

Variable is a location in the memory where a value can be stored for the user. When declaring a variable most importantly it must have a name and a data type. What are the data types? Integer, float, double, char are the data types and the variable name can assign any name. The format for declaring a variable is, data type first and the name should be the after the data type. For examples int sum, float average like wise.

Variable declaring in c programming
Variable declaring in c programming

In C, we must careful when the variable is declaring. Because C is a case sensitive language. It means you must careful about the uppercase and the lowercase. For an example, Sum, sum and SUM are three different variable names.

Other rules are variable may not be a reserved word ( ex- return, if, for… ), does not begin with a digit and variable may not contain a blank spaces( ex-  wrong one is “int sum of the number” correct one is “int sumOfTheNumber” or “int Sum_of_the_number” )

Let’s see another example program.

01) Get the age from the user and print he/she is an adult or a child.( hint age >= 18, so he/she is an adult )

Answer for the Question 02
Answer for the Question 02

In here “scanf” is the method that we assign values, which we get from the user, to the relevant variable. If you want to get values from the user, use “scanf” keyword. In the below shows the output when you enter 10 for the age.

Output for the question 02
Output for the question 02

That’s all about the simple introduction of the C programming. Click here to learn advanced C programming. Don’t forget to leave a comment my failure things and share this to your friends. So see you in another post.

Thank you. This is the end of “C programming for beginners” article and make sure to leave a comment.

There are more articles from BuildITMasters. Follow the below link to refer.

Other articles from different categories.

Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Isurindi H.G.P.
Isurindi H.G.P.
3 years ago

good job bro . all the best osanda .

Would love your thoughts, please comment.x