Functions: Function Definition, prototyping, types of functions, passing arguments to functions, Nested Functions, Recursive functions.
Strings: Declaring and Initializing strings, Operations on strings, Arrays of strings, passing strings to functions. Storage Classes: Automatic, External, Static and Register Variables.
Functions: Function Definition, prototyping, types of functions, passing arguments to functions, Nested Functions, Recursive functions.
Strings: Declaring and Initializing strings, Operations on strings, Arrays of strings, passing strings to functions. Storage Classes: Automatic, External, Static and Register Variables.
An array is a group of data items of same data type that share a common name. Ordinary variables are capable of holding only one value at a time. If we want to store more than one value at a time in a single variable, we use arrays.
An array is a collective name given to a group of similar variables. Each member in the group is referred to by its position in the group.
Arrays are alloted the memory in a strictly contiguous fashion. The simplest array is a one-dimensional array which is a list of variables of same data type. An array of one-dimensional arrays is called a two-dimensional array.
COURSE TITLE: SOFTWARE DEVELOPMENT VI
COURSE CODE: VIT 351
TOPICS COVERED:
ARRAYS
TYPES OF ARRAYS
MULTIDIMENSIONAL ARRAYS
CHARACTER HANDLING IN C
STRING HANDLING IN C
QUIZ SET 2
Homework Assignment – Array Technical DocumentWrite a technical .pdfaroraopticals15
Homework Assignment – Array Technical Document
Write a technical document that describes the structure and use of arrays. The document should
be 3 to 5 pages and include an Introduction section, giving a brief synopsis of the document and
arrays, a Body section, describing arrays and giving an annotated example of their use as a
programming construct, and a conclusion to revisit important information about arrays described
in the Body of the document. Some suggested material to include:
Declaring arrays of various types
Array pointers
Printing and processing arrays
Sorting and searching arrays
Multidimensional arrays
Indexing arrays of various dimension
Array representation in memory by data type
Passing arrays as arguments
If you find any useful images on the Internet, you can use them as long as you cite the source in
end notes.
Solution
Array is a collection of variables of the same type that are referenced by a common name.
Specific elements or variables in the array are accessed by means of index into the array.
If taking about C, In C all arrays consist of contiguous memory locations. The lowest address
corresponds to the first element in the array while the largest address corresponds to the last
element in the array.
C supports both single and multi-dimensional arrays.
1) Single Dimension Arrays:-
Syntax:- type var_name[size];
where type is the type of each element in the array, var_name is any valid identifier, and size is
the number of elements in the array which has to be a constant value.
*Array always use zero as index to first element.
The valid indices for array above are 0 .. 4, i.e. 0 .. number of elements - 1
For Example :- To load an array with values 0 .. 99
int x[100] ;
int i ;
for ( i = 0; i < 100; i++ )
x[i] = i ;
To determine to size of an array at run time the sizeof operator is used. This returns the size in
bytes of its argument. The name of the array is given as the operand
size_of_array = sizeof ( array_name ) ;
2) Initialisg array:-
Arrays can be initialised at time of declaration in the following manner.
type array[ size ] = { value list };
For Example :-
int i[5] = {1, 2, 3, 4, 5 } ;
i[0] = 1, i[1] = 2, etc.
The size specification in the declaration may be omitted which causes the compiler to count the
number of elements in the value list and allocate appropriate storage.
For Example :- int i[ ] = { 1, 2, 3, 4, 5 } ;
3) Multidimensional array:-
Multidimensional arrays of any dimension are possible in C but in practice only two or three
dimensional arrays are workable. The most common multidimensional array is a two
dimensional array for example the computer display, board games, a mathematical matrix etc.
Syntax :type name [ rows ] [ columns ] ;
For Example :- 2D array of dimension 2 X 3.
int d[ 2 ] [ 3 ] ;
A two dimensional array is actually an array of arrays, in the above case an array of two integer
arrays (the rows) each with three elements, and is stored row-wise in memory.
For Example :- Program to fill .
An array is a group of data items of same data type that share a common name. Ordinary variables are capable of holding only one value at a time. If we want to store more than one value at a time in a single variable, we use arrays.
An array is a collective name given to a group of similar variables. Each member in the group is referred to by its position in the group.
Arrays are alloted the memory in a strictly contiguous fashion. The simplest array is a one-dimensional array which is a list of variables of same data type. An array of one-dimensional arrays is called a two-dimensional array.
COURSE TITLE: SOFTWARE DEVELOPMENT VI
COURSE CODE: VIT 351
TOPICS COVERED:
ARRAYS
TYPES OF ARRAYS
MULTIDIMENSIONAL ARRAYS
CHARACTER HANDLING IN C
STRING HANDLING IN C
QUIZ SET 2
Homework Assignment – Array Technical DocumentWrite a technical .pdfaroraopticals15
Homework Assignment – Array Technical Document
Write a technical document that describes the structure and use of arrays. The document should
be 3 to 5 pages and include an Introduction section, giving a brief synopsis of the document and
arrays, a Body section, describing arrays and giving an annotated example of their use as a
programming construct, and a conclusion to revisit important information about arrays described
in the Body of the document. Some suggested material to include:
Declaring arrays of various types
Array pointers
Printing and processing arrays
Sorting and searching arrays
Multidimensional arrays
Indexing arrays of various dimension
Array representation in memory by data type
Passing arrays as arguments
If you find any useful images on the Internet, you can use them as long as you cite the source in
end notes.
Solution
Array is a collection of variables of the same type that are referenced by a common name.
Specific elements or variables in the array are accessed by means of index into the array.
If taking about C, In C all arrays consist of contiguous memory locations. The lowest address
corresponds to the first element in the array while the largest address corresponds to the last
element in the array.
C supports both single and multi-dimensional arrays.
1) Single Dimension Arrays:-
Syntax:- type var_name[size];
where type is the type of each element in the array, var_name is any valid identifier, and size is
the number of elements in the array which has to be a constant value.
*Array always use zero as index to first element.
The valid indices for array above are 0 .. 4, i.e. 0 .. number of elements - 1
For Example :- To load an array with values 0 .. 99
int x[100] ;
int i ;
for ( i = 0; i < 100; i++ )
x[i] = i ;
To determine to size of an array at run time the sizeof operator is used. This returns the size in
bytes of its argument. The name of the array is given as the operand
size_of_array = sizeof ( array_name ) ;
2) Initialisg array:-
Arrays can be initialised at time of declaration in the following manner.
type array[ size ] = { value list };
For Example :-
int i[5] = {1, 2, 3, 4, 5 } ;
i[0] = 1, i[1] = 2, etc.
The size specification in the declaration may be omitted which causes the compiler to count the
number of elements in the value list and allocate appropriate storage.
For Example :- int i[ ] = { 1, 2, 3, 4, 5 } ;
3) Multidimensional array:-
Multidimensional arrays of any dimension are possible in C but in practice only two or three
dimensional arrays are workable. The most common multidimensional array is a two
dimensional array for example the computer display, board games, a mathematical matrix etc.
Syntax :type name [ rows ] [ columns ] ;
For Example :- 2D array of dimension 2 X 3.
int d[ 2 ] [ 3 ] ;
A two dimensional array is actually an array of arrays, in the above case an array of two integer
arrays (the rows) each with three elements, and is stored row-wise in memory.
For Example :- Program to fill .
2. C PROGRAMMING
Arrays
Arrays are used to store multiple values in a single variable, instead of
declaring separate variables for each value.
To create an array, define the data type (like int) and specify the name
of the array followed by square brackets [].
To insert values to it, use a comma-separated list, inside curly braces:
3. C PROGRAMMING
Syntax for declaring an array:-
dataType array_name[arraySize];
Example:- Declare an array
int student_marks[20];
char student_name[10];
float numbers[5];
Note:- After the declaration, size of the array cannot be changed.
4. C PROGRAMMING
Access elements of an array in C
In C, you can access the elements of the array using their index.
Suppose, you declare an array like below:-
If you want to access the first element of the above array then do
numbers[0] and if you want to access the second element then do
numbers[1] and so on.
The first index of the array is 0 not 1. That’s why numbers[0] is the first
element.
To access the last element of the array, do numbers[4].
numbers[0] numbers[1] numbers[2] numbers[3] numbers[4]
2 3 4 5 6
5. C PROGRAMMING
• Initialize an array:-
• At the time of declaration, it is possible to initialize an array.
• int numbers[5] = {2, 3, 4, 5, 6};
• You can also initialize an array like below:-
• int numbers[] = {2, 3, 4, 5, 6};
• In case, if you don’t specify the size of the array during initialization then the
compiler will know it automatically.
• numbers[0] = 2
• numbers[1] = 3
• numbers[2] = 4
• numbers[3] = 5
• numbers[4] = 6
6. C PROGRAMMING
Basic Example of an array:-
#include<stdio.h>
int main()
{
int numbers[5] = {2, 3, 4, 5, 6};
printf(" Basic Example of an array");
printf("First number is : %dn",numbers[0]);
printf("Third number is : %dn",numbers[2]);
printf("Last number is : %dn",numbers[4]);
}
7. C PROGRAMMING
Change the value of array elements:-
In C, you can also change the elements of the array after declaring it.
Example:- Changing the value of array elements
#include<stdio.h>
int main()
{
int numbers[5] = {2, 3, 4, 5, 6};
numbers[0] = 4; // changing value from 2 to 4!
numbers[2] = 5; // changing value from 4 to 5!
numbers[4] = 10; // changing value from 6 to 10!
printf("First number is : %dn",numbers[0]);
printf("Third number is : %dn",numbers[2]);
printf("Last number is : %dn",numbers[4]);
}
8. C PROGRAMMING
#include <stdio.h>
int main()
{
//Initialize array
int arr[5] = {1, 2, 3, 4, 5};
printf("Elements of given array: n");
//Loop through the array by incrementing value of i
for (int i = 0; i < =5; i++) {
printf("%d ", arr[i]);
}
9. #include <stdio.h>
int main() {
int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
int a;
for(a = 9; a >= 0; a--)
printf("%d ", array[a]);
return 0;
}
10. C PROGRAMMING
Arrays using functions :
#include <stdio.h>
void display(int age1, int age2) {
printf("%dn", age1);
printf("%dn", age2);}
int main() {
int ageArray[] = {2, 8, 4, 12};
// pass second and third elements to display()
display(ageArray[1], ageArray[2]);
return 0;
}