Skip to content

Instantly share code, notes, and snippets.

@manojnaidu619
Created June 25, 2019 14:11
Show Gist options
  • Save manojnaidu619/c73ade54af7c06cc85d68be127d45826 to your computer and use it in GitHub Desktop.
Save manojnaidu619/c73ade54af7c06cc85d68be127d45826 to your computer and use it in GitHub Desktop.
Different methods of passing Structures to Functions
#include <iostream>
using namespace std;
struct Queue{
int size;
int rear;
int front;
};
void passing_pointer(struct Queue *p){
cout << p->size << " ";
cout << p->rear << " ";
cout << p->front << " ";
}
void passing_struct(struct Queue p){
cout << p.size << " ";
cout << p.rear << " ";
cout << p.front << " ";
}
int main(){
struct Queue q; // q is a Structure Object
q.size = 10;
q.rear = 20;
q.front = 30;
passing_pointer(&q); // Passing the address (Call by address)
cout << endl;
passing_struct(q); // Passing the value (Call by value)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment