1) The
C language is a low level language with characters, numbers and constants
2) The only way
to learn a new programming language is by writing programs in it. While going
into the structure of C program we will see a small example, if we want to
print "hiii to all" in C language we have to write a program which is
as follows
#include<stdio.h>
main()
{
printf("hiii to
all");
}
3) The C program is saved by an extension
.C, If we want to run this code first
we have to do compilation, to compile we have to use command cc filename.c , if the file name you want to give as hiii so you have to save it as hiii.c and for compilation we have to write cc hiii.c then if no errors are displayed , then we have to run the program we have to type the command a. out then it prints hiii to all.
we have to do compilation, to compile we have to use command cc filename.c , if the file name you want to give as hiii so you have to save it as hiii.c and for compilation we have to write cc hiii.c then if no errors are displayed , then we have to run the program we have to type the command a. out then it prints hiii to all.
4) Now you got an idea how we write a
program in C language. Let’s see what is the structure of a C program
Let u know about each thing in detail
11)
Documentation section: In this
section we can declare multiline function(*------*) in this function we can
write the name of the program or any matter which is not considered by the
compiler and we can also declare comment lines(//--------)where we can write
what actually the meaning of the particular line
For example:
printf("hiii to all);
//it prints hiii to all on the screen
2)
Link section: In this section we
declare predefined functions like #include<stdio.h> which is also called
as library function in this it includes the definitions of what we declare in
the program like printf(), scanf() etc.,
3)
Definition function: Some of the
constants are not included in the library function like pi value and if you
want to define our own values for a particular variable we can define in this
section example:#define Pi 3.1717.It is not compulsion to define this section
in all programs it is our requirement to
define in a program
4)
Global declaration section: A
local variable is a variable that is declared inside a function. A global
variable is a variable that is declared outside all functions. A local variable
can only be used in the function where it is declared. A global variable can be
used in all functions .Local variable is different than global variables, the
constants like int a=2; if declared in a particular function it is a local
variable and if it is declared in main() part it is global declaration
5)
Main() function section: As the
name indicates this section is heart of the program without this the
program cannot be executed if you do not
write this section the program is invalid
6)
Subprogram section: This section
is wriiten inside main section whatever we write in the main() is logic let us
see an example program to add two numbers
#include<stdio.h> //link section
main() //main()
function
{
int a,b,c; //global
declarations
a=10;
b=5;
c=a+b;
printf("the sum is c=%d,"c);
}
No comments:
Post a Comment