26-08-2017, 03:45 PM
What are the differences between C and C ++?
1) C ++ is a superset type of C, most C programs except few exceptions (see this and this) work in C ++ as well.
2) C is a procedural programming language, but C ++ supports both procedural programming and object programming.
3) Since C ++ supports object-oriented programming, it supports functions such as overloading functions, templates, inheritance, virtual functions, friend functions. These characteristics are absent in C.
4) C ++ supports exception handling at the language level, while handling C exceptions is done in the traditional if-else style.
5) C ++ supports references, C does not.
6) In C, scanf () and printf () are mainly used as input / output. C ++ mainly uses flows to perform input and output operations. cin is standard input flow and cout is standard output flow.
There are many more differences, above is a list of major differences.
What are the differences between references and pointers?
Both references and pointers can be used to change the local variables of a function within another function. Both can also be used to save copies of large objects when passed as arguments to functions or returned from functions for efficiency gains.
Despite the previous similarities, there are the following differences between references and pointers.
References are less powerful than pointers
1) Once a reference is created, you can not refer to another object later; It can not be reseated. This is often done with pointers.
2) References can not be NULL. Pointers are often made NULL to indicate that they are not pointing at anything valid.
3) A reference must be initialized when it is declared. There is no such restriction with pointers
Because of the above limitations, references in C ++ can not be used to implement data structures such as Linked List, Tree, etc. In Java, references have no previous constraints and can be used to implement all data structures. References being more powerful in Java, is the main reason why Java does not need pointers.
References are safer and easier to use:
1) Safer: Since references need to be initialized, wild references like wild pointers are unlikely to exist. It is still possible to have references that do not refer to a valid place (see questions 5 and 6 in the following exercise)
2) Easier to use: References do not need dereferencing operator to access the value. They can be used as normal variables. The '&' operator is only needed at the time of the declaration. You can also access members of an object reference with the dot operator ('.'), Unlike pointers where the arrow operator (->) is required to access members.
1) C ++ is a superset type of C, most C programs except few exceptions (see this and this) work in C ++ as well.
2) C is a procedural programming language, but C ++ supports both procedural programming and object programming.
3) Since C ++ supports object-oriented programming, it supports functions such as overloading functions, templates, inheritance, virtual functions, friend functions. These characteristics are absent in C.
4) C ++ supports exception handling at the language level, while handling C exceptions is done in the traditional if-else style.
5) C ++ supports references, C does not.
6) In C, scanf () and printf () are mainly used as input / output. C ++ mainly uses flows to perform input and output operations. cin is standard input flow and cout is standard output flow.
There are many more differences, above is a list of major differences.
What are the differences between references and pointers?
Both references and pointers can be used to change the local variables of a function within another function. Both can also be used to save copies of large objects when passed as arguments to functions or returned from functions for efficiency gains.
Despite the previous similarities, there are the following differences between references and pointers.
References are less powerful than pointers
1) Once a reference is created, you can not refer to another object later; It can not be reseated. This is often done with pointers.
2) References can not be NULL. Pointers are often made NULL to indicate that they are not pointing at anything valid.
3) A reference must be initialized when it is declared. There is no such restriction with pointers
Because of the above limitations, references in C ++ can not be used to implement data structures such as Linked List, Tree, etc. In Java, references have no previous constraints and can be used to implement all data structures. References being more powerful in Java, is the main reason why Java does not need pointers.
References are safer and easier to use:
1) Safer: Since references need to be initialized, wild references like wild pointers are unlikely to exist. It is still possible to have references that do not refer to a valid place (see questions 5 and 6 in the following exercise)
2) Easier to use: References do not need dereferencing operator to access the value. They can be used as normal variables. The '&' operator is only needed at the time of the declaration. You can also access members of an object reference with the dot operator ('.'), Unlike pointers where the arrow operator (->) is required to access members.