How actually the code executes in C.
--
Here I will give a simple example and explain how the code executes line by line-
This is a basic C program to add 2 Numbers, Going through it line by line-
1-The first line ‘#include<stdio.h>’ what it is doing is, It is building the inbuilt modules which includes functions such as scanf, printf and many others functions.
2-Coming to the ‘int main()’ line this line basically mean that it is expecting a return of integer for the main function, In order to keep it simple for the starting just make the return type void for this example. I will talk in detail about in detail in another series of notes.
3-The curly braces are used to define the body of function and scope of control statements.
4-We are initializing 3 variables as A, B, and sum=0,all 3 have type as int.
5- Print Function will simply print the statement which is written in inverted commas.
6-We use scanf(Here %d is a format specifier and & is a address of the variable where it get stored)to take input from the user.
7-We are adding 2 values and assigning it to sum.
8-Printing our result in printf statement.
9-At last we are return the values as 0,Because we defined our main function as int. In case of void nothing will get returned.