answersLogoWhite

0


Best Answer

The default access specifier for a class is private. The default access specifier for a struct is public. It does not matter if it is a function or a variable.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Which is public to all access class or struct or function or variable?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is difference between struct variable and class object?

structure variable can access the variable but class object can access the function also


What is the difference between declaring variable and initializing variables?

Actually, there is a third step, call definition. Declaration is a statement to the compiler of what type an identifier is, definition is the allocation of memory for that identifier, and initialization is the assignment of an initial value to that identifier. Usually, declaration and definition are done together, but you can also add initialization in that step if desired. int a; /* declaration and definition */ a = 1; /* initialization */ int a = 1; /* declaration, definition, and initialization */ For the case of seperate declaration and definition, consider the struct... struct _mystruct { int a; }; /*declaration */ struct _mystruct mystruct; /* definition */ struct _mystruct { int a; } mystruct; /*declaration and definition */ Note: To be more precise: struct _mystruct; /* struct declaration */ struct _mystruct { int a; }; /* struct definition */ typedef struct _mystruct MYTYPE; /* type definition */ extern struct _mystruct mystructvar; /* variable declaration */ struct _mystruct mystructvar; /* variable definition */ struct _mystruct mystructvar = {7} ; /* variable definition with initialization */ struct _mystruct { int a; } mystruct; /* struct definition and variable definition */ extern struct _mystruct { int a; } mystruct; /* struct definition and variable declaration */


Demonstrate single inheritance in C plus plus?

struct base1 { // ... }; struct base2 { // ... }; struct derived1 : public base1 // single inheritance { // ... }; struct derived2 : public base1, public base2 // multiple inheritance { // ... };


How are the keywords struct and class different?

The keyword class is not a keyword in C. It is a keyword in C++, so I have added C++ to the category list for this question.The default access specifier for struct is public, while for class, it is private.Struct does not allow you to specify methods, while class does.A struct is not a class, and cannot be derived, while a class can be treated as a struct, if the scope and access is correct.


Which of the following is not a variable data type real integer number or string?

FILE, struct stat and struct tm are some examples.


Which data structure in a compiler is responsible for managing information about variables and their attributes?

It is up to the designer of the compiler to decide... it can be something like this: struct Type; struct Block; typedef struct Variable { const char *name; struct Type *type; struct Block *block; /* refers to the block that is the scope of the variable */ int attributes; /* volatile, const, static etc */ } Variable;


How do you access elements of array of structure in a function?

For example: struct { int fld; } v[2]; v[0].fld = 1;


What is meant by private access in c plus plus?

It isn't. Private is the default access for class members. For struct members, the default access is public. Aside from default access, a class and a struct serve the same purpose; to define a class. As such, the following class definitions are equivalent: class X { int a; }; struct Y { private: int b; }; Typically, we use a struct to define simple data types with trivial construction and use class for more complex data types, often to encapsulate an invariant or to acquire a resource, hiding the implementation details from consumers using private access.


What is a class in c plus plus how does it compare with structure in c?

A struct in C is a POD (plain old data) type. A class in C++ can also be a POD for backward compatibility with C code, but more typically combines data with methods that operate upon the data, including constructors and initialisers. Classes in C++ can be declared using either the struct or class keyword. By convention you will typically use struct to define POD data types and class to define more complex data types. The only practical difference between a struct and a class is that classes use private access and inheritance by default while struct uses public access and inheritance by default. Thus the following two class definitions are functionally the same: struct A { A():m_data(0) {} // public access by default private: int m_data; }; class B { int m_data; // private access by default public: B():m_data(0) {} };


What is typdef in c?

It is a keyword generally used to rename data types, using typedef you can create alias which can be used to declare the variable. e.g. typedef struct node { int info; struct node *next; }Node; now to declare variable of struct node type we can use the word Node in place of struct node


Is inheritance polymorphism possible in structure in c plus plus?

Yes. A C++ struct is exactly the same as a C++ class. The only difference is that struct members are public by default, whereas class members are private by default. Other than that, they work exactly the same way. Typically, you will use a struct when there is no need to encapsulate the data members (public access only), or when you need backward compatibility with C-style code. A C-style struct has only public data members (none of which can be a class of course, but may be another struct), but it has no methods whatsoever. Thus you need to disable the compiler-generated default and copy constructors, the destructor and the assignment operator. This is achieved by declaring them without a function body (no curly braces).


How is a structure type pointer variable declared?

struct thisorthat *ptr;