Hello everyone, my name is Atharva and we are continuing with this C programming course.
In the last video we discussed C libraries.
We had seen that our string.h library that is there or time.h library that is there or similar to that there are other libraries, those provide different functions.
And we use these functions in our program and make them more productive and efficient.
This was about our inbuilt functions and inbuilt C libraries.
In this video we are going to discuss the errors.
We will be discussing, whenever in our program any problem comes, how that problem can be solved and debugged.
Debugging means to finding out the solution for that particular problem.
We call it debugging, that’s why in this video we will discuss the running and debugging topic in which we will be generating some error.
Then we will see why exactly that error is coming.
Then we will solve it and rectify it and then we will run it again and compile it successfully.
So, in this video we are going to see different types of errors which we can face while running the program and how to derive its solution, even that we will be seeing in this video.
So, here we are seeing various errors encountered in C programming, in which the 1st type that we would be seeing is called “Syntax Error”.
Which means that whenever we write our program, there is a problem in its Syntax.
At that time, we get a Syntax Error, which means in our Syntax there is some problem.
That is the reason we call it Syntax error.
Along with that if we go ahead, the second error is called the “Logical error”.
In that we have not made any problem in Syntax, everything we have written as per the C programming rules.
If it so happens that the program that we have made, its logic itself is a problem.
Which means in its logic there is something like that which we cannot do in our real life.
In that situation we face a logical error in our program.
And how that can be rectified, that we will be seeing in this video.
Along with that the third error that we are seeing, that is “Runtime Error”.
Now what is the runtime error? When we write such a program in which there is no problem in the Syntax, neither there is any problem in the logic.
And it easily gets compiled, our compiler doesn’t have any problem.
But when we run it and there is an interaction with the user or the user gives any input.
So, on the basis of the input or on the basis of the runtime any error gets generated or there is any problem in the program.
So, that error we call a runtime error, which our compiler doesn’t catch.
That’s why we will see all these errors in this video and we will know how the solutions are derived for these errors.
So, we will start with our syntax error.
Like we spoke about it, it is a Syntax mistake in our program.
So, we know in the program that we have to start a preprocessor command with #include.
In place of #include I have put $include.
There our Syntax is a problem.
There we can face the error.
In this way, if there is any problem in the Syntax.
In that situation our compiler gets to know that, here it has created that problem and there it generates the error.
That we call a Syntax error.
If we go ahead, we will talk about the logical error and if we talk about the logic, we are making a program, in which what we are doing is, let's suppose we take 2 variables,” a and b”.
What we did was we “divided a’s value in b and we stored it in some third variable”.
So, basically “a divided b is stored inside c and we got c printed”.
So, this was a very easy program.
Now how the problem comes in it, that we will see.
Let's suppose we have kept the “a’s value as 5 and b’s value we have kept as 0”.
So, when we are doing 5/0, so this actually doesn’t exist mathematically, this becomes infinity.
That is why it brings about a problem in our logic.
Our program understands it and the compiler displays an error, which we call a logical error, it means there is some problem with our logic.
What was the problem in the logic? We divided our number with 0 and we cannot divide anything with 0.
We have to minimum divide it with 1.
So, this was about our logical errors.
We will see even this practically, how they are generated.
Third error which we call as runtime error.
What is that? When there is no error during the compilation.
Which means our compiler did not get any error, it did not get the Syntax or no error in the logical but there is some problem during the runtime.
When we are running the program at that time it is not behaving properly.
In that situation we have to face, runtime error.
The run time error is not caught by the compiler.
But we have to search it by ourselves, why this type of problem is getting generated over here.
All these things or all the errors that we saw, we would generate them practically first.
We will purposefully do such mistake in our program, with which we got to know that here this kind of error will be generated.
And we will see that how that error can be rectified.
Now we will go into our text editor and we have made one sample templet over here of our C program.
In this very first we will try to generate one Syntax error.
In Syntax error we can do anything.
In the place of int, we have written INT in capital or instead of instead of main we have written mains, instead of return we have written returns, instead of #inclue, we have written $include.
If these mistakes happen even if unknowingly, that we consider in Syntax error.
Now what I will go here is I will make one variable and I will make the variable of this type and inside it I will store 5.
With the help of printf I will print it and see, exactly the values that I had stored in my a variable, it has come in which output.
So, you will see that everything is fine over here.
As soon as we will save it and we will try to execute it,…(Typing) it got easily executed and it has even run and it gave us 5 as the output.
So, this way about a normal program.
So, how the problem can occur in our syntax.
Lets suppose we wrote all these things but at the end we did not put semicolon at the end.
Right? Printf statement, everything we have written correctly, just semicolon we have not put.
So, what happened here? We have broken the C programming rule over here by not putting semicolon.
So, now we will again execute and see.
So, you can see that it has generated the error and given us.
And here has it generated the error? This printf statement is saying, “expected a semicolon”.
So, here one semicolon was expected.
This error that has come we call it as Syntax error.
Our compiler catches the Syntax error.
It knows that writing here has brought some issue.
That’s why it shows us the output in the terminal itself that in your program somewhere here ther is a problem.
So, we got to know that we have to put a semicolon over here.
Now we will save it.
Now you can see that if I write this int in capital, what is the error that we will get, lets see that.
So, here if we are again executing it.
Here you can see that there is one more error that has come and the error is “unknown type name INT”.
So, this is saying that have you made any error, did it mean W I N NT
or do you have made some or the other problem over here? Because this type of
data type is not defined in our C programming language.
So, that's why we can read it and rectify it over here.
Maybe here in INT, there was an error.
That's why we were facing this error.
Now we will run this now, everything is fine in our program.
That's why it got compiled and everything was fine.
So, we will run it now.
So, our output has come which we had stored in a.
This was about our Syntax error.
In this Syntax, we can make a mistake anywhere in the top or bottom, anywhere in the program.
It can happen by mistake or sometimes we forget to write.
In that situation we have to face Syntax error.
Now we will talk about a different type of an error which we call as a logical error.
And when do we face this logical error, we will see that.
Now what we will do here, we will make it, it is a simple program.
And we have done a=5.
Here I will make one more variable and what I will do in this variable is I will divide my a with zero.
Right? And here in the output I will try to print C.
So, what we are doing here is I have taken one variable a and in it that five is stored and I want to divide it with zero and I will be storing it in C variable and I will print C and see what exactly is the output that is coming out here.
When I perform this, you can see that I have got an error over here and the error is saying division by zero.
Division by zero we know as per maths it is an error because division by zero doesn't exist in real life.
We cannot divide anything in zero parts like I have a biscuit.
So, I will break the biscuit and I will divide it into two parts.
But if someone tells me that you have to divide the biscuit in zero parts, that situation cannot exist in real life, which means we cannot divide five by zero.
That's why it has generated this error over here.
And this error we call as logical error, which means that whatever is written is right.
All the rules of a C programming are correct.
But there is a problem in our logic, there is a problem that we have divided that particular number with zero.
So here we will not divide this number by zero and we will divide it by two.
If you divided it by two this value will be converted into decimal because 5 divided by 2 is 2.5.
So, we will create it in float, our C variable and here we will put this.
So, we will again execute it and see whether our answer is correct or not.
So, you can see that now I'm not getting any error because I have done everything right, logically and even syntactically.
So, as soon as I will run it over here.
You can see that I've got the output over here 2.00.
Which means that 5/2, it has created some problem again over here.
We will see here once again, this 5/2, why is it displaying 2.
So, instead of doing it this way.
Here there is some problem in the compiler.
We can do it in this way.
Rather than taking it into decimal, if we keep our variable in integer itself.
So here I have made a’s value as 6 and here if we do 6/2, so we should get 3 as an output in C.
So, we will see whether we are getting 3 here.
So, here as soon as we will execute it.
So here I'm getting 3 as an output.
So, in this way our logic should be absolutely correct.
So that in our computer or in our program we don’t have to face the logical errors.
Now we will talk about 1 more error which is called “Runtime” error.
Now what exactly is runtime error? Run time error means that complier is working correctly and the execution has also happened correctly, there is no problem with the Syntax, there is no problem even with the logic.
But when we are running it and doing some interaction with the user at that time we get to face that problem, we call that as runtime error.
How we can face that problem that we will be seeing over here.
So, what are we doing here is we have created the same scenario.
We have a and instead of defining it early on, I will do it as a and b.
So, that when I am taking user input from it.
There I can take both these values as a user input.
So, what I have done here, I have put two format specifiers and now I am going to take 2 values input from the user.
And what I will do about these two values? In the two values, I will perform this kind of an operation in which it will be “a/b” and I will close it over here.
And then we will print C and see.
So here our program is that we have to take two values from the user in a and b, after taking the values in A and B.
It will be stored in C and then we will print C.
So, I will save this.
Now we will run it and see it over here.
Now it has got run very easily.
We didn't have to face any error.
Our syntax is correct.
Our logic is correct.
Because there is no problem over here but as soon as I run it over here, you can see here that it is asking for some input over here from me.
It is asking for two numbers from me on which basically I'm going to perform the division.
So, I will give the first number as 12 and press enter.
And here basically I have to face this error.
Why? Because again, there was some problem with the logic.
And here we had not put ampersand in scan F.
What happens when we don't put the ampersand? Our compiler doesn't reach the variables address.
Whatever values that we are giving input from here that are not getting stored in a and b.
Even this is a type of logical error and we have rectified it over here.
Now we will execute it again and we will run it and you can see that again it is asking for the values here.
So, suppose I give the first value as 14.
Then I'll press Enter and give the second value.
And the second value will go and be saved in b, if I give 0 over here, the second value, you can see that as soon as I press enter here our program is abruptly closed without giving any output.
But why has this happened? Because we had given a’s value as 14 but when we gave b’s value, that we gave as zero and when we perform the operation over here, 14/0, It again became an error and that's why it was not able to complete over here.
It ended the program abruptly.
So, this we call as Runtime Error.
The error that we were getting earlier, even that was an runtime error because we had not got an ampersand.
By not giving the ampersand, our compiler was not able to reach a or b variable and it was not able to store the value over there.
So, here there is a point to concentrate on that our logical errors like we just spoke about divided by zero or about not putting the ampersand.
So, these logical errors can also be the runtime errors because maybe our compiler will find that logic correct.
But in real life, that logic will not work that's why it will generate that error in runtime.
It will create that problem.
That's why these errors can come in each other's category.
And a logical error can become a runtime error and the runtime error can be a logical error.
So, here with the help of the program, we saw how we can save ourselves from making a syntax error along with that we can check our logic again and again, if our logic is correct or not, is it doing such a thing that is not possible in real life.
And if I say that all the things I have solved properly, even after that, when I'm giving user input or I'm running my program at that time, such a problem is getting created, such a scenario is getting created, in which my program is not working properly.
So how to rectify all these errors that is what we have seen in this video.
If you think that there is any part of this video or this
topic, you might have not understood then you can ask us any query or question
related to that topic without any inhibition.
You just have to go on forums.learnvern.com, you have to type your query there in your own language and we will
come up with the solution or the
answer as soon as possible in your own language.
Apart from this if you wish to have a discussion on any topic.
Even that you will be able to do on forums.learnvern.com.
And now we will discuss our next topic.
Our next topic is going to be compilation and execution related.
In the next video we will be seeing this process of error generation, how our compiler reads the code and how it converts the code going ahead.
It gets executed basically.
So, all these things we will be seeing in our next video.
We will meet you in the next video.
Share a personalized message with your friends.