SlideShare a Scribd company logo
Mr. R.D.SIVAKUMAR, M.Sc.,M.Phil.,M.Tech.,
Assistant Professor of Computer Science &
Assistant Professor and Head, Department of M.Com.(CA),
Ayya Nadar Janaki Ammal College,
Sivakasi – 626 124.
Mobile: 099440-42243
e-mail : sivamsccsit@gmail.com
website: www.rdsivakumar.blogspot.in
A Sample C Program
A Sample C Program
A program is defined as a set of instructions to be executed sequentially to obtain the
desired result. A program cannot be written without a function. A function may be pre-
defined or user defined.
We will see the first program in C. The C program code is given below:
#include <stdio.h>
main()
{
printf(“Hello World”);
}
This program, upon execution, will display the message Hello World on the screen.
There must be a function defined as main().
The main() function is a user-defined one. The user has to define the main() function
to provide necessary code. When a C program runs, the control is transferred to this
function. This is called the program’s entry point. The program has two functions, one is
the user-defined main() function which is the entry point and the other one is printf()
function which is pre-defined and used to display the results on the standard
output(screen or monitor)
A Sample C Program
Simple parentheses () are used to represent a function. Here main() is the calling
function and printf() is the called function. The “Hello World” program with necessary
explanations is given below.
The first line in the program #include <stdio.h> is a preprocessor statement. #include
is a preprocessor directive. The preprocessor is a software program that will expand the
source code while the program is compiled.
The #include <stdio.h> statement includes the contents of the stdio.h file (standard
input and output header file) globally, that is, prior to the main() function. The contents
of the stdio.h file are the function declaration statements of the pre-defined output and
input functions like printf() and scanf() etc.
A Sample C Program
The declarations of the functions printf() and scanf() are as follows:
int printf(char *, …);
int scanf(char *, …);
The ellipses (…) represent that the above two functions can take variable number of
parameters. But the first parameter is always a string. A parameter is a data or
information passed on to the called function. Zero or more number of such parameters
are passed to any function.
They are given one after another within the brackets, which come after the name of
the function. In the program shown above, the printf() assumes only one parameter
which is a string to be displayed on the monitor. The first parameter type (string type) is
char * which will be read as “character pointer” and will be discussed later.
A Sample C Program
The C compiler is able to recognize the pre-defined functions only because of
their declarations in the appropriate header files. The following program
illustrates the use of header files. The program while it is being executed clears
the contents of the screen before displaying hello on the monitor.
The function clrscr() is a pre-defined one whose prototype (declaration) is available
in conio.h file and hence it has been included. If the statement #include <conio.h> is
not included, the C compiler expects the definition of clrscr() function from the
programmer and if the definition is not provided, it reports an error
Statements
Each and every line of a C program can be considered as a statement. There are
generally four types of statements. They are:
Preprocessor statement
• Function header statement
• Declaration statement
• Executable statement
As you know already, the preprocessor statement is used to expand the source
code by including the function declaration statements from the specified header
files. The function header statement is used as a first line in the definition of a
function. The declaration statements are further classified into variable
declaration statements and function declaration statements.
Assignment Statements
The assignment statement has the following form:
variable = expression
 Its purpose is saving the result of the expression to the right of the assignment
operator to the variable on the left. Here are some rules:
The expression is evaluated first with the rules discussed in the single mode or
the mixed mode expressions pages.
If the type of the expression is identical to that of the variable, the result is saved in
the variable.
Otherwise, the result is converted to the type of the variable and saved there.
If the type of the variable is INTEGER while the type of the result is REAL,
the fractional part, including the decimal point, is removed making it an integer
result.
If the type of the variable is REAL while the type of the result is INTEGER,
then
 a decimal point is appended to the integer making it a real number.
Once the variable receives a new value, the original one disappears and is no more
available. CHARACTER assignment follows the rules stated in the discussion of
the PARAMETER attribute.
Increment and Decrement Statements
Increment operators are used to increase the value of the variable by one and
decrement operators are used to decrease the value of the variable by one in C
programs.
Syntax:
Increment operator: ++var_name; (or) var_name++;
Decrement operator: – -var_name; (or) var_name – -;
Example:
Increment operator : ++ i ; i ++ ;
Decrement operator : - – i ; i – - ;
Expression
An expression occurs usually on the right hand side of an assignment statement.
It has a value when it is evaluated. There are many forms of expressions and some
of them are shown below:
int a,b,c; variable declaration statement
a = 10;
On the right hand side, a constant value is used and hence it is a constant
expression whose value is 10.
b = a;
A variable expression is used here whose value is 10. The right hand side of this
assignment statement has been associated with two values: a variable’s value and
an expression value. In this case both values are same.
But always remember that the expression value is assigned to the left hand side
variable. The expressions can be named based on the operators used. The other
expressions are:
right hand side
c = a+b; arithmetic expression
c = a > b; relational expression
f = d = e; assignment expression
Postfix and Prefix Increment Expression
++ and -- operator as prefix and postfix If you use ++ operator as prefix like:
++var; then, the value of operand is increased by 1 then, only it is returned but,
if you use ++ as postfix like: var++; then, the value of operand is returned first
then, only it is increased by 1
Input and Output Statements
Input : In any programming language input means to feed some data into program.
This can be given in the form of file or from command line. C programming
language provides a set of built-in functions to read given input and feed it to the
program as per requirement.
Output : In any programming language output means to display some data on
screen, printer or in any file. C programming language provides a set of built-in
functions to output required data.
Input and Output Statements
As we have seen already, the function printf() is used to display the results on the
standard output (screen). We have seen the use of printf() to display the string on
the monitor. Actually, the first parameter of the printf() function is a string which is
used to control the output and hence it can be called as “control string”. This
parameter is used to format the output for display and hence we can also call it as a
“formatting string”.
Example:
To print a value of an integer:
int n; /* variable n is declared as integer*/
n = 10;
printf(“%d”, n);
In the above example, ‘%d’ is used as a formatting character within the control
string of printf() function to display the value of an integer. The control string of
printf() function can take three types of characters.
• Ordinary characters
• Formatting characters
• Escape sequence characters
Input and Output Statements
Ordinary characters within the control string are displayed as such. In the case of
printf(“hello”); statement, the control string has ordinary characters only. They are
displayed as such on the screen. Table 4.4 lists the formatting characters used to
display the values of various types.
As seen already, the escape sequence characters are represented by a backslash
followed by another character. They are in fact single character constants only. They
are stored and manipulated as a single character. Escape sequences allow partial
control over the format of the output. The frequently used escape sequences in the
control string of printf() function are:
User defined functions
A function that is declare, calling and define by the user is called user
define function. Every user define function has three parts as:
Prototype or Declaration
Calling
Definition
Thank you..!!

More Related Content

What's hot

Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
Wingston
 
User_Defined_Functions_ppt_slideshare.
User_Defined_Functions_ppt_slideshare.User_Defined_Functions_ppt_slideshare.
User_Defined_Functions_ppt_slideshare.
NabeelaNousheen
 
Cnotes
CnotesCnotes
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
Mansi Tyagi
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
Vikram Nandini
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
imtiazalijoono
 
structure of a c program
structure of a c programstructure of a c program
structure of a c program
sruthi yandapalli
 
C fundamentals
C fundamentalsC fundamentals
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
Open Gurukul
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic conceptsAbhinav Vatsa
 
Chap 2 structure of c programming dti2143
Chap 2  structure of c programming dti2143Chap 2  structure of c programming dti2143
Chap 2 structure of c programming dti2143alish sha
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
sana shaikh
 
Function C programming
Function C programmingFunction C programming
Function C programming
Appili Vamsi Krishna
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
trupti1976
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya Jyothi
SowmyaJyothi3
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILEProgramming in C Presentation upto FILE
Programming in C Presentation upto FILE
Dipta Saha
 
Casa lab manual
Casa lab manualCasa lab manual
Casa lab manual
BHARATNIKKAM
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 

What's hot (20)

C Programming
C ProgrammingC Programming
C Programming
 
Cp module 2
Cp module 2Cp module 2
Cp module 2
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
User_Defined_Functions_ppt_slideshare.
User_Defined_Functions_ppt_slideshare.User_Defined_Functions_ppt_slideshare.
User_Defined_Functions_ppt_slideshare.
 
Cnotes
CnotesCnotes
Cnotes
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
structure of a c program
structure of a c programstructure of a c program
structure of a c program
 
C fundamentals
C fundamentalsC fundamentals
C fundamentals
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic concepts
 
Chap 2 structure of c programming dti2143
Chap 2  structure of c programming dti2143Chap 2  structure of c programming dti2143
Chap 2 structure of c programming dti2143
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya Jyothi
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILEProgramming in C Presentation upto FILE
Programming in C Presentation upto FILE
 
Casa lab manual
Casa lab manualCasa lab manual
Casa lab manual
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 

Similar to Sample for Simple C Program - R.D.Sivakumar

C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)indrasir
 
Chapter3
Chapter3Chapter3
Chapter3
Kamran
 
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. AnsariBasic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
G. H. Raisoni Academy of Engineering & Technology, Nagpur
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
SangeetaBorde3
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
rajkumar490591
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
TejaswiB4
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
TejaswiB4
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
REHAN IJAZ
 
Unit 2 CMath behind coding.pptx
Unit 2 CMath behind coding.pptxUnit 2 CMath behind coding.pptx
Unit 2 CMath behind coding.pptx
PragatheshP
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
sachindane
 
java or oops class not in kerala polytechnic 4rth semester nots j
java or oops class not in kerala polytechnic  4rth semester nots jjava or oops class not in kerala polytechnic  4rth semester nots j
java or oops class not in kerala polytechnic 4rth semester nots j
ishorishore
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman
 
Functions in C.pptx
Functions in C.pptxFunctions in C.pptx
Functions in C.pptx
KarthikSivagnanam2
 
Functions.pptx, programming language in c
Functions.pptx, programming language in cFunctions.pptx, programming language in c
Functions.pptx, programming language in c
floraaluoch3
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
Likhil181
 
C programming language for beginners
C programming language for beginners C programming language for beginners
C programming language for beginners
ShreyaSingh291866
 
Introduction%20C.pptx
Introduction%20C.pptxIntroduction%20C.pptx
Introduction%20C.pptx
20EUEE018DEEPAKM
 

Similar to Sample for Simple C Program - R.D.Sivakumar (20)

C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
 
Chapter3
Chapter3Chapter3
Chapter3
 
C programming
C programmingC programming
C programming
 
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. AnsariBasic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
 
Unit 1
Unit 1Unit 1
Unit 1
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
 
Unit 2 CMath behind coding.pptx
Unit 2 CMath behind coding.pptxUnit 2 CMath behind coding.pptx
Unit 2 CMath behind coding.pptx
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
 
java or oops class not in kerala polytechnic 4rth semester nots j
java or oops class not in kerala polytechnic  4rth semester nots jjava or oops class not in kerala polytechnic  4rth semester nots j
java or oops class not in kerala polytechnic 4rth semester nots j
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Functions in C.pptx
Functions in C.pptxFunctions in C.pptx
Functions in C.pptx
 
Functions.pptx, programming language in c
Functions.pptx, programming language in cFunctions.pptx, programming language in c
Functions.pptx, programming language in c
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
 
C programming language for beginners
C programming language for beginners C programming language for beginners
C programming language for beginners
 
Introduction%20C.pptx
Introduction%20C.pptxIntroduction%20C.pptx
Introduction%20C.pptx
 
Function in c
Function in cFunction in c
Function in c
 

More from Sivakumar R D .

Internet Connections and Its Protocols - R D Sivakumar
Internet Connections and Its Protocols - R D SivakumarInternet Connections and Its Protocols - R D Sivakumar
Internet Connections and Its Protocols - R D Sivakumar
Sivakumar R D .
 
Internet - R D Sivakumar.
Internet - R D Sivakumar.Internet - R D Sivakumar.
Internet - R D Sivakumar.
Sivakumar R D .
 
Data Communication - R D Sivakumar
Data Communication - R D SivakumarData Communication - R D Sivakumar
Data Communication - R D Sivakumar
Sivakumar R D .
 
NETWORK SERVICES - R D Sivakumar
NETWORK SERVICES - R D SivakumarNETWORK SERVICES - R D Sivakumar
NETWORK SERVICES - R D Sivakumar
Sivakumar R D .
 
Computer Communications - R D Sivakumar
Computer Communications - R D SivakumarComputer Communications - R D Sivakumar
Computer Communications - R D Sivakumar
Sivakumar R D .
 
Online Data Protection - R D Sivakumar
Online Data Protection - R D SivakumarOnline Data Protection - R D Sivakumar
Online Data Protection - R D Sivakumar
Sivakumar R D .
 
Software Engineering - R.D.Sivakumar
Software Engineering - R.D.SivakumarSoftware Engineering - R.D.Sivakumar
Software Engineering - R.D.Sivakumar
Sivakumar R D .
 
Different Kinds of Internet Protocols - R.D.Sivakumar
Different Kinds of Internet Protocols - R.D.SivakumarDifferent Kinds of Internet Protocols - R.D.Sivakumar
Different Kinds of Internet Protocols - R.D.Sivakumar
Sivakumar R D .
 
Internet - R.D.Sivakumar
Internet - R.D.SivakumarInternet - R.D.Sivakumar
Internet - R.D.Sivakumar
Sivakumar R D .
 
Electronic Publishing Tools for E-Learning - R.D.Sivakumar
Electronic Publishing Tools for E-Learning - R.D.SivakumarElectronic Publishing Tools for E-Learning - R.D.Sivakumar
Electronic Publishing Tools for E-Learning - R.D.Sivakumar
Sivakumar R D .
 
E-learning Packages - R.D.Sivakumar
E-learning Packages - R.D.SivakumarE-learning Packages - R.D.Sivakumar
E-learning Packages - R.D.Sivakumar
Sivakumar R D .
 
Digital Communication - R.D.Sivakumar
Digital Communication - R.D.SivakumarDigital Communication - R.D.Sivakumar
Digital Communication - R.D.Sivakumar
Sivakumar R D .
 
Digigogy in Teaching - R.D.Sivakumar
Digigogy in Teaching - R.D.SivakumarDigigogy in Teaching - R.D.Sivakumar
Digigogy in Teaching - R.D.Sivakumar
Sivakumar R D .
 
Cyber Commerce Technology - R.D.Sivakumar
Cyber Commerce Technology - R.D.SivakumarCyber Commerce Technology - R.D.Sivakumar
Cyber Commerce Technology - R.D.Sivakumar
Sivakumar R D .
 
Video Lesson Creation - R.D.Sivakumar
Video Lesson Creation - R.D.SivakumarVideo Lesson Creation - R.D.Sivakumar
Video Lesson Creation - R.D.Sivakumar
Sivakumar R D .
 
Cognitive and Personal Dimensions of Cyber Learning - R.D.Sivakumar
Cognitive and Personal Dimensions of Cyber Learning - R.D.SivakumarCognitive and Personal Dimensions of Cyber Learning - R.D.Sivakumar
Cognitive and Personal Dimensions of Cyber Learning - R.D.Sivakumar
Sivakumar R D .
 
Innovative Presentation - R.D.Sivakumar
Innovative Presentation - R.D.SivakumarInnovative Presentation - R.D.Sivakumar
Innovative Presentation - R.D.Sivakumar
Sivakumar R D .
 
Open Source in E-Learning - R.D.Sivakumar
Open Source in E-Learning - R.D.SivakumarOpen Source in E-Learning - R.D.Sivakumar
Open Source in E-Learning - R.D.Sivakumar
Sivakumar R D .
 
Tuxpaint - R.D.Sivakumar
Tuxpaint - R.D.SivakumarTuxpaint - R.D.Sivakumar
Tuxpaint - R.D.Sivakumar
Sivakumar R D .
 
Academic Blog Design - R.D.Sivakumar
Academic Blog Design - R.D.SivakumarAcademic Blog Design - R.D.Sivakumar
Academic Blog Design - R.D.Sivakumar
Sivakumar R D .
 

More from Sivakumar R D . (20)

Internet Connections and Its Protocols - R D Sivakumar
Internet Connections and Its Protocols - R D SivakumarInternet Connections and Its Protocols - R D Sivakumar
Internet Connections and Its Protocols - R D Sivakumar
 
Internet - R D Sivakumar.
Internet - R D Sivakumar.Internet - R D Sivakumar.
Internet - R D Sivakumar.
 
Data Communication - R D Sivakumar
Data Communication - R D SivakumarData Communication - R D Sivakumar
Data Communication - R D Sivakumar
 
NETWORK SERVICES - R D Sivakumar
NETWORK SERVICES - R D SivakumarNETWORK SERVICES - R D Sivakumar
NETWORK SERVICES - R D Sivakumar
 
Computer Communications - R D Sivakumar
Computer Communications - R D SivakumarComputer Communications - R D Sivakumar
Computer Communications - R D Sivakumar
 
Online Data Protection - R D Sivakumar
Online Data Protection - R D SivakumarOnline Data Protection - R D Sivakumar
Online Data Protection - R D Sivakumar
 
Software Engineering - R.D.Sivakumar
Software Engineering - R.D.SivakumarSoftware Engineering - R.D.Sivakumar
Software Engineering - R.D.Sivakumar
 
Different Kinds of Internet Protocols - R.D.Sivakumar
Different Kinds of Internet Protocols - R.D.SivakumarDifferent Kinds of Internet Protocols - R.D.Sivakumar
Different Kinds of Internet Protocols - R.D.Sivakumar
 
Internet - R.D.Sivakumar
Internet - R.D.SivakumarInternet - R.D.Sivakumar
Internet - R.D.Sivakumar
 
Electronic Publishing Tools for E-Learning - R.D.Sivakumar
Electronic Publishing Tools for E-Learning - R.D.SivakumarElectronic Publishing Tools for E-Learning - R.D.Sivakumar
Electronic Publishing Tools for E-Learning - R.D.Sivakumar
 
E-learning Packages - R.D.Sivakumar
E-learning Packages - R.D.SivakumarE-learning Packages - R.D.Sivakumar
E-learning Packages - R.D.Sivakumar
 
Digital Communication - R.D.Sivakumar
Digital Communication - R.D.SivakumarDigital Communication - R.D.Sivakumar
Digital Communication - R.D.Sivakumar
 
Digigogy in Teaching - R.D.Sivakumar
Digigogy in Teaching - R.D.SivakumarDigigogy in Teaching - R.D.Sivakumar
Digigogy in Teaching - R.D.Sivakumar
 
Cyber Commerce Technology - R.D.Sivakumar
Cyber Commerce Technology - R.D.SivakumarCyber Commerce Technology - R.D.Sivakumar
Cyber Commerce Technology - R.D.Sivakumar
 
Video Lesson Creation - R.D.Sivakumar
Video Lesson Creation - R.D.SivakumarVideo Lesson Creation - R.D.Sivakumar
Video Lesson Creation - R.D.Sivakumar
 
Cognitive and Personal Dimensions of Cyber Learning - R.D.Sivakumar
Cognitive and Personal Dimensions of Cyber Learning - R.D.SivakumarCognitive and Personal Dimensions of Cyber Learning - R.D.Sivakumar
Cognitive and Personal Dimensions of Cyber Learning - R.D.Sivakumar
 
Innovative Presentation - R.D.Sivakumar
Innovative Presentation - R.D.SivakumarInnovative Presentation - R.D.Sivakumar
Innovative Presentation - R.D.Sivakumar
 
Open Source in E-Learning - R.D.Sivakumar
Open Source in E-Learning - R.D.SivakumarOpen Source in E-Learning - R.D.Sivakumar
Open Source in E-Learning - R.D.Sivakumar
 
Tuxpaint - R.D.Sivakumar
Tuxpaint - R.D.SivakumarTuxpaint - R.D.Sivakumar
Tuxpaint - R.D.Sivakumar
 
Academic Blog Design - R.D.Sivakumar
Academic Blog Design - R.D.SivakumarAcademic Blog Design - R.D.Sivakumar
Academic Blog Design - R.D.Sivakumar
 

Recently uploaded

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 

Recently uploaded (20)

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 

Sample for Simple C Program - R.D.Sivakumar

  • 1. Mr. R.D.SIVAKUMAR, M.Sc.,M.Phil.,M.Tech., Assistant Professor of Computer Science & Assistant Professor and Head, Department of M.Com.(CA), Ayya Nadar Janaki Ammal College, Sivakasi – 626 124. Mobile: 099440-42243 e-mail : sivamsccsit@gmail.com website: www.rdsivakumar.blogspot.in A Sample C Program
  • 2. A Sample C Program A program is defined as a set of instructions to be executed sequentially to obtain the desired result. A program cannot be written without a function. A function may be pre- defined or user defined. We will see the first program in C. The C program code is given below: #include <stdio.h> main() { printf(“Hello World”); } This program, upon execution, will display the message Hello World on the screen. There must be a function defined as main(). The main() function is a user-defined one. The user has to define the main() function to provide necessary code. When a C program runs, the control is transferred to this function. This is called the program’s entry point. The program has two functions, one is the user-defined main() function which is the entry point and the other one is printf() function which is pre-defined and used to display the results on the standard output(screen or monitor)
  • 3. A Sample C Program Simple parentheses () are used to represent a function. Here main() is the calling function and printf() is the called function. The “Hello World” program with necessary explanations is given below. The first line in the program #include <stdio.h> is a preprocessor statement. #include is a preprocessor directive. The preprocessor is a software program that will expand the source code while the program is compiled. The #include <stdio.h> statement includes the contents of the stdio.h file (standard input and output header file) globally, that is, prior to the main() function. The contents of the stdio.h file are the function declaration statements of the pre-defined output and input functions like printf() and scanf() etc.
  • 4. A Sample C Program The declarations of the functions printf() and scanf() are as follows: int printf(char *, …); int scanf(char *, …); The ellipses (…) represent that the above two functions can take variable number of parameters. But the first parameter is always a string. A parameter is a data or information passed on to the called function. Zero or more number of such parameters are passed to any function. They are given one after another within the brackets, which come after the name of the function. In the program shown above, the printf() assumes only one parameter which is a string to be displayed on the monitor. The first parameter type (string type) is char * which will be read as “character pointer” and will be discussed later.
  • 5. A Sample C Program The C compiler is able to recognize the pre-defined functions only because of their declarations in the appropriate header files. The following program illustrates the use of header files. The program while it is being executed clears the contents of the screen before displaying hello on the monitor. The function clrscr() is a pre-defined one whose prototype (declaration) is available in conio.h file and hence it has been included. If the statement #include <conio.h> is not included, the C compiler expects the definition of clrscr() function from the programmer and if the definition is not provided, it reports an error
  • 6. Statements Each and every line of a C program can be considered as a statement. There are generally four types of statements. They are: Preprocessor statement • Function header statement • Declaration statement • Executable statement As you know already, the preprocessor statement is used to expand the source code by including the function declaration statements from the specified header files. The function header statement is used as a first line in the definition of a function. The declaration statements are further classified into variable declaration statements and function declaration statements.
  • 7. Assignment Statements The assignment statement has the following form: variable = expression  Its purpose is saving the result of the expression to the right of the assignment operator to the variable on the left. Here are some rules: The expression is evaluated first with the rules discussed in the single mode or the mixed mode expressions pages. If the type of the expression is identical to that of the variable, the result is saved in the variable. Otherwise, the result is converted to the type of the variable and saved there. If the type of the variable is INTEGER while the type of the result is REAL, the fractional part, including the decimal point, is removed making it an integer result. If the type of the variable is REAL while the type of the result is INTEGER, then  a decimal point is appended to the integer making it a real number. Once the variable receives a new value, the original one disappears and is no more available. CHARACTER assignment follows the rules stated in the discussion of the PARAMETER attribute.
  • 8. Increment and Decrement Statements Increment operators are used to increase the value of the variable by one and decrement operators are used to decrease the value of the variable by one in C programs. Syntax: Increment operator: ++var_name; (or) var_name++; Decrement operator: – -var_name; (or) var_name – -; Example: Increment operator : ++ i ; i ++ ; Decrement operator : - – i ; i – - ;
  • 9. Expression An expression occurs usually on the right hand side of an assignment statement. It has a value when it is evaluated. There are many forms of expressions and some of them are shown below: int a,b,c; variable declaration statement a = 10; On the right hand side, a constant value is used and hence it is a constant expression whose value is 10. b = a; A variable expression is used here whose value is 10. The right hand side of this assignment statement has been associated with two values: a variable’s value and an expression value. In this case both values are same. But always remember that the expression value is assigned to the left hand side variable. The expressions can be named based on the operators used. The other expressions are: right hand side c = a+b; arithmetic expression c = a > b; relational expression f = d = e; assignment expression
  • 10. Postfix and Prefix Increment Expression ++ and -- operator as prefix and postfix If you use ++ operator as prefix like: ++var; then, the value of operand is increased by 1 then, only it is returned but, if you use ++ as postfix like: var++; then, the value of operand is returned first then, only it is increased by 1 Input and Output Statements Input : In any programming language input means to feed some data into program. This can be given in the form of file or from command line. C programming language provides a set of built-in functions to read given input and feed it to the program as per requirement. Output : In any programming language output means to display some data on screen, printer or in any file. C programming language provides a set of built-in functions to output required data.
  • 11. Input and Output Statements As we have seen already, the function printf() is used to display the results on the standard output (screen). We have seen the use of printf() to display the string on the monitor. Actually, the first parameter of the printf() function is a string which is used to control the output and hence it can be called as “control string”. This parameter is used to format the output for display and hence we can also call it as a “formatting string”. Example: To print a value of an integer: int n; /* variable n is declared as integer*/ n = 10; printf(“%d”, n); In the above example, ‘%d’ is used as a formatting character within the control string of printf() function to display the value of an integer. The control string of printf() function can take three types of characters. • Ordinary characters • Formatting characters • Escape sequence characters
  • 12. Input and Output Statements Ordinary characters within the control string are displayed as such. In the case of printf(“hello”); statement, the control string has ordinary characters only. They are displayed as such on the screen. Table 4.4 lists the formatting characters used to display the values of various types. As seen already, the escape sequence characters are represented by a backslash followed by another character. They are in fact single character constants only. They are stored and manipulated as a single character. Escape sequences allow partial control over the format of the output. The frequently used escape sequences in the control string of printf() function are:
  • 13. User defined functions A function that is declare, calling and define by the user is called user define function. Every user define function has three parts as: Prototype or Declaration Calling Definition