Write a C++ Program to demonstrate Passing String to a user defined function.

Program Code:


#include <iostream>
using namespace std;
// display() function declaration 
void display(char str[]);
// main() function definition
int main()
{    
char name[30];   
cout << "Enter your string: "; 
cin.get(name, 30); 
// user defined function display() calling 
display(name);   
return 0;
}


// user defined function display() definition
void display(char str[])
{  
cout << "Your entered string is : " ;
cout<< str;
cout<<endl;
}

The program output is tested on www.jdoodle.com

Output:
Enter your string: Mukesh Rajput
Your entered string is : Mukesh Rajput



Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: