adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Anonymous array in C and C++


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 :-




Post a Comment

0 Comments