What's the difference between struct in 1.c and c++? Answer: C has no Protection behavior and can not define functions, but can have function pointers. C++ has Protection behavior, default is public; functions can be defined. What's the difference between struct and class in 2.c++? Answer: Grammatically speaking, there are only two differences between class and struct when defining a type: 1 > Default inheritance permissions.If not specified explicitly, the inheritance from class is treated as private inheritance, and the inheritance from struct is treated as public inheritance. 2 > Default access rights for members.Class members default to private permissions, and struct defaults to public permissions. Apart from these two points, class and struct are basically one thing.There is no other difference in grammar. 3.How to judge whether a program is compiled by C compiler or c+ + compiler Answer: There is a macro to judge. # ifdef__cplusplus Cout < < "c++"; #else Cout < < "c"; #endif What's the difference between 4.c and c++? Answer: From the mechanism: C is process-oriented (but C can also write object-oriented programs); c++ is object-oriented, providing classes.However, it is easier to write object-oriented programs in c+ + than in c+. From the applicable direction: C is suitable for situations requiring small code size and high efficiency, such as embedded, C + + is suitable for higher level and complex; most of the Linux core is written in c, because it is system software, the efficiency requirements are very high. It can also be seen from the name that c++ is more than c+, which indicates that c++ is a superset of C. Why not call c++ instead of c++? Because c++ has too many extensions than c+, so we put two++ after c, so it becomes c++. C language is a structured programming language and C + + is an object-oriented programming language C + + focuses on objects rather than processes, and on class design rather than logical design. 5.What is the difference between "reference" and pointer? Answer: When a pointer points to an object through a pointer variable, it indirectly operates on the variable it points to.The use of pointers in the program makes the readability of the program poor. The reference itself is an alias of the target variable. The operation of the reference is the operation of the target variable. 6. ClassA {virtual void func1 (); void func2 ();} ClassB: class A {void func1 (){cout < < "fun1 in class b"} endl;} virtual void func2 () {cout < < "fun2 in class B"> endl;} Func1 in A and func2 in B are imaginary functions. 7. int ID [sizeof (unsigned long)]; is that right?Why? Answer: Right; this sizeof is a compile-time operator, which is determined at compile time and can be regarded as a machinerelated constant. 8.What is the scope of action of a static global variable (or static external variable) defined in a file? A: This document.Static global variables limit their scope, that is, they are valid only in the source file that defines the variable and cannot be used in other source files of the same source program.Because the scope of static global variables is limited to one source file and can only be shared by functions in that source file, errors in other source files can be avoided. What are the ways to transfer the median of 9.c++ functions? Answer: The three transfer modes of c++ function are: value transfer, pointer transfer and reference transfer. 10.For a frequently used short function, what is the implementation in C language and what is the implementation in C++? Answer: C is defined by macro, c++ by inline 11.What's the difference between a reference and a pointer? Answer: 1 > References must be initialized without pointers 2 > References cannot be changed after initialization (c++ 11 can be changed), and pointers can change the object they refer to 3 > There is no reference to null values, but there is a pointer to null values. What are the meanings of virtual and inline in 12.c++? Answer: Adding virtual keyword before the declaration of the base class member function means that the member function is declared as a virtual function.Inline is put together with the definition body of a function, so that the function is called inline.Inline is a keyword for implementation, not for declaration. The feature of virtual functions is that if you want derived classes to redefine the methods of base classes, you define them as virtual methods in base classes, which enables
C and C + + interview questions
Tips: Current document can only be previewed at most page8,If the total number of pages in the document exceeds page 8,please download the document。
Uploaded by admin on 2019-10-14 00:56:24