answersLogoWhite

0


Best Answer

A private function can be either a nested function, but only if the compiler allows nested functions (ANSI C does not).

Or it can be a static global function. Static global functions are just like global functions, but they can only be used in the same module.

The naming convention requires that it's name begins with an underscore.

Global functions that are not static are public functions in C.

See:

[[http://groups.Google.hu/group/comp.lang.c/browse_thread/thread/8e65b8824709a760/a396eb5a4472a6f8?lnk=gst&q=private+function#a396eb5a4472a6f8]]

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

7y ago

The private and public keywords are two of the three base and member access specifiers. The third is protected.

  • Private members are only accessible to the class and friends of the class in which they are declared.
  • Protected members are the same as private but are also accessible to derivatives of the class in which they are declared and friends of those derivatives.
  • Public members are accessible from anywhere.
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are public and private functions in C?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Only public member functions can access public member data TrueFalse?

False. Public member data is accessible to all functions, whether they be public, protected or private members of the same class, or they are outside of the class completely.


Can private members of a class be inherited?

All fields and methods of a class are inherited: public class A {private int x =10;public int XVal{get{return x;}}} public class B:A {public B(){x = 20;}}


In c plus plus what is the purpose of the keyword public and private in the definition of a class?

Public members/functions can be accessed from outside the class, private members/functions can only be accessed from functions of that class. Ex. class sampleClass{ private int value; public void setValue(int a){value = a;} /* legal, value can be accessed since this is a method within the same class */ public int getValue(){return value;} }; int main() { sampleClass sc; // class is instantiated sc.setValue(5); // legal, setValue() is public sc.value = 7; // ERROR, value is private, will not compile printf("%d\n", sc.getValue()); // Will print 5 return 0; }


How can you access private functions of a class from the Main function in Cpp?

Any member functions and data members declared as 'private' in a class, can only be accessed directly by functions within the class.They cannot be accessed directly by derived objects, nor from anywhere outside an object of the class, such as from the Main function.To access private class members, you must rely on what are called accessor functions. Accessor functions are functions inside the class, either public or protected, which automatically have access to private members.If a function from Main, or elsewhere outside the class hierarchy, needs access, then you need to use publicaccessor functions. For derived class access, you can use protected accessor functions.


Which base class member functions are not inherited by a derived class?

Derived classes only inherit the protected and public members of their base classes. Private member functions cannot be inherited by a derived class.

Related questions

What if you declare public members rather than private in c plus plus?

Public members in C++ have accessibility to any function that has scope to the instance of the class, whereas private members have accessibility only to functions of that class.


Why private data members or functions are not inherited?

Because that's what private means. Private data members or functions are intended to be usable only in the base class, and the inheriting class can only access protected or public members or functions.


Only public member functions can access public member data TrueFalse?

False. Public member data is accessible to all functions, whether they be public, protected or private members of the same class, or they are outside of the class completely.


What do you mean by access specifier in c?

There are no access specifiers in C. All functions and data are public.


When class will be used and when structure will be used?

In class default members are private and in structure default members are public ,When ever you want to hide data from outside functions then you can use class.But in ANSI C we can hide data by using private access specifier.


Functions of public infrastructure?

Public infrastructure is infrastructure that is owned by the public or is for public use. It is generally distinguishable from private or generic infrastructure in terms of policy, financing, purpose.


What are the differences between public and private policy?

in C++/java if you want to perform data hiding(one of the concept of OOP's) you need to use Private. i.e. only functions in that class or object can use that. public can be used any where in the other program which is not a part of that class. Private classes are defined in order to increase the security, since in many situations there is no need for others to access the private attributes.


What is classes in programing?

There are no classes in C; it is not an object-oriented programming language. C++ has classes. A class is a data type from which objects can instantiated in much the same way that an integer variable can be instantiated from an int data type in both C and C++. However, an int is a primitive data type; it has no member methods associated with it. The built-in operators are designed to operate upon primitive data types but those operators are not integral to the type. A class is more like a struct in C; an aggregate of data values. A class can contain both static data (data that is common to the class) and non-static data (data that relates to an instance of the class). However, as well as storing data, a class can also define member functions that operate upon that data, but that are scoped to the class (static member functions) or to an instance of the class (instance member functions). Unlike C where a struct's data members are always public, a C++ class can define separate public, protected and private data members (and functions), where private is the default access. A C++ struct is also a class, but one where the members are public by default. As such, a C++ struct can be used to create trivial "plain old data" classes that are compatible with C code as well as to create highly complex data types. Objects are self-contained entities where the member methods (functions and operators) have private access to the class representation. Non-member functions cannot gain access to this representation other than through public member functions or by being declared a friend of the class. The protected representation is the same as the private representation but is also accessible to derivatives of the class. Derivatives automatically inherit the public and protected members of their base classes, but not the private members. This makes it possible to derive more specialised classes from existing classes without have to duplicate the base class code.


Are there other public functions that might benefit from more competition including competition from private?

The Post Office?


What is better private or public high school?

yes it is in public school if you get a B on a test in private you get a C so they have different scales.A honor class in public is a regular class in pravite.It is a proven fact that private school is much better then public school.


What is class in C programming?

There are no classes in C; it is not an object-oriented programming language. C++ has classes. A class is a data type from which objects can instantiated in much the same way that an integer variable can be instantiated from an int data type in both C and C++. However, an int is a primitive data type; it has no member methods associated with it. The built-in operators are designed to operate upon primitive data types but those operators are not integral to the type. A class is more like a struct in C; an aggregate of data values. A class can contain both static data (data that is common to the class) and non-static data (data that relates to an instance of the class). However, as well as storing data, a class can also define member functions that operate upon that data, but that are scoped to the class (static member functions) or to an instance of the class (instance member functions). Unlike C where a struct's data members are always public, a C++ class can define separate public, protected and private data members (and functions), where private is the default access. A C++ struct is also a class, but one where the members are public by default. As such, a C++ struct can be used to create trivial "plain old data" classes that are compatible with C code as well as to create highly complex data types. Objects are self-contained entities where the member methods (functions and operators) have private access to the class representation. Non-member functions cannot gain access to this representation other than through public member functions or by being declared a friend of the class. The protected representation is the same as the private representation but is also accessible to derivatives of the class. Derivatives automatically inherit the public and protected members of their base classes, but not the private members. This makes it possible to derive more specialised classes from existing classes without have to duplicate the base class code.


The fields in a c program are by default private is true or not?

I guess you mean C++, not C.Data fields of a structure/union are public by default,those of a class are private by default.