Search
 
SCRIPT & CODE EXAMPLE
 

CPP

passing structure to function in c++ example

#include <iostream>
using namespace std;

struct Person {
    char name[50];
    int age;
    float salary;
};

void displayData(Person);   // Function declaration

int main() {
    Person p;

    cout << "Enter Full name: ";
    cin.get(p.name, 50);
    cout << "Enter age: ";
    cin >> p.age;
    cout << "Enter salary: ";
    cin >> p.salary;

    // Function call with structure variable as an argument
    displayData(p);

    return 0;
}

void displayData(Person p) {
    cout << "
Displaying Information." << endl;
    cout << "Name: " << p.name << endl;
    cout <<"Age: " << p.age << endl;
    cout << "Salary: " << p.salary;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to format decimal palces in c++ 
Cpp :: c++ client service ros 
Cpp :: toupper c++ 
Cpp :: c++ print text 
Cpp :: define vector with size and value c++ 
Cpp :: c++ initialise array 
Cpp :: string number to integer number C++ 
Cpp :: c++ math 
Cpp :: prime number c++ 
Cpp :: standard template library in c++ 
Cpp :: il2cpp stuck unity 
Cpp :: how to make dictionary of numbers in c++ 
Cpp :: how to get euler constant in c++ 
Cpp :: C++ wchar_t 
Cpp :: C++ linked list iterator 
Cpp :: makefile for single cpp file 
Cpp :: what library is rand in c++ 
Cpp :: remove comments c++ 
Cpp :: c++ random int troll 
Cpp :: vectors in c++ 
Cpp :: files in c++ 
Cpp :: unordered map c++ 
Cpp :: C++ vector at() method 
Cpp :: nested conditional operator 
Cpp :: valid parentheses in cpp 
Cpp :: c++ unordered_map initialize new value 
Cpp :: && c++ 
Cpp :: std::enable_shared_from_this include 
Cpp :: enter items in array until enter is pressed c++ 
Cpp :: remove item from layout 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =