N
Neo
I wrote the following code to learn about structs(ok I know classes are
better) but I couldnt understand why the mystruct declaration and the
functions getval and display have to be before main(). I got compile
errors when I declared them in main() function. why not after main() as
I feel thay are similar to variable declarations. please let me know:
other than preprocessor commands and globals, whats the rule for things
appearing before main() and after main() ??
---------code------------------------------------------------
#include <iostream>
using namespace std;
typedef struct mystruct {
int i;
char c;
} ic_struct;
void getval (ic_struct* a, int b, char c) {
a->i= b;
a->c= c;
}
void display (ic_struct* x) {
cout << "x.i value= " << x->i << endl \
<< "x.c value= " << x->c << endl;
}
int main () {
ic_struct st1;
ic_struct* p_st1 = &st1;
getval(p_st1, 3, 'q');
display(p_st1);
return 0;
}
better) but I couldnt understand why the mystruct declaration and the
functions getval and display have to be before main(). I got compile
errors when I declared them in main() function. why not after main() as
I feel thay are similar to variable declarations. please let me know:
other than preprocessor commands and globals, whats the rule for things
appearing before main() and after main() ??
---------code------------------------------------------------
#include <iostream>
using namespace std;
typedef struct mystruct {
int i;
char c;
} ic_struct;
void getval (ic_struct* a, int b, char c) {
a->i= b;
a->c= c;
}
void display (ic_struct* x) {
cout << "x.i value= " << x->i << endl \
<< "x.c value= " << x->c << endl;
}
int main () {
ic_struct st1;
ic_struct* p_st1 = &st1;
getval(p_st1, 3, 'q');
display(p_st1);
return 0;
}