






































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







































A computer program is set of instructions,written in any of the computer languages,as a step by step solution of problems.
Programming is the process of planning,designing,
writing,
testing
and
maintaining
these
procedures
or
programs according to user need.
Through
this
approach
one
can
have
accurate, error free code.
Each module can have – sequence, selectionor iterative statements.
C
programs
are
run
on
different
environment.
E.g.
if
u
have
written
a
C
program
in
windows 95, then it can be executed in UNIXwithout any or little modification.
docsity.com
A Simple C Program Structure
/* Filename:
hello.c
Author: N.S.Dhindsa
Date written: 03/08/2012Description:
This program prints the greeting
“Hello, World!”
*/
#include <stdio.h>int main ( void ){
printf ( “Hello, World!\n” ) ;return 0 ;
}
Comment: •
A comment is descriptive text used to help areader of the program understand its content.
All comments must begin with the characters/* and end with the characters */
These are called comment delimiters.
The program header comment always comesfirst.
Text surrounded by /* and */ is ignored bycomputer.
Used to describe program.
The reserved word “int” indicates thatmain( ) returns an integer value.
The parentheses following the reservedword
“main”
indicate
that
it
is
a
function.
Braces { and } indicate a block.
The bodies of all functions must becontained in braces.
docsity.com
printf( “Prog. In C is easy. %s \n", input );
printf( ) is a library function declared in<stdio.h>
Syntax:
printf(
FormatString
Expr
Expr
FormatString
: String of text to print.
FormatString
has
placeholders
to
show
where to put the values.
printf (“Hello, World!\n”) ;
All
statements
in
end
with
a
semicolon(;).
Entire line is called a statement.
printf() prints the text/string of characterswithin double quotes (“ ”).
Escape character () indicates that printf( )should do something out of the ordinary.
docsity.com
return 0 ;
Because
function
main()
returns
an
integer
value,
there
must
be
a
statement that indicates what this valueis.
The statement return 0 indicates thatmain() returns a value of zero to theoperating system.
A value of 0 indicates that the programsuccessfully terminated execution.
docsity.com
program header comment preprocessor directives (if any) int main ( void ){
statement (s); return 0 ;
}
The C language consists of:
(lower case)
docsity.com