JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi sociology physics physical education maths english economics geography History

chemistry business studies biology accountancy political science

Class 12

Hindi physics physical education maths english economics

chemistry business studies biology accountancy Political science History sociology

Home science Geography

English medium Notes

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Class 12

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Categories: c++ language in hindi

C++ : Function with String in hindi , what is function with string program example in c++ language

what is function with string program example in c++ language , C++ : Function with String in hindi :-

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

String

string character का समूह होता है | string को use करने के लिए string class और chracter array को use किया जाता है | इसके लिए निन्म syntax होता है :

char a[];

ये syntax से character array को use किया जाता है |  इसमें character array को use करने के लिए cout और cin statement को use किया जाता है  | string class के function को use करने के लिए string.h header file को use किया जाता है | इसके लिए निन्म syntax को use किया जाता है |

string string_name ;

इस syntax मे data size को declare नहीं किया जाता है | string.cout() function और string.cin() function को string को read और write करने के लिए use किया जाता  है |

इसका उदाहरन निन्म है :-

#include<iostream.h>

#include<conio.h>

#include<string.h>

void main()

{

char first_name[20];

string last_name ;

cout<<“Enter First Name :”<<endl;

cin>>first_name;

cout<<“Enter Last Name :”<<endl;

string.cin(last_name);

cout<<“Name :”<<first_name last_name<<endl;

getch();

}

इस उदहारण मे ,first_name एक character array होता है | इसे read करने के लिए cout statement को use किया जाता है |  और last_name एक string variable है और string.cout() function को string variable को read करने के लिए use किया जाता है |

इसका आउटपुट होता है :-

Enter First Name : Parth

Enter Last Name : Patel

Name : Parth Patel

Function with string

जब किसी string को function मे pass किया जाता है  तब  string को function मे pass करने के लिए तीन method को use किया ह्जता है |

1.charaecter array को pass किया जाता है |

2.string lateral ये single quote मे क्लोज होता है इसे function मे pass किया जाता है |

3.pointer to char set को use किया जाता है इसमें string के address को use किया जाता है |

#include<iostream.h>

#include<conio.h>

int c_in(const char*s ,char c);

void main()

{

using namespace std;

char m[15]=”minimum”;

char *wait = “ululate”;

int_ms=c_in(m , ‘m’);

int_ms=c_in(wait, ‘u’);

cout<<ms<<“m character in “<<m<<endl;

cout<<ms<<“u character in “<<wail<<endl;

getch();

}

int c_in(const char*s ,char c)

{

int count = 0;

while(*s)

{

if(*s==c)

{

count++;

s++;

}

return count ;

}

इस उदाहरन मे  const keyword को use किया जाता है | const keyword को string variable को declare किया जाता है | string variable की जगह chracter array को use किया जाता है | syntax निन्म है :

int c_in(const char [] ,char c);

 इस उदहारण मे string pointer को भी use किया गया है | loop मे string variable ‘s’ को string variable ‘s’ मे assign किया गया है | और pointer variable को use किया जाता है |

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

3 m character in minimum

2 u character in ululate

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

#include<iostream.h>

#include<conio.h>

int stringlength ( string *s);

void main()

{

string name ;

cout<<“Enter Name :”;

cin>>name;

int length = stringlength ( &name ) ;

cout<<“Length :”<<length;

getch();

}

int stringlength ( string *s)

{

int count =o;

while(*s==’/0′)

{

count++;

}

return count ;

}

इस उदाहरन मे ,stringlength() function को use किया जाता है | function stringlength() से string की length को calculate किया जाता है | string variable को  stringlength () पास्ड किया जाता है | और इस variable को function definition मे एक और variable ‘s’ मे initail किया जाता है | और इसके बाद input() का use यूजर द्वारा input को लिया गया है |

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

Enter Name : Parth

Length : 5

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

#include<iostream.h>

#include<conio.h>

int input( string *s );

void display( string *o );

void main()

{

string  v;

v=input( string *s);

display(v);

getch();

}

void input( string *s )

{

cout<<“Enter Name : “;

string.cin(*s);

return s;

}

void display ( string *o )

{

cout<<“Name :”<<*o;

}

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

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

Enter Name : Parth

Name : Parth

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

Sbistudy

Recent Posts

four potential in hindi 4-potential electrodynamics चतुर्विम विभव किसे कहते हैं

चतुर्विम विभव (Four-Potential) हम जानते हैं कि एक निर्देश तंत्र में विद्युत क्षेत्र इसके सापेक्ष…

3 days ago

Relativistic Electrodynamics in hindi आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा

आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा Relativistic Electrodynamics in hindi ? अध्याय : आपेक्षिकीय विद्युतगतिकी…

5 days ago

pair production in hindi formula definition युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए

युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए pair production in hindi formula…

7 days ago

THRESHOLD REACTION ENERGY in hindi देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा

देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा THRESHOLD REACTION ENERGY in hindi…

7 days ago

elastic collision of two particles in hindi definition formula दो कणों की अप्रत्यास्थ टक्कर क्या है

दो कणों की अप्रत्यास्थ टक्कर क्या है elastic collision of two particles in hindi definition…

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