YouTube Icon

Interview Questions.

Top 100+ C And C++ Interview Questions And Answers - May 27, 2020

fluid

Top 100+ C And C++ Interview Questions And Answers

Question 1. What Is The Difference Between C And C++ ?

Answer :

C is a procedural language then again c++ is an item orientated language.
C follows top down technique, c++ follows backside up method.
C is a low stage language, c++ is a center stage language.
Input and putput functions differs within the  languages, c makes use of printf and scanf while c++ uses >> and << as input and output operators.
C++ can be broken down to solve real world problems which is not the case in c.
Question 2. What Is The Difference Between Declaration And Definition ?

Answer :

There are basically two differences between declaration and definition : 

In declaration no space is reserved for the variable, declaration only tells about the 'type' of the variable we are using or we will be using int he program.
Definition on the other hand reserves the sapce for the variable and some initial value is given to it.
Another major difference is that redeclaration is not an error whereas redefinition is an error,
In simple words, when we declare no space is reserved for the variable and we can redeclare it in the program
On the other hand, when we define a variable some sapce is reserved for it to hold values plus some initial value is also given to it, apart from it we cannot give another definition to the variable, i.E. We cannot define it again.
Example: 

extern int x -> is a assertion whereas int y is definition.

DBMS Interview Questions
Question three. If You Want To Share Several Functions Or Variables In Several Files Maintaining The Consistency How Would You Share It?

Answer :

To preserve the consistency between several files first of all place each definition in '.C' record than the usage of external declarations put it in '.H' file after it's miles blanketed .H report we will use it in numerous documents the usage of #consist of because it may be in one of the header files, accordingly to preserve the consistency we can make our very own header file and include it wherein ever wanted.

Question 4. What Do You Mean By Translation Unit?

Answer :

A Translation Unit is a hard and fast of source documents that is visible with the aid of the compiler and it translate it as one unit that is typically.Document and all the header documents cited in #include directives.

When a C preprocessor expands the supply report with all the header files the end result is the preprocessing translation unit which when further processed translates the preprocessing translation unit into translation unit, in addition with the assist of this translation unit compiler forms the item document and in the long run forms an executable application.

C++ Tutorial
Question 5. Describe Linkages And Types Of Linkages?

Answer :

When we claim identifiers inside the same scope or in the unique scopes they can be made to refer the same item or characteristic with the assist of likages. 

There are three forms of linkages: 

External linkage 
Internal linkage 
None linkage
EXternal Linkages manner 'global, non-static' capabilities or variable.

Example: extern int a1

Internal Linkages method static variable and features. Example: static int a2

None Linkages method neighborhood variables.

Example : int a3

C++ Interview Questions
Question 6. Keeping In Mind The Efficiency, Which One Between If-else And Switch Is More Efficient?

Answer :

Between if-else chain and switch statements, as a long way as efficiency is concerned it's far tough to mention that which one is more efficient because each of them posses rarely any difference in phrases of performance. 
Switch can ne transformed into if else chain internally through the compiler.
Switch statements are compact way of writting a leap table whereas if-else is a long way of writting situations.
Between if-esle and switch statements, switch instances are prefered to be used within the programming as it's miles a compact and purifier manner of writting situations within the application.
Question 7. What Are Structures And Unions?

Answer :

While handling real international problems we come upon situations when we need to apply exceptional records kind as one, C allows the user to outline it very own records kind called structures and unions.Structures and unions gathers collectively one-of-a-kind atoms of informations that comprise a given entity.

Java Tutorial C & Data Structures Interview Questions
Question 8. What Is The Difference Between Structures And Unions?

Answer :

Conceptually systems and unions are identical, the differnce between them lies of their 'Memory Management' or in simple words the reminiscence required through them.
Elements in structures are stored in contiguous blocks, in which as in unions the memory is allocated in this kind of way that the equal memory allotted for one variable serves as its memory at one occassion and as reminiscence for any other varioable at some different occassion. 
Therefore, the fundamental distinction lies within the manner mrmory is allotted to each systems and unions.
Question nine. What Do You Mean By Enumerated Data Type?

Answer :

Enumerated Data type facilitates the user in defining its own statistics type and additionally offers the person an opportunity to outline what values this type can take.

The use of Enumerated Data Type maily lie whilst this system get greater complicated or greater quantity of programers are workin on it as it makes this system listings greater readable.

Java Interview Questions
Question 10. What Are Preprocessor Directives In C?

Answer :

The Preprocessor techniques the source software before it's miles surpassed to the compiler. The functions that preprocessor offers are referred to as Prepsocessor Directives.

Preprocessing directives are strains for your software that begin with `#'. The `#' is accompanied by way of an identifier that is the directive call. For example, `#define' is the directive that defnes a macro. Whitespace is likewise allowed before and after the `#'. A preprocessing directive cannot be a couple of line in normal situations. Some directive names require arguments.View solutions in information

Go (programming language) Tutorial
Question 11. How C Functions Prevents Rework And Therefore Saves The Programmers Time As Well As Length Of The Code ?

Answer :

As we recognise that c permits us to make capabilities and cal them where ever wished, it prevents rework via calling the identical characteristic again and again where ever requires intead as an example if we make a funtion that adds two numbers, it could be referred to as anywhere in the program in which ever the addintion is needed and we do now not want to code once more for including any wide variety. 

It also shortens the length of the program as we do now not need to code again the identical element for next time we will easy call the funtion and use it on every occasion wanted.

Go (programming language) Interview Questions
Question 12. Keyword Mean In Declaration?

Answer :

This key-word indicated that the characteristic or the variable is implemented externally and it emphasizes that the variable ot the characteristic exits external to the document or function.

We use this keyword while we want to make anything global within the mission, it does now not lie inside any characteristic.

DBMS Interview Questions
Question 13. Can Union Be Self Referenced?

Answer :

No, Union can't be self referenced because it shares a unmarried memory for all of its information participants.View solutions in information

F Sharp (programming language) Tutorial
Question 14. Define Pointers?

Answer :

Pointes are unique kind of variables that are used to shop the reminiscence deal with of the opposite variables.
Pointers are declared normallt as different variables withe diffrence of * this is present in front of the pointer identifier.
There are  operators that are used with the tips one is '&' and some other one is '*'.
& is known as address of operator and * is referred to as dereferncing operator, each are prefix unary operators.
Question 15. Which Format Specifier Is Used For Printing A Pointer Value?

Answer :

%p is used to display the corresponding argument that could be a pointer.
%x can also be used to print values in hexadecimal form.
F Sharp (programming language) Interview Questions
Question sixteen. What Is The Use Of 'car' Keyword ?

Answer :

The car keyword declares a local variable whose scope stays inside the block of code, it is a variable with the neighborhood scope.
When we declare a variable with the auto keyword it specify that it belongs to an vehicle garage elegance.
These variables are seen simplest inside the bolck in which they may be declared.
These sorts of variables aren't initialised routinely alternatively need to be initialised xplicitly.
R Programming language Tutorial
Question 17. What Is The Use Of Register Keyword With The Variables?

Answer :

Register keyword signifies that of viable to shop variable within the sign in than shop it in sign in. 
Variables are usually saved in stacks and are exceeded backward and forward to processor each time required.
Also check in keyword while used redused code size that is an essential component in embeded device.
C preprocessor Interview Questions
Question 18. What Do You Mean By Global Variables?

Answer :

These are the variables which remains seen in the course of this system and are not recreated when they're recalled.

These types are with the aid of default initialised to zero and allocated memory on Data Segment.View solutions in information

C++ Interview Questions
Question 19. What Do You Mean By Static Variables?

Answer :

Static is an get entry to qualifier that limits the scope of the variable but reasons the variable to exist for the lifetime of this system. This method a static variable is one which isn't visible outdoor the function in which it is declared as its scopeis restricted to the block of code wherein it has been created but its lifespan remains until the program terminates.

The fee of the sort of variable will remain and can be visible even after calls to a function also the announcement assertion of such form of a variable interior a characteristic is finished simplest once.

D Programming Language Tutorial
Question 20. What Is The Difference Between Global Variables And Static Variables?

Answer :

The scope of the variable describes that the variable is out there at sure factor inside the software or not.
The distinction between international variables and static variables lies in this concept most effective. 
The scope of the global variables stays through out the program also the existence span of these variables is thru out the program.
The scope of the static Variables remains within the block of code in which they may be created but the life span remains through out this system.
Thus, the primary difference is among the scope of each form of variables.
R Programming language Interview Questions
Question 21. What Is The Difference Between Global Variables And Local Variable?

Answer :

First, Global variables are the variables which can be accessed from everywhere through out this system whereas neighborhood variables are the ones which could simplest be accessed within the block of code in which they're created.
Second, worldwide variables are seen at some point of the program whereas nearby variables are not known to the opposite capabilities in the applications i.E. They are seen in the block of code in which they're created.
Third, worldwide variables are allotted reminiscence on Data Segament whereas nearby variables are allocated memory on the stack.
Question 22. What Do You Mean By Volatile Variable?

Answer :

Variables prefixed with the key-word unstable acts as a data type qualifier. The unstable keyword tries to alter the default manner in which the variables are stored and the manner the compiler handles the variables.

It is a form of education to the optimizer to now not to optimize the varabli all through compilation.

Lua (programming language) Tutorial
Question 23. What Is The Prototype Of Printf Function?

Answer :

Prototype of printf function is:

int printf( const char *format ,?)

In this the Second parameter: '?' (Three non-stop dots) are known as known as ellipsis which indicates the variable number of arguments.

D Programming Language Interview Questions
Question 24. Define Macro?

Answer :

Macros are the identifiers that constitute statements or expressions in different phrases macros are fragment of code that is been given a name. #outline directive is used to dedine a macro.
Example, we've got define a macro i.E SQUARE(x) x*x. 
Here the macro determines the rectangular of the given variety. Macro Declaration: #define call text.
C & Data Structures Interview Questions
Question 25. What Is The Disadvantage Of Using A Macro?

Answer :

The important drawback related to the macro is :

When a macro is invoked no kind checking is performed.Therefore it's far important to declare a macro coreectly in order that it offers a accurate solution whenever it is called within the software.

Question 26. What Is A Void Pointer?

Answer :

When we claim a variable as a pointer to a variable of kind void, it's miles known as void pointer. Another name for it is widespread pointer.

In widespread we can't have a void type variable,however if the variable is of void type it do not factor to any data and because of this it can't be de-referenced.

Lua (programming language) Interview Questions
Question 27. What Is A Unnitialised Pointer?

Answer :

When we create a pointer the memory to the pointer is allocated however the contents or fee that reminiscence has to hold remains untouched. Unitialised tips are the ones recommendations which do not preserve any initial value.

Example: int *p; is said to be an unitialise pointer, it's miles recomended to initialise the pointer earlier than definitely the use of it as it an mistakes.

Java Interview Questions
Question 28. What Is Dangling Pointer?

Answer :

These are the tips that do not point to any object of suitable type. These are special cases of memory vialation as they do now not point to any appropraite kind.These arises when some item is deleted from the reminiscence or when an object is deallocated thus the pointer keeps on pointin to the reminiscence location untill it's far changed. Dangling guidelines may additionally cause unpredictable outcomes.

Question 29. What Do You Know About Near, Far And Huge Pointer?

Answer :

A near pointer is a sixteen bit pointer to an item that is contained inside the current section like code phase, data segment, stack phase and additional phase. It holds only offset address.
A a long way pointer is a 32 bit pointer to an item anywhere in reminiscence. It can handiest be used when the compiler allocates a segment check in, or we will say the compiler must allocate segment sign in to use far hints. These hints hold 16 bit section and sixteen bit offset deal with.
Huge recommendations also are a ways guidelines i.E. 32 bit pointer the distinction is that the huge pointer may be improved or reduced uniformly among any segments and might have any fee from 0 to 1MB.
Embedded C Interview Questions
Question 30. What Is Null Pointer?

Answer :

NULL pointer isn't the unitialised pointer that may point anywhere, the NULL recommendations are the only which do not factor everywhere that is which do now not point to any object or any characteristic.




CFG