Hello guys, to I am gonna tell you guys about main
function and will our program can be complied without main function….
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("hello world");
}
#include<conio.h>
void main()
{
clrscr();
printf("hello world");
}
Here in this program why
there’s not a semi-colon after parenthesis ()?
Unlike
clrscr() , we are basically defining a function named as main. Any name
followed by parenthesis is a function in C language. We will discuss more about
functions later on. so if we place a semicolon after function name with a
parenthesis we basically calls a function .when we call a function it executes
the codes or instruction which are written between curly brackets {}.
What if
we don’t define main function?????
We can
define function of any name like Hello() , program() etc. but what if we don’t
define main function.
So if we
don’t define main function the program will compile successfully, the only
problem what we come across is that we can’t run our program. Our IDE of C language
is only responsible for compiling our codes. Neither C language nor our IDE
runs our program. Running a program is the job of your operating system.
Operating system first searches for main function before executing our codes or
instruction. So if we won’t define main function , our program will compile
successfully but we won’t able to run our program as operating system will be
unable to find main function.so there will be an runtime error.
Thank you!!!!! Happy holi
!!!!
0 comments:
Post a Comment