Anonymous array in C and C++
C
#include<stdio.h> void print(int n,const int arr[]) { int i; for(i=0;i<n;i++) { printf("%4d",arr[i]); } } int main() { printf("Elements of anonymous array :- "); print(5,(const int[]){12,33,42,56,89}); printf("\n\n"); return 0; }
CPP
#include<iostream> using namespace std; void print(int n,const int arr[]) { int i; for(i=0;i<n;i++) { cout<<" "<<arr[i]; } } int main() { cout<<"Elements of anonymous array :- "; print(10,(const int[]){12,33,42,89,56,23,20,90,56,89}); cout<<"\n\n"; return 0; }
Output :-
0 Comments