What is private and public in c++? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is private and public in c++?

What is private and public in c++? in c++ we'll use the term private and public and in Python we'll use global variable and local variable so are they both same?

13th Oct 2018, 2:19 PM
Sainath Dora
4 Answers
+ 1
Global means every scope can access it. local means only the scope where it's declared can access it. global and local aren't the same as public and private because public and private only applies to classes or structs while global and local are for functions and variables. Other than that, they're pretty similar.
13th Oct 2018, 2:59 PM
qwerty
qwerty - avatar
+ 1
private means only the class scope can access it. public means you can access it in any scope (if you have an instance of it).
13th Oct 2018, 2:52 PM
qwerty
qwerty - avatar
+ 1
A block of code. a scope is surrounded between curly brackets (in C++).
13th Oct 2018, 2:54 PM
qwerty
qwerty - avatar
0
what do u mean by scope?
13th Oct 2018, 2:53 PM
Sainath Dora