Created
June 25, 2019 14:11
-
-
Save manojnaidu619/c73ade54af7c06cc85d68be127d45826 to your computer and use it in GitHub Desktop.
Different methods of passing Structures to Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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