homework help

How Do I Hide a Data Member of a Structure in C Language?

by Sep 28, 2015Programming

C language is one of the most common programming languages to have excellent features. You can easily get that structure is used to declare complex data types. Here, distinctive data members are grouped in a single variable. A struct in C is public by default, and thus it is visible. If you use C++ to get a structure, then a struct is same as a class, but it is private and thus cannot be viewed. Now, how is it possible in C? An important factor is you cannot make any data private.

How to hide a data member in C language?

Some proper points you should know-

1. You should take steps very carefully to hide data.

2. There is no exact command that hides data in C. So, don’t search for those codes or functions that hide a data.

3. If you just want to show a part of the whole structure, then use APIs.

4. An “opaque” pointer in C is used to point out a structure of program internally. It means you can get this if it points to your API functions.

5. Thus, an exact structure is required for a positive result, but your each step must be accurate.

6. You can easily use FILE* pointer to access data members that you want to hide.

Thus, without a proper API function you are unable to hide data. The standard library has API function, and thus you can easily use it with an opaque pointer. But, without this function there is no other function to have the exact result. Now, you can easily understand that how much easy it is. But, as there is not specific instruction or program, so it is somehow difficult for the users to give it a proper structure. Along with this, a user can also get that “What are the coolest and/or funniest programming errors?”