3 Questions On C Vs C++ Differences

C++ as everyone knows has evolved from C and retains several features of C. However, there are several differences some of which are very prominent and others which often go unnoticed unless otherwise you get a compilation error. Below are three questions for your practice. Though you may not exact similar questions on placement papers/interviews, reading these types of questions will help to improve your understanding and make you stay prepared to tackle the conventional questions very comfortably.

Question 1

In terms of syntax, what is a simple difference between struct declarations between C and C++ ?

Answer :

In C it is always necessary to include 'struct' keyword while declaring, but you could skip the 'struct' keyword in C++.

Example,

In C++ : struct_name struct_instance;
In C : struct struct_name struct_instance;

Question 2

State which of the following statements are true.

a) Boolean data type is native in both C and C++
b) Boolean data type is not a fundamental data type in C and C++,
c) C++ has boolean data type as a native data type while in C it is not present.

Answer :

c) C++ has boolean data type as a native data type while in C it is not present.

Boolean is not available in C as a fundamental data type. However this can be simulated using enum.

Question 3

Which of the following is true regarding exception handling in C and C++ ?

a) There is no exception handling in C whereas it exists in C++
b) Function return codes can report errors in C while try catch blocks can be used in C++
c) With advanced libraries try catch blocks can be used in both C and C++

Answer :

b) Function return codes can report errors in C while try catch blocks can be used in C++

(The above answer is self explanatory.)

Post a Comment

Please Select Embedded Mode To Show The Comment System.*

Previous Post Next Post