JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

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

Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic

Question Tag Definition • A question tag is a small question at the end of a…

1 week ago

Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)

Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…

1 week ago

Report Writing examples in english grammer How to Write Reports explain Exercise

Report Writing • How to Write Reports • Just as no definite rules can be laid down…

1 week ago

Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th

Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…

1 week ago

विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features

continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…

1 week ago

भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC

भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…

1 week 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