Following is the simple program for sum using structure.
I am facing a problem when I declare structure variable "dd" outside of main with structure then the programme works but if declared within main, it does not . Can anyone tell me why it is so ?Code:#include<iostream> #include<string.h> using namespace std; struct ab { int x,y; }dd; void sum() { cin>> dd.x>>dd.y; int z= dd.x + dd.y; cout<<z; } int main() { sum(); return 0; }