-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray&function.cpp
More file actions
51 lines (48 loc) · 1.04 KB
/
array&function.cpp
File metadata and controls
51 lines (48 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* how the fuction call is done*/
#include<iostream>
using namespace std;
void print(){
cout<<"you called the fuction rightly";
}
int main(){
print();
return 0;
}
/*arrays are always passed as pointers to the function.*/
/*we majorly pass array in three ways in the fuction
1. passing array as pointer
2 passing array as an unsized array
3 passing array as a sized array*/
#include<iostream>
using namespace std;
void unsizedArray(int arr[],int n){
cout<<"the array is";
for (int i=0;i<n;++i){
cout<<*(arr+i)<<" " ;
}
cout<<endl;
}
void sizedArray(int arr[3],int n){
cout<<"th array is";
for (int i=0;i<=n;i++){
cout<<arr[i]<<" ";
}
cout<<endl;
}
void pointerArray(int *ptr,int n){
cout<<"the array using pointer is";
for(int i=0;i<=n;i++){
cout<<ptr[i]<<" ";
}
}
int main(){
int arr[]={1,2,3};
unsizedArray(arr,2);
sizedArray(arr,2);
pointerArray(arr,2);
return 0;
}
/*o/p
the array is 1 2 3
the array is 1 2 3
the array using pointer is 1 2 3 */