An array is a collection of similar elements.
one variable => Capable of storing multiple similar values.
int marks[90]; // integer array char name[20]; // character array or string float percentile[90]; // float array
Note:---
Array Index starts with 0.
1.Write a program to accept marks in 4 subjects by the user in an array and print them to the screen one by one.
2.Write a program to accept marks of 5 students in an array and print them to the screen one by one.
int a[3]={34,45,20}; arrays can be initialized while declaration
int arr[3] = {1,2,3}
1 integer = 4 bytes -- this is askable question.
this will reserve 4 x3 = 12 bytes.
A pointer can be incremented to point to the next memory location of that type.
Following operations can be performed on a pointer:-
- Addition of a number to a pointer.
- Substraction of a number from a pointer.
- Substraction of one pointer from another.
- Comparison of two pointer variables.
5. Try these operations on another variable by creating poitners in a seperate program. Demonstrate all the four operations.
if the pointer variable(pv) points to index 0, pv++ will point to index 1 & so on......
void printarray(int *ptr,int n) OR void printarray(int ptr[],int n)
An array can be of 2 dimension/3 dimension/n dimensions.
A 2 dimensional array can be defined as
int arr[3][2] = {{1,4}
{7,9}
{11,22}};
10.Create a 2-d array by taking input from the user.Write a display function to print the content of this 2-d array on the screen.
- Create an array of 10 numbers. Verify using pointer arithmetic that (ptr+2) points to the third element where ptr is a pointer pointing to the first element of the array.
- Write a program to create an array of 10 integers and store multiplication table of 5 in it.
- Repeat problem 2 for general input provided by the user using scanf.
- Write a program containing a function which reverses the array passed to it.
- Write a program containing functions which counts the number of positive integers in an array.
- Create an array of size 3x10 containing multiplication tables of the numbers 2,7 and 9 respectively.
- Repeat problem 7 for a custom input given.
- create a 3-D array and print the address of its elements in increasing order.
- create an array of size n, input the elements of the array, sum them and print the sum of the elements in a new line.