A C program, whatever its size, consists of functions and variables. A function contains statements that specify the computing operations to be done, and variables store values used during the computation.
C functions are like the subroutines and functions in Fortran or the procedures and functions of Pascal. Our example is a function named main. Normally you are at liberty to give functions whatever names you like, but "main'' is special - your program begins executing at the beginning of main. This means that every program must have a main somewhere. main will usually call other functions to help perform its job, some that you wrote, and others from libraries that are provided for you.
The first line of the program,
#include <stdio.h> tells the compiler to include information about the standard input/output library; the line appears at the beginning of many C source files.
One method of communicating data between functions is for the calling function to provide a list of values, called arguments, to the function it calls. The parentheses after the function name surround the argument list. In this example, main is defined to be a function that expects no arguments, which is indicated by the empty list ( ).
#include <stdio.h> include information about standard library
main() define a function called main
{
that received no argument values
statements of main are enclosed in braces
printf("hello, world\n"); main calls library function printf
to print this sequence of characters
} \n represents the newline character
In computer programming, an entry point is where control enters a program or piece of code and execution begins. This marks the transition from load time (and dynamic link time, if present) to run time.
Most simply, programs begin execution at the beginning; this is common in scripting language, simple binary executable formats, and boot loaders. In other cases the entry point is at some other fixed point, at some memory address – an absolute address or relative address (offset).
Alternatively, execution can begin at a named point, either with a conventional name fixed by the language or system, or at a caller-specified name. In many programming languages, notably C, this is a function called main, and thus the entry point is often called the main function.
In C and C++, the function prototype of the main function looks like one of the following:
int main(void);
int main();
int main(int argc, char **argv);
int main(int argc, char *argv[]);
In C and C++, the function prototype of the main function looks like one of the following:
int main(void);
int main();
int main(int argc, char **argv);
int main(int argc, char *argv[]);
The parameters argc, argument count, and argv, argument vector,respectively give the number and values of the program's command-line arguments. The names of argc and argv may be any valid identifier in C, but it is common convention to use these names.
In C++, the names are to be taken literally, and the "void" in the parameter list is to be omitted, if strict conformance is desired.Other platform-dependent formats are also allowed by the C and C++ standards, except that in C++ the return type must always be int; for example, Unix (though not POSIX.1) and Microsoft Windows have a third argument giving the program's environment, otherwise accessible through getenv in stdlib.h.
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
ReplyDeletewebsite: geeksforgeeks.org
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
ReplyDeletewebsite: geeksforgeeks.org
A Computer Science portal for geeks. It contains well written, well thought and well
ReplyDeleteexplained computer science and programming articles, quizzes and practice/competitive
programming/company interview Questions.
website: geeksforgeeks.org