![]() |
|
#1
|
|||
|
|||
'stuct' instead of just 'int'Recently I had following test question:
Why would one ever write: struct S { int x; } instead of just “int” ? E.g. “void Foo(S);” or “S Bar(S);” instead of: “void Foo(int);” or “int Bar(int)” Do you have some ideas? Thanks. |
|
#2
|
|||
|
|||
|
Doing this can increase code readability. Say you've a program that does arithmetic on vectors and matrices. Being a clever coder, you use dynamically allocated memory, and use pointers to access. But a pointer to a vector will look identical to a matrix. A function multiplying 2 matrices gives a matrix, but matrix by a vector gives a vector.
So the code would be like: CPP / C++ / C Code:
CPP / C++ / C Code:
GF |
Recent GIDBlog
Writing a book by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The