Recall, the software is like a factory, where a product is produced by processing the raw materials. Even though that is the big picture, the reality is that the factory itself consists of many pieces of machinery, and each of these machines takes some raw materials and processes them to produce a good. The same can be done in programming.

The whole program can be divided into functions. Each function will take an input and produce an output.

Why Functions?

This is a quiz program we made in the last article. You might have noticed that for each question and the…


Numbers and characters can be stored in an array. What if a word or a sentence is needed to be stored in a variable? One way to do this is using a character array. There is a more convenient way, to store them as strings.

What is a string?

A string is an array of characters that is terminated with a null terminator. The null terminator is a special character ‘\0’, which has the numerical value of 0. It is used to represent emptiness. So, in the case of a string, the null terminator denotes where the string ends. So, can’t we just use…


Variables are used to store values. Each variable is like a box. The box will contain a value. The box can be opened and a value can be stored in it. Then the value can be used whenever it is needed. Just open the box and take the value. It’s very useful

But imagine a scenario where the marks of five subjects should be stored. To do this, five variables can be created: subjectt1, subject2, subject3, subject4, and subject5, and the marks of each subject can be stored in it.

But what if there is a need to store the…


Suppose there arises a need to display a text a hundred times. One way that is very painful, is to write a hundred lines of code to display it a hundred times. Thanks to loops, there is no need to repeatedly write code to do such repetitive tasks.

while loop

The ‘while loop’ loops through the statements until the condition becomes false.

Syntax:

while(condition) {
statement(s);
}

Example:

Output

I am looping 1 times
I am looping 2 times
I am looping 3 times
I am looping 4 times
I am looping 5 times

The condition for the loop is written…


We talked about the ‘if and else’ statements for decision-making. In cases, where there are more conditions to be checked, it is better and more convenient to use the switch statements, for example, the operations on a calculator. In a calculator, we need to check whether the operation is addition, subtraction, multiplication, or division.

Calculator Program

Take a look at the calculator program

Output

Enter first number: 5
Enter the operator: +
Enter second number: 6
5.00 + 6.00 = 11.00

After taking the inputs, we made a switch statement.

switch(sign)

The lines to what to do according to the value…


We have seen the method to get inputs from the user. There might come a time where we need to instruct the computer to make decisions based on the input. For example, in a quiz program, we ask the user the answer and then we need to check whether the user had entered the correct answer. This process of instructing computers to make decisions is known as ‘decision making’ in programming.

if and else

‘if and else’ statements check whether a condition is true or false. …


Software is like a factory that takes raw materials and gives out a product. The Software takes an input and gives out an output. What every software basically does is taking data from the users or environment(input) and producing new data(output) which will benefit the user of the software. Till now, we have been programming without user interaction. Programming starts to get interesting when interacting with the user.

scanf()

To output values onto the screen we used the printf() function. To take an input from the user through the screen, we use the scanf() function. The usage is similar with a…


Relational operators are used to evaluate or test the relation between two expressions. There comes a time when we will need to connect two or more such evaluations or expressions and provide a compound output, like when we need to check whether a variable contains a number that is between 10 and 20. Logical operators are used in such cases where we have to combine the evaluation of the expressions.

&&

This is known as the “logical AND” operator. It is used to check whether the condition on both sides of the operator is true.

int a, b;
bool condition1, condition2…


In programming, very often there arises a need to evaluate expressions. We may need to check whether the values stored in two variables are equal or whether the value in one variable is greater than the value in the other variable or vice versa and so on. We use relational operators for such operations.

Boolean Data Type

There is one special data type known as boolean. This data type can only store either of the two values: true or false. To use boolean data type in C, we have to import a header file known as ‘stdbool.h’.


Like we said variables are like boxes that are used to store values. We also saw how can we display the stored values. But we may also need to perform operations on those stored values. Operators help us to do this. Specifically, arithmetic operators help us to perform arithmetic operations on values.

In an operation, we will have an expression, operator and operands.

a+b;

Here the whole statement is the expression, a and b are the operands and ‘+’ is the operator. …

Shafi Sahal

Developer, adventure lover and a truth seeker

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store