JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: c++ language in hindi

C++ : Function With Array in hindi , what is function with array program example in c++ language

what is function with array program example in c++ language , C++ : Function With Array in hindi :-

इससे पहले के article मे  function को discuss किया गया है | इस article मे struture को  function के साथ कैसे use किया जाता है | function को array और string के साथ use करने एक method को इस article को discuss करेगे | 

Array 

Array एक एस data type जिसमे सामान  data type का समूह होता है | उदाह्रानो के लिए temperature एक array होता है | इसमें  temp एक array होता है जिसमे एक महीने के 10  दिनों के temperture का समूह है | array को declare करने के लिए निन्म syntax होता ही :-

array temp[10];

यहा पर temp array है और इसकी size ’10’ होती है क्योकि इनमे १ओ० value store होती है |

Array को  declare करने के बाद इस type के  array name को declare नहीं  किया जाता है | बल्कि  इस variable को प्रोग्राम मे use किया जाता है | इसका उदाहरन निन्म है :-

#include<iostream.h>

#include<conio.h>

void main()

{

int temp[10];

cout<<“Enter Temperature : “;

for(i=0;i<10;i++)

{

cin>>temp[i];

}

cout<<“Temperture for 10 Days :”;

for(i=0;i<10;i++)

{

cout<<temp[i];

}

getch();

}

इस उदाहरन मे , array temp [] की element को यूजर द्वारा input किया जाता है | अब इस element की value को display किया जाता है इसका आउटपुट होगा :

Enter Temperature : 12 13 14 15 22 43 23 32 34 21 

Temperture for 10 Days : 12 13 14 15 22 43 23 32 34 21 

Function with Array

जब किसी array को function मे pass किया जाता है  तब केवल array के नाम को function मे pass किया जाता है | जब इस function को define किया जाता है तब एक नए array को use करते है जिसमे pass array को इस array मे initial करते है | उदाहरन के लिए :

#include<iostream.h>

#include<conio.h>

void display (int temp[10])

void main()

{

int temp[10];

cout<<“Enter Temperature : “;

for(i=0;i<10;i++)

{

cin>>temp[i];

}

display(temp);

getch();

}

void display ( int t[10])

{

cout<<“Temperture for 10 Days :”;

for(i=0;i<10;i++)

{

cout<<t[i];

}

}

इस उदाहरन मे ,display() function को use किया जाता है | इस function से array की value को display किया जाता है | array variable को  display () पास्ड किया जाता है | और इस variable को function definition मे एक और variable ‘t’ मे initail किया जाता है |

इसका आउटपुट होगा :

Enter Temperature : 12 13 16 15 22 43 23 32 34 21 

Temperture for 10 Days : 12 13 16 15 22 43 23 32 34 21 

जब किसी array को function मे pass किया जाता है  तब struture को function नोरमल variable की तरह pass किया जाता है | और function मे array को भी नार्मल variable की तरह return किया जाता है | उदाहरन के लिए :

#include<iostream.h>

#include<conio.h>

void display (int temp[10]);

int input();

void main()

{

int o[10];

o=input();

display(temp);

getch();

}

void input()

{

int temp [10];

cout<<“Enter Temperature : “;

for(i=0;i<10;i++)

{

cin>>temp[i];

}

return temp ;

}

void display ( int t[10])

{

cout<<“Temperture for 10 Days :”;

for(i=0;i<10;i++)

{

cout<<t[i];

}

}

इस उदाहरन मे ,display()  और  input() function को use किया जाता है | function display() से array के element की  value को display किया जाता है | array को      function  display () पास्ड किया जाता है | और इस variable को function definition मे एक और variable ‘bt मे initail किया जाता है | और इसके बाद input() का use यूजर द्वारा input को लिया गया है |

Enter Publish Year : 1999

Enter Book Name : Tera Naam

Enter Price : 130

Book Details

Publish Year : 1999

Book Name : Tera Naam

Price : 130

इन उदाहरन के अलावा function मे array के दुसरे उदाहरन को consider करेगे : जिसमे  multi dimension array  को function मे  pass किया जाता है | इन उदाहरन मे multi dimension array मे operation को perform किया जाता ही | और बाद मे इस function को variable मे assign किया जाता है | और variable को display() मे pass किया जाता है |

#include<iostream.h>

#include<conio.h>

void display (int matrix[3][3]);

int input();

void main()

{

int o[3][3];

o=input();

display( o );

getch();

}

void input()

{

int m[3][3];

cout<<“Enter Matrix Element : “;

for(i=0;i<3;i++)

{

for(j=0;j,3;j++)

{

cin>>m[i][j];

}

}

return m ;

}

void display ( int matrix[10])

{

cout<<“Matrix :”;

for(i=0;i<3;i++)

{

for(j=0;j,3;j++)

{

cin<<mat[i][j];

}

}

}

इस उदाहरन मे ,display()  और  input() function को use किया जाता है | function display() से  multi dimension array को की value को display किया जाता है |  multi dimension array variable को  display () पास्ड किया जाता है | और इस variable को function definition मे एक और variable ‘m’ मे initail किया जाता है | और इसके बाद input() का use यूजर द्वारा input को लिया गया है |

इसका आउटपुट होगा :

Enter Matrix Element : 12 13 14 15 16 17 18 19 20 

Matrix :

12 13 14 

15 16 17

18 19 20

इस article मे   array  को function मे pass और return करने के method को discuss किया जाता है | अब age के article मे function को string को discuss करेगे |

Sbistudy

Recent Posts

सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है

सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…

10 hours ago

मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the

marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…

10 hours ago

राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi

sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…

2 days ago

गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi

gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…

2 days ago

Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन

वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…

3 months ago

polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten

get all types and chapters polity notes pdf in hindi for upsc , SSC ,…

3 months ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now