SlideShare ist ein Scribd-Unternehmen logo
1 von 47
Handling
Input/output
&
Control Statements
Course: BCA
Subject: Programming In C Language
ARRAYS
An array is a group of related data items that share a
common name. For instance, we can define array
name salary to represent a set of salary of a group
of employees.
A particular value is indicated by writing a number
called index number or subscript in brackets after the
array name.
Eg: salary[10]
ONE DIMENSIONAL ARRAY
 An array with a single subscript is known as one
dimensional array.
 Eg: 1) int number[5];
 The values to array elements can be assigned as
follows.
 Eg: 1) number[0] = 35;
 number[1] = 40;
 number[2] = 20;
Declaration of Arrays
 The general form of array declaration is
type variable-name[size];
The type specifies the type of element that will be
contained in the array, such as int, float, or char and the
size indicates the maximum number of elements that
can be stored inside the array.
Cont..
 There is no convenient way to initialize only selected
elements.
 There is no shortcut method for initializing a large number
of array elements like the one available in FORTRAN
 Eg:
1) float height[50];
2) int group[10];
3)char name[10];
Initialization of Arrays
 The general form of initialization of arrays is:
static type array-name[size] = {list of values};
Eg:
static int number[3] = {0,0};
If the number of values in the list is less than the number of
elements, then only that many elements will be initialized.
The remaining elements will be set to zero automatically.
Initialization of arrays in C suffers two drawbacks
Cont..
 We can use the word ‘static’ before type declaration. This
declares the variable as a static variable.
 Eg :
1) static int counter[] = {1,1,1};
2)
………
………
for(i =0; i < 100; i = i+1)
{
if i < 50
sum[i] = 0.0;
else
sum[i] = 1.0;
}
……….
……….
/*Program showing one-dimensional array*/
main()
{
int i;
float x[10],value,total;
printf(“Enter 10 real
numbers:n”);
for(i =0; i < 10; i++)
{
scanf(“%f”,&value);
x[i] = value;
}
total = 0.0;
for(i = 0; i < 10; i++)
total = total + x[i] * x[i];
printf(“n”);
for(i = 0; i < 10; i++)
printf(“x[%2d] = %5.2f
n”,i+1,x[i]);
printf(“nTotal = %.2fn”,total);
}
 OUTPUT
 Enter 10 real numbers:
 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9
10.10
 x[1] = 1.10
 x[2] = 2.20
 x[3] = 3.30
 x[4] = 4.40
 x[5] = 5.50
 x[6] = 6.60
 x[7] = 7.70
 x[8] = 8.80
 x[9] = 9.90
 x[10] = 10.10
 Total = 446.86
TWO-DIMENSIONAL ARRAYS
 Two-dimensional arrays are declared as follows:
type array-name[row_size][column_size];
Eg:
product[i][j] = row * column;
MULTIDIMENSIONAL ARRAY
 C allows arrays of three or more dimensions. The exact
limit is determined by the compiler.
 The general form of a multidimensional array is
type array_name[s1][s2][s3]…s[m];
 Eg:
1. int survey[3][5][12];
2. float table[5][4][5][3];
String
 A string is a array of characters. Any group of
characters(except the double quote sign) defined between
double quotation marks is a constant string.
 Eg: 1) “Man is obviously made to think”
 If we want to include a double quote in a string, then we
may use it with the back slash.
 Eg:
 printf(“”well done!””);
 will output
 “well done!”
Cont..
 The operations that are performed on character strings
are
 Reading and writing strings.
 Combining strings together.
 Copying one string to another.
Comparing strings for equality.
 Extracting a portion of a string.
DECLARING AND INITIALIZING STRING VARIABLES
 A string variable is any valid C variable name and is always declared as an
array.
 The general form of declaration of a string variable is
 char string_name[size];
 Eg:
char city[10];
char name[30];
 When the compiler assigns a character string to a character array, it
automatically supplies a null character (‘0’) at the end of the string.
 Therefore, the size should be equal to the maximum number of characters in
the string plus one. C permits a character array to be initialized in either of
the following two forms:
 static char city[9] = “NEW YORK”;
 static char city[9] = {‘N’, ‘E’, ‘W’, ‘ ‘, ‘Y’, ‘O’, ‘R’, ‘K’, ‘0’};
Cont..
 Reading Words
 The familiar input function scanf can be used with %s
format specification to read in a string of characters.
 Eg:
char address[15];
scanf(“%s”,address);
Program
/*Reading a series of words using scanf function*/
main()
{
char
word1[40],word2[40],word3[40],
word4[40];
printf(“Enter text:n”);
scanf(“%s %s”,word1, word2);
scanf(“%s”, word3);
scanf(“%s”,word4);
printf(“n”);
printf(“word1 = %s n word2 = %s
n”,word1, word2);
printf(“word3 = %s n word4 = %s
n”,word3, word4);
}
 OUTPUT
 Enter text:
 Oxford Road, London
M17ED
 Word1 = Oxford
 Word2 = Road
 Word3 = London
 Word4 = M17ED
Reading a Line of Text
 It is not possible to use scanf function to read a line
containing more than one word.
 This is because the scanf terminates reading as soon as
a space is encountered in the input.
 We can use the getchar function repeatedly to read
single character from the terminal, using the function
getchar.
 Thus an entire line of text can be read and stored
in an array.
WRITING STRINGS TO SCREEN
 We have used extensively the printf function with %s
format to print strings to the screen.
 The format %s can be used to display an array of
characters that is terminated by the null character.
 For eg, the statement
 printf(“%s”, name);
 can be used to display the entire contents of the array
name.
ARITHMETIC OPERATIONS ON CHARACTERS
 C allows us to manipulate characters the same way we
do with numbers.
 Whenever a character constant or character variable is
used in an expression, it is automatically converted
into integer value by the system.
 For eg, if the machine uses the ASCII representation,
then,
x = ‘a’;
printf(“%d n”,x);
 will display the number 97 on the screen.
String Function
 The C library supports a function that converts a string
of digits into their integer values.
 The function takes the form:
x = atoi(string)
PUTTING STRINGS TOGETHER
Just as we cannot assign one string to another directly,
we cannot join two strings together by the simple
arithmetic addition. That is, the statements such as
string3 = string1 + string2;
string2 = string1 + “hello”;
are not valid. The characters from string1 and
string2 should be copied into string3 one after the
other.
The process of combining two strings together is called
concatenation.
COMPARISON OF TWO STRINGS
 C does not permit the comparison of two strings directly.
That is, the statements such as are not permitted.
if(name1 == name2)
if(name == “ABC”);
 It is therefore necessary to compare the two strings to
be tested, character by character.
 The comparison is done until there is a mismatch or one of
the strings terminate into a null character, whichever
occurs first.
STRING - HANDLING FUNCTIONS
 C library supports a large number of string-handling
functions that can be used to carry out many of the string
manipulation activities. Following are the most commonly
usedFunction Action
 strcat( ) Concatenates two strings
 strcmp( ) Compares two strings
 strcpy( ) Copies one string over another
 strlen( ) Finds the length of the string
Cont..
 strcat( ) Function
 The strcat function joins two strings together.
 It takes the following form
 strcat( string1,string2);
 Eg:
 strcat(part1, “GOOD”);
 strcat(strcat(string1,string2),string3);
 Here three strings are concatenated and the result is stored in
string1.
Cont..
 strcmp( ) Function
 It is used to compare two strings identified by the
arguments and has a value 0 if they are equal.
 It takes the form:
 Eg:
1) strcmp(name1,name2);
2) strcmp(name1,”john”;
3) strcmp(“ram”, “rom”);
Cont..
 strcpy( ) Function
 This function works almost like a string assignment
operator. It takes the form
 strcpy(string1,string2);
 This assigns the content of string2 to string1.
 Eg:
strcpy(city, “DELHI”);
strcpy(city1,city2);
Cont..
 strlen( ) Function
 This function counts and returns the number of
characters in a string.
n = strlen(string);
Function
 C functions can be classified into two categories,
namely, library functions and userdefined functions.
 Main is an example of user-defined functions,
printf and scanf belong to the category of library
functions.
 The main difference between these two categories is
that library functions are not required to be written by
us whereas a user-defined function has to be
developed by the user at the time of writing the
program
THE FORM OF C FUNCTIONS
 Function-name(argument list)
argument declaration;
{
local variable declarations;
executable statement-1;
executable statement-2;
………
………
return(expression);
}
 A function that does nothing may not include any
executable statements.
For eg:
do_nothing( ) { }
Function Include Following elements:
RETURN VALUES AND THEIR TYPES
 The return statement can take the form:
return
or
return(expression);
 Eg:
if(x <= 0)
return(0);
else
return(1);
CALLING A FUNCTION
 A function can be called by simply using the function name
in the statement.
 Eg:
main()
{
int p;
p = mul(10,5);
printf(“%d n”, p);
}
 When the compiler executes a function call, the control is
transferred to the function mul(x,y).
 The function is then executed line by line as described and the value
is returned,
 when a return statement is encountered. This value is assigned to p.
CATEGORY OF FUNCTIONS
 A function may belong to one of the following
categories.
1) Functions with no arguments and no return values.
2) Functions with arguments and no return values.
3) Functions with arguments and return values.
NO ARGUMENTS AND NO RETURN VALUES
 A function does not receive any data from the calling
function. Similarly, it does not return any value.
ARGUMENTS BUT NO RETURN VALUES
 The nature of data communication between the
calling function and the called function with
arguments but no return values is shown in the
diagram
ARGUMENTS WITH RETURN VALUES
 Here there is a two-way data
communication between the
calling and the called
function.
function1( )
{
----------
function2(a )
----------
----------
}
function2(f )
---------
{
---------
---------
return e;
}
function1( )
{
----------
function2(a )
----------
----------
}
Values of Argument
Function Results
RECURSION
 When a function in turn calls another function a
process of ‘chaining’ occurs
 The recursive function is
 a kind of function that calls itself, or
 a function that is part of a cycle in the sequence of
function calls.
 Recursion is a special case of this process, where a
function calls itself.
f1 f1 f2 fn…
Cont.
Eg:
main()
{
printf(“Example for recursion”);
main();
}
This is follows from the format of a recursive definition as
consisting of two parts:
1. Initialization –analogous to induction base cases
2. Recursion –analogous to induction step
Cont..
A simple example of a recursively defined function is the factorial
function:
n! = 1· 2· 3· 4 ···(n –2)·(n –1)·n
Fact=n*factorial(n-1);
Fact=3*factorial(2);
2*factorial
 Recursion is one way to decompose a task into smaller subtasks.
At least one of the subtasks is a smaller example of the same task.
 The smallest example of the same task has a non-recursive
solution.
Cont..
INITIALIZATION: 0!= 1
RECURSION: n != n · (n -1)!
To compute the value of a recursive function,
e.g. 5!, one plugs into the recursive definition obtaining
expressions involving lower and lower values of the
function, until arriving at the base case.
recursion
EG: 5! = 5 · 4! = 5 · 4 · 3! = 5 · 4 · 3 · 2!= 5 · 4 · 3 · 2 · 1! = 5 · 4 · 3 · 2 · 1 · 0!
= 5 · 4 · 3 · 2 · 1 · 1 = 120
FUNCTIONS WITH ARRAYS
 To pass an array to a called function, it is sufficient to
list the name of the array, without any subscripts, and
the size of the array as arguments.
 Eg:
largest(a,n);
Storage Class
 A variable in C can have any one of the four storage
classes.
1. Automatic variables.
2. External variables.
3. Static variables.
4. Register variables.
AUTOMATIC VARIABLES (LOCAL/INTERNAL)
 Automatic variables are declared inside a function in which
they are to be utilized.
 They are created when a function is called and destroyed
automatically when the function is
 exited.
 Eg:
main()
{
int number;
---------
---------
}
 We may also use the keyword auto to declare automatic
variables explicitly.
EXTERNAL VARIABLES
 Variables that are both alive and active throughout
the entire program are known as external
variables.
 They are also known as global variables
Eg:
int number;
float length = 7.5;
Cont..
main()
{
-------
-------
}
function1( )
{
-------
-------
}
function2( )
{
-------
-------
}
The keyword extern can be used for explicit declarations of external
variables.
STATIC VARIABLES
 As the name suggests, the value of a static variable
persists until the end of the program.
 A variable can be declared static using the keyword
static.
 Eg:
1) static int x;
2) static int y;
REGISTER VARIABLES
 We can tell the compiler that a variable should be kept
in one of the machine’s registers, instead of keeping in
the memory.
 Since a register access is much faster than a memory
access, keeping the frequently accessed variables in the
register will lead to faster execution of programs.
 This is done as follows: register int count;
References:
1. Programming in C by yashwant kanitkar
2. ANSI C by E.balagurusamy- TMG publication
3. Computer programming and Utilization by sanjay shah Mahajan Publication
4. www.cprogramming.com/books.html
5. en.wikipedia.org/wiki/C_(programming_language)
6. www.programmingsimplified.com/c-program-example
7. http://cm.bell-labs.com/cm/cs/who/dmr/chist.html
8. http://en.wikipedia.org/wiki/datatypes in c language
9. http://en.wikipedia.org/wiki/List_of_C-based_programming_languages
10. http://en.wikipedia.org/wiki/C_(programming_language)

Weitere ähnliche Inhalte

Was ist angesagt?

Character Array and String
Character Array and StringCharacter Array and String
Character Array and StringTasnima Hamid
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocationViji B
 
Virtual base class
Virtual base classVirtual base class
Virtual base classTech_MX
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaRahulAnanda1
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in javaNilesh Dalvi
 
Enumerated data types in C
Enumerated data types in CEnumerated data types in C
Enumerated data types in CArpana shree
 
File handling in Python
File handling in PythonFile handling in Python
File handling in PythonMegha V
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAMaulik Borsaniya
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programmingKamal Acharya
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ pptKumar
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator OverloadingNilesh Dalvi
 

Was ist angesagt? (20)

Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Type casting
Type castingType casting
Type casting
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 
C++ string
C++ stringC++ string
C++ string
 
Virtual base class
Virtual base classVirtual base class
Virtual base class
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 
Enumerated data types in C
Enumerated data types in CEnumerated data types in C
Enumerated data types in C
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
 
Python OOPs
Python OOPsPython OOPs
Python OOPs
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Control structure
Control structureControl structure
Control structure
 
File in C language
File in C languageFile in C language
File in C language
 

Andere mochten auch (20)

Arrays In C Language
Arrays In C LanguageArrays In C Language
Arrays In C Language
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Arrays
ArraysArrays
Arrays
 
Arrays
ArraysArrays
Arrays
 
Pointers In C
Pointers In CPointers In C
Pointers In C
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
Passing an Array to a Function (ICT Programming)
Passing an Array to a Function (ICT Programming)Passing an Array to a Function (ICT Programming)
Passing an Array to a Function (ICT Programming)
 
Strings(2007)
Strings(2007)Strings(2007)
Strings(2007)
 
Mission and Vision
Mission and VisionMission and Vision
Mission and Vision
 
Programming & Data Structure Lecture Notes
Programming & Data Structure Lecture NotesProgramming & Data Structure Lecture Notes
Programming & Data Structure Lecture Notes
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
 
Unit 8. Pointers
Unit 8. PointersUnit 8. Pointers
Unit 8. Pointers
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in C
 
C string
C stringC string
C string
 
Computer Programming- Lecture 5
Computer Programming- Lecture 5 Computer Programming- Lecture 5
Computer Programming- Lecture 5
 
Functions in C
Functions in CFunctions in C
Functions in C
 

Ähnlich wie function, storage class and array and strings

C UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYC UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYRajeshkumar Reddy
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)SURBHI SAROHA
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
Chapter 13.1.7
Chapter 13.1.7Chapter 13.1.7
Chapter 13.1.7patcha535
 
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptxganeshkarthy
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of cTushar B Kute
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingRasan Samarasinghe
 
Dti2143 chapter 5
Dti2143 chapter 5Dti2143 chapter 5
Dti2143 chapter 5alish sha
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its functionFrankie Jones
 

Ähnlich wie function, storage class and array and strings (20)

Array &strings
Array &stringsArray &strings
Array &strings
 
Unit 2
Unit 2Unit 2
Unit 2
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
 
C UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYC UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDY
 
Strings
StringsStrings
Strings
 
[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
 
Unitii string
Unitii stringUnitii string
Unitii string
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
 
String notes
String notesString notes
String notes
 
Chapter 13.1.7
Chapter 13.1.7Chapter 13.1.7
Chapter 13.1.7
 
Session 4
Session 4Session 4
Session 4
 
Lecture 05 2017
Lecture 05 2017Lecture 05 2017
Lecture 05 2017
 
string , pointer
string , pointerstring , pointer
string , pointer
 
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
 
Dti2143 chapter 5
Dti2143 chapter 5Dti2143 chapter 5
Dti2143 chapter 5
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its function
 
Arrays
ArraysArrays
Arrays
 

Mehr von Rai University

Brochure Rai University
Brochure Rai University Brochure Rai University
Brochure Rai University Rai University
 
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,Rai University
 
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02Rai University
 
Bsc agri 2 pae u-4.3 public expenditure
Bsc agri  2 pae  u-4.3 public expenditureBsc agri  2 pae  u-4.3 public expenditure
Bsc agri 2 pae u-4.3 public expenditureRai University
 
Bsc agri 2 pae u-4.2 public finance
Bsc agri  2 pae  u-4.2 public financeBsc agri  2 pae  u-4.2 public finance
Bsc agri 2 pae u-4.2 public financeRai University
 
Bsc agri 2 pae u-4.1 introduction
Bsc agri  2 pae  u-4.1 introductionBsc agri  2 pae  u-4.1 introduction
Bsc agri 2 pae u-4.1 introductionRai University
 
Bsc agri 2 pae u-3.3 inflation
Bsc agri  2 pae  u-3.3  inflationBsc agri  2 pae  u-3.3  inflation
Bsc agri 2 pae u-3.3 inflationRai University
 
Bsc agri 2 pae u-3.2 introduction to macro economics
Bsc agri  2 pae  u-3.2 introduction to macro economicsBsc agri  2 pae  u-3.2 introduction to macro economics
Bsc agri 2 pae u-3.2 introduction to macro economicsRai University
 
Bsc agri 2 pae u-3.1 marketstructure
Bsc agri  2 pae  u-3.1 marketstructureBsc agri  2 pae  u-3.1 marketstructure
Bsc agri 2 pae u-3.1 marketstructureRai University
 
Bsc agri 2 pae u-3 perfect-competition
Bsc agri  2 pae  u-3 perfect-competitionBsc agri  2 pae  u-3 perfect-competition
Bsc agri 2 pae u-3 perfect-competitionRai University
 

Mehr von Rai University (20)

Brochure Rai University
Brochure Rai University Brochure Rai University
Brochure Rai University
 
Mm unit 4point2
Mm unit 4point2Mm unit 4point2
Mm unit 4point2
 
Mm unit 4point1
Mm unit 4point1Mm unit 4point1
Mm unit 4point1
 
Mm unit 4point3
Mm unit 4point3Mm unit 4point3
Mm unit 4point3
 
Mm unit 3point2
Mm unit 3point2Mm unit 3point2
Mm unit 3point2
 
Mm unit 3point1
Mm unit 3point1Mm unit 3point1
Mm unit 3point1
 
Mm unit 2point2
Mm unit 2point2Mm unit 2point2
Mm unit 2point2
 
Mm unit 2 point 1
Mm unit 2 point 1Mm unit 2 point 1
Mm unit 2 point 1
 
Mm unit 1point3
Mm unit 1point3Mm unit 1point3
Mm unit 1point3
 
Mm unit 1point2
Mm unit 1point2Mm unit 1point2
Mm unit 1point2
 
Mm unit 1point1
Mm unit 1point1Mm unit 1point1
Mm unit 1point1
 
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
 
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
 
Bsc agri 2 pae u-4.3 public expenditure
Bsc agri  2 pae  u-4.3 public expenditureBsc agri  2 pae  u-4.3 public expenditure
Bsc agri 2 pae u-4.3 public expenditure
 
Bsc agri 2 pae u-4.2 public finance
Bsc agri  2 pae  u-4.2 public financeBsc agri  2 pae  u-4.2 public finance
Bsc agri 2 pae u-4.2 public finance
 
Bsc agri 2 pae u-4.1 introduction
Bsc agri  2 pae  u-4.1 introductionBsc agri  2 pae  u-4.1 introduction
Bsc agri 2 pae u-4.1 introduction
 
Bsc agri 2 pae u-3.3 inflation
Bsc agri  2 pae  u-3.3  inflationBsc agri  2 pae  u-3.3  inflation
Bsc agri 2 pae u-3.3 inflation
 
Bsc agri 2 pae u-3.2 introduction to macro economics
Bsc agri  2 pae  u-3.2 introduction to macro economicsBsc agri  2 pae  u-3.2 introduction to macro economics
Bsc agri 2 pae u-3.2 introduction to macro economics
 
Bsc agri 2 pae u-3.1 marketstructure
Bsc agri  2 pae  u-3.1 marketstructureBsc agri  2 pae  u-3.1 marketstructure
Bsc agri 2 pae u-3.1 marketstructure
 
Bsc agri 2 pae u-3 perfect-competition
Bsc agri  2 pae  u-3 perfect-competitionBsc agri  2 pae  u-3 perfect-competition
Bsc agri 2 pae u-3 perfect-competition
 

Kürzlich hochgeladen

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 

Kürzlich hochgeladen (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 

function, storage class and array and strings

  • 2. ARRAYS An array is a group of related data items that share a common name. For instance, we can define array name salary to represent a set of salary of a group of employees. A particular value is indicated by writing a number called index number or subscript in brackets after the array name. Eg: salary[10]
  • 3. ONE DIMENSIONAL ARRAY  An array with a single subscript is known as one dimensional array.  Eg: 1) int number[5];  The values to array elements can be assigned as follows.  Eg: 1) number[0] = 35;  number[1] = 40;  number[2] = 20;
  • 4. Declaration of Arrays  The general form of array declaration is type variable-name[size]; The type specifies the type of element that will be contained in the array, such as int, float, or char and the size indicates the maximum number of elements that can be stored inside the array.
  • 5. Cont..  There is no convenient way to initialize only selected elements.  There is no shortcut method for initializing a large number of array elements like the one available in FORTRAN  Eg: 1) float height[50]; 2) int group[10]; 3)char name[10];
  • 6. Initialization of Arrays  The general form of initialization of arrays is: static type array-name[size] = {list of values}; Eg: static int number[3] = {0,0}; If the number of values in the list is less than the number of elements, then only that many elements will be initialized. The remaining elements will be set to zero automatically. Initialization of arrays in C suffers two drawbacks
  • 7. Cont..  We can use the word ‘static’ before type declaration. This declares the variable as a static variable.  Eg : 1) static int counter[] = {1,1,1}; 2) ……… ……… for(i =0; i < 100; i = i+1) { if i < 50 sum[i] = 0.0; else sum[i] = 1.0; } ………. ……….
  • 8. /*Program showing one-dimensional array*/ main() { int i; float x[10],value,total; printf(“Enter 10 real numbers:n”); for(i =0; i < 10; i++) { scanf(“%f”,&value); x[i] = value; } total = 0.0; for(i = 0; i < 10; i++) total = total + x[i] * x[i]; printf(“n”); for(i = 0; i < 10; i++) printf(“x[%2d] = %5.2f n”,i+1,x[i]); printf(“nTotal = %.2fn”,total); }  OUTPUT  Enter 10 real numbers:  1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10  x[1] = 1.10  x[2] = 2.20  x[3] = 3.30  x[4] = 4.40  x[5] = 5.50  x[6] = 6.60  x[7] = 7.70  x[8] = 8.80  x[9] = 9.90  x[10] = 10.10  Total = 446.86
  • 9. TWO-DIMENSIONAL ARRAYS  Two-dimensional arrays are declared as follows: type array-name[row_size][column_size]; Eg: product[i][j] = row * column;
  • 10. MULTIDIMENSIONAL ARRAY  C allows arrays of three or more dimensions. The exact limit is determined by the compiler.  The general form of a multidimensional array is type array_name[s1][s2][s3]…s[m];  Eg: 1. int survey[3][5][12]; 2. float table[5][4][5][3];
  • 11. String  A string is a array of characters. Any group of characters(except the double quote sign) defined between double quotation marks is a constant string.  Eg: 1) “Man is obviously made to think”  If we want to include a double quote in a string, then we may use it with the back slash.  Eg:  printf(“”well done!””);  will output  “well done!”
  • 12. Cont..  The operations that are performed on character strings are  Reading and writing strings.  Combining strings together.  Copying one string to another. Comparing strings for equality.  Extracting a portion of a string.
  • 13. DECLARING AND INITIALIZING STRING VARIABLES  A string variable is any valid C variable name and is always declared as an array.  The general form of declaration of a string variable is  char string_name[size];  Eg: char city[10]; char name[30];  When the compiler assigns a character string to a character array, it automatically supplies a null character (‘0’) at the end of the string.  Therefore, the size should be equal to the maximum number of characters in the string plus one. C permits a character array to be initialized in either of the following two forms:  static char city[9] = “NEW YORK”;  static char city[9] = {‘N’, ‘E’, ‘W’, ‘ ‘, ‘Y’, ‘O’, ‘R’, ‘K’, ‘0’};
  • 14. Cont..  Reading Words  The familiar input function scanf can be used with %s format specification to read in a string of characters.  Eg: char address[15]; scanf(“%s”,address);
  • 15. Program /*Reading a series of words using scanf function*/ main() { char word1[40],word2[40],word3[40], word4[40]; printf(“Enter text:n”); scanf(“%s %s”,word1, word2); scanf(“%s”, word3); scanf(“%s”,word4); printf(“n”); printf(“word1 = %s n word2 = %s n”,word1, word2); printf(“word3 = %s n word4 = %s n”,word3, word4); }  OUTPUT  Enter text:  Oxford Road, London M17ED  Word1 = Oxford  Word2 = Road  Word3 = London  Word4 = M17ED
  • 16. Reading a Line of Text  It is not possible to use scanf function to read a line containing more than one word.  This is because the scanf terminates reading as soon as a space is encountered in the input.  We can use the getchar function repeatedly to read single character from the terminal, using the function getchar.  Thus an entire line of text can be read and stored in an array.
  • 17. WRITING STRINGS TO SCREEN  We have used extensively the printf function with %s format to print strings to the screen.  The format %s can be used to display an array of characters that is terminated by the null character.  For eg, the statement  printf(“%s”, name);  can be used to display the entire contents of the array name.
  • 18. ARITHMETIC OPERATIONS ON CHARACTERS  C allows us to manipulate characters the same way we do with numbers.  Whenever a character constant or character variable is used in an expression, it is automatically converted into integer value by the system.  For eg, if the machine uses the ASCII representation, then, x = ‘a’; printf(“%d n”,x);  will display the number 97 on the screen.
  • 19. String Function  The C library supports a function that converts a string of digits into their integer values.  The function takes the form: x = atoi(string)
  • 20. PUTTING STRINGS TOGETHER Just as we cannot assign one string to another directly, we cannot join two strings together by the simple arithmetic addition. That is, the statements such as string3 = string1 + string2; string2 = string1 + “hello”; are not valid. The characters from string1 and string2 should be copied into string3 one after the other. The process of combining two strings together is called concatenation.
  • 21. COMPARISON OF TWO STRINGS  C does not permit the comparison of two strings directly. That is, the statements such as are not permitted. if(name1 == name2) if(name == “ABC”);  It is therefore necessary to compare the two strings to be tested, character by character.  The comparison is done until there is a mismatch or one of the strings terminate into a null character, whichever occurs first.
  • 22. STRING - HANDLING FUNCTIONS  C library supports a large number of string-handling functions that can be used to carry out many of the string manipulation activities. Following are the most commonly usedFunction Action  strcat( ) Concatenates two strings  strcmp( ) Compares two strings  strcpy( ) Copies one string over another  strlen( ) Finds the length of the string
  • 23. Cont..  strcat( ) Function  The strcat function joins two strings together.  It takes the following form  strcat( string1,string2);  Eg:  strcat(part1, “GOOD”);  strcat(strcat(string1,string2),string3);  Here three strings are concatenated and the result is stored in string1.
  • 24. Cont..  strcmp( ) Function  It is used to compare two strings identified by the arguments and has a value 0 if they are equal.  It takes the form:  Eg: 1) strcmp(name1,name2); 2) strcmp(name1,”john”; 3) strcmp(“ram”, “rom”);
  • 25. Cont..  strcpy( ) Function  This function works almost like a string assignment operator. It takes the form  strcpy(string1,string2);  This assigns the content of string2 to string1.  Eg: strcpy(city, “DELHI”); strcpy(city1,city2);
  • 26. Cont..  strlen( ) Function  This function counts and returns the number of characters in a string. n = strlen(string);
  • 27. Function  C functions can be classified into two categories, namely, library functions and userdefined functions.  Main is an example of user-defined functions, printf and scanf belong to the category of library functions.  The main difference between these two categories is that library functions are not required to be written by us whereas a user-defined function has to be developed by the user at the time of writing the program
  • 28. THE FORM OF C FUNCTIONS  Function-name(argument list) argument declaration; { local variable declarations; executable statement-1; executable statement-2; ……… ……… return(expression); }  A function that does nothing may not include any executable statements. For eg: do_nothing( ) { }
  • 30. RETURN VALUES AND THEIR TYPES  The return statement can take the form: return or return(expression);  Eg: if(x <= 0) return(0); else return(1);
  • 31. CALLING A FUNCTION  A function can be called by simply using the function name in the statement.  Eg: main() { int p; p = mul(10,5); printf(“%d n”, p); }  When the compiler executes a function call, the control is transferred to the function mul(x,y).  The function is then executed line by line as described and the value is returned,  when a return statement is encountered. This value is assigned to p.
  • 32. CATEGORY OF FUNCTIONS  A function may belong to one of the following categories. 1) Functions with no arguments and no return values. 2) Functions with arguments and no return values. 3) Functions with arguments and return values.
  • 33. NO ARGUMENTS AND NO RETURN VALUES  A function does not receive any data from the calling function. Similarly, it does not return any value.
  • 34. ARGUMENTS BUT NO RETURN VALUES  The nature of data communication between the calling function and the called function with arguments but no return values is shown in the diagram
  • 35. ARGUMENTS WITH RETURN VALUES  Here there is a two-way data communication between the calling and the called function. function1( ) { ---------- function2(a ) ---------- ---------- } function2(f ) --------- { --------- --------- return e; } function1( ) { ---------- function2(a ) ---------- ---------- } Values of Argument Function Results
  • 36. RECURSION  When a function in turn calls another function a process of ‘chaining’ occurs  The recursive function is  a kind of function that calls itself, or  a function that is part of a cycle in the sequence of function calls.  Recursion is a special case of this process, where a function calls itself. f1 f1 f2 fn…
  • 37. Cont. Eg: main() { printf(“Example for recursion”); main(); } This is follows from the format of a recursive definition as consisting of two parts: 1. Initialization –analogous to induction base cases 2. Recursion –analogous to induction step
  • 38. Cont.. A simple example of a recursively defined function is the factorial function: n! = 1· 2· 3· 4 ···(n –2)·(n –1)·n Fact=n*factorial(n-1); Fact=3*factorial(2); 2*factorial  Recursion is one way to decompose a task into smaller subtasks. At least one of the subtasks is a smaller example of the same task.  The smallest example of the same task has a non-recursive solution.
  • 39. Cont.. INITIALIZATION: 0!= 1 RECURSION: n != n · (n -1)! To compute the value of a recursive function, e.g. 5!, one plugs into the recursive definition obtaining expressions involving lower and lower values of the function, until arriving at the base case. recursion EG: 5! = 5 · 4! = 5 · 4 · 3! = 5 · 4 · 3 · 2!= 5 · 4 · 3 · 2 · 1! = 5 · 4 · 3 · 2 · 1 · 0! = 5 · 4 · 3 · 2 · 1 · 1 = 120
  • 40. FUNCTIONS WITH ARRAYS  To pass an array to a called function, it is sufficient to list the name of the array, without any subscripts, and the size of the array as arguments.  Eg: largest(a,n);
  • 41. Storage Class  A variable in C can have any one of the four storage classes. 1. Automatic variables. 2. External variables. 3. Static variables. 4. Register variables.
  • 42. AUTOMATIC VARIABLES (LOCAL/INTERNAL)  Automatic variables are declared inside a function in which they are to be utilized.  They are created when a function is called and destroyed automatically when the function is  exited.  Eg: main() { int number; --------- --------- }  We may also use the keyword auto to declare automatic variables explicitly.
  • 43. EXTERNAL VARIABLES  Variables that are both alive and active throughout the entire program are known as external variables.  They are also known as global variables Eg: int number; float length = 7.5;
  • 44. Cont.. main() { ------- ------- } function1( ) { ------- ------- } function2( ) { ------- ------- } The keyword extern can be used for explicit declarations of external variables.
  • 45. STATIC VARIABLES  As the name suggests, the value of a static variable persists until the end of the program.  A variable can be declared static using the keyword static.  Eg: 1) static int x; 2) static int y;
  • 46. REGISTER VARIABLES  We can tell the compiler that a variable should be kept in one of the machine’s registers, instead of keeping in the memory.  Since a register access is much faster than a memory access, keeping the frequently accessed variables in the register will lead to faster execution of programs.  This is done as follows: register int count;
  • 47. References: 1. Programming in C by yashwant kanitkar 2. ANSI C by E.balagurusamy- TMG publication 3. Computer programming and Utilization by sanjay shah Mahajan Publication 4. www.cprogramming.com/books.html 5. en.wikipedia.org/wiki/C_(programming_language) 6. www.programmingsimplified.com/c-program-example 7. http://cm.bell-labs.com/cm/cs/who/dmr/chist.html 8. http://en.wikipedia.org/wiki/datatypes in c language 9. http://en.wikipedia.org/wiki/List_of_C-based_programming_languages 10. http://en.wikipedia.org/wiki/C_(programming_language)