Top 30 C And C++ Interview Questions
Q1. What Is A Void Pointer?
When we claim a variable as a pointer to a variable of kind void, it's miles referred to as void pointer. Another call for it's far everyday pointer.
In wellknown we can not have a void type variable,but if the variable is of void type it do not factor to any statistics and because of this it can't be de-referenced.
Q2. What Do You Mean By Global Variables?
These are the variables which stays visible at some stage in this system and are not recreated while they're recalled.
These kinds are by default initialised to 0 and allocated reminiscence on Data Segment.View wers in details
Q3. What Do You Mean By Volatile Variable?
Variables prefixed with the key-word unstable acts as a statistics kind qualifier. The risky keyword tries to adjust the default manner in which the variables are stored and the way the compiler handles the variables.
It is a type of guidance to the optimizer to no longer to optimize the varabli throughout compilation.
Q4. What Is A Unnitialised Pointer?
When we create a pointer the memory to the pointer is allocated but the contents or price that memory has to hold stays untouched. Unitialised suggestions are those pointers which do not hold any preliminary cost.
Example: int *p; is said to be an unitialise pointer, it is recomended to initialise the pointer before genuinely the usage of it because it an mistakes.
Q5. What Do You Mean By Static Variables?
Static is an access qualifier that limits the scope of the variable but reasons the variable to exist for the lifetime of this system. This me a static variable is one which isn't seen outside the feature wherein it's far declared as its scopeis restricted to the block of code in which it has been created but its lifespan stays until the program terminates.
The price of such a variable will stay and can be visible even after calls to a function also the announcement statement of such kind of a variable interior a feature is performed best as soon as.
Q6. How C Functions Prevents Rework And Therefore Saves The Programmers Time As Well As Length Of The Code ?
As we know that c permits us to make features and cal them wherein ever wished, it prevents transform by using calling the identical characteristic again and again in which ever requires intead for example if we make a funtion that provides numbers, it could be referred to as everywhere within the application wherein ever the addintion is needed and we do not want to code again for adding any variety.
It additionally shortens the length of the program as we do not need to code again the same component for next time we will simple call the funtion and use it on every occasion wanted.
Q7. What Is The Prototype Of Printf Function?
Prototype of printf feature is:
int printf( const char *layout ,?)
In this the Second parameter: '?' (Three non-stop dots) are referred to as called ellipsis which shows the variable wide variety of arguments.
Q8. What Is The Difference Between Structures And Unions?
Conceptually systems and unions are identical, the differnce among them lies of their 'Memory Management' or in simple phrases the memory required with the aid of them.
Elements in structures are stored in contiguous blocks, in which as in unions the memory is allocated in one of these way that the equal memory allocated for one variable serves as its reminiscence at one occassion and as memory for some other varioable at some different occassion.
Therefore, the fundamental distinction lies within the manner mrmory is allocated to both systems and unions.
Q9. What Is The Difference Between C And C++ ?
C is a procedural language alternatively c++ is an item oriented language.
C follows pinnacle down method, c++ follows bottom up technique.
C is a low level language, c++ is a middle degree language.
Input and putput functions differs within the languages, c uses printf and scanf while c++ makes use of >> and << as input and output operators.
C++ can be broken down to solve real world problems which is not the case in c.
Q10. What Do You Know About Near, Far And Huge Pointer?
A near pointer is a 16 bit pointer to an object which is contained in the current segment like code segment, data segment, stack segment and extra segment. It holds only offset address.
A far pointer is a 32 bit pointer to an object anywhere in memory. It can only be used when the compiler allocates a segment register, or we can say the compiler must allocate segment register to use far pointers. These pointers hold 16 bit segment and 16 bit offset address.
Huge pointers are also far pointers i.E. 32 bit pointer the difference is that the huge pointer can be increased or decreased uniformly between any segments and can have any value from 0 to 1MB.
Q11. What Do You Mean By Enumerated Data Type?
Enumerated Data type helps the user in defining its own data type and also gives the user an opportunity to define what values this type can take.
The use of Enumerated Data Type maily lie when the program get more complicated or more number of programers are workin on it as it makes the program listings more readable.
Q12. What Is Dangling Pointer?
These are the pointers that do not point to any object of appropriate type. These are special cases of memory vialation as they do not point to any appropraite type.These arises when some object is deleted from the memory or when an object is deallocated thus the pointer keeps on pointin to the memory location untill it is modified. Dangling pointers may lead to unpredictable results.
Q13. Keyword Mean In Declaration?
This keyword indicated that the function or the variable is implemented externally and it emphasizes that the variable ot the function exits external to the file or function.
We use this keyword when we want to make anything global in the project, it does not lie within any function.
Q14. Keeping In Mind The Efficiency, Which One Between If-else And Switch Is More Efficient?
Between if-else chain and switch statements, as far as efficiency is concerned it is hard to say that which one is more efficient because both of them posses hardly any difference in terms of efficiency.
Switch can ne converted into if else chain internally by the compiler.
Switch statements are compact way of writting a jump table whereas if-else is a long way of writting conditions.
Between if-esle and switch statements, switch cases are prefered to be used in the programming as it is a compact and cleaner way of writting conditions in the program.
Q15. What Are Preprocessor Directives In C?
The Preprocessor processes the source program before it is passed to the compiler. The features that preprocessor offers are known as Prepsocessor Directives.
Preprocessing directives are lines in your program that start with `#'. The `#' is followed by an identifier that is the directive name. For example, `#define' is the directive that defnes a macro. Whitespace is also allowed before and after the `#'. A preprocessing directive cannot be more than one line in normal circumstances. Some directive names require arguments.View wers in details
Q16. What Is The Difference Between Declaration And Definition ?
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 announcement while int y is definition.
Q17. What Is The Difference Between Global Variables And Local Variable?
First, Global variables are the variables which may be accessed from everywhere through out this system while local variables are the ones which could simplest be accessed inside the block of code wherein they are created.
Second, worldwide variables are visible at some point of this system whereas neighborhood variables aren't acknowledged to the other functions in the packages i.E. They're visible within the block of code wherein they're created.
Third, international variables are allocated reminiscence on Data Segament while local variables are allotted memory at the stack.
Q18. What Is The Difference Between Global Variables And Static Variables?
The scope of the variable describes that the variable is out there at sure factor within the program or not.
The distinction between worldwide variables and static variables lies on this idea simplest.
The scope of the worldwide variables remains via out the program also the existence span of these variables is thru out the program.
The scope of the static Variables stays in the block of code wherein they're created however the lifestyles span remains through out this system.
Thus, the primary difference is between the scope of each sort of variables.
Q19. If You Want To Share Several Functions Or Variables In Several Files Maintaining The Consistency How Would You Share It?
To hold the consistency between several documents firstly place every definition in '.C' record than using external declarations placed it in '.H' record after it's miles covered .H report we are able to use it in numerous documents using #encompass because it might be in one of the header files, for that reason to hold the consistency we can make our personal header report and encompass it where ever needed.
Q20. Define Macro?
Macros are the identifiers that constitute statements or expressions in other phrases macros are fragment of code that is been given a name. #define directive is used to dedine a macro.
Example, we have outline a macro i.E SQUARE(x) x*x.
Here the macro determines the square of the given wide variety. Macro Declaration: #define name text.
Q21. Can Union Be Self Referenced?
No, Union can not be self referenced as it stocks a single reminiscence for all of its statistics members.View wers in details
Q22. What Do You Mean By Trlation Unit?
A Trlation Unit is a set of source files this is seen by the compiler and it trlate it as one unit that is commonly.Report and all of the header documents referred to in #include directives.
When a C preprocessor expands the supply report with all the header documents the end result is the preprocessing trlation unit which while similarly processed trlates the preprocessing trlation unit into trlation unit, in addition with the assist of this trlation unit compiler bureaucracy the object record and in the end bureaucracy an executable application.
Q23. What Is Null Pointer?
NULL pointer isn't always the unitialised pointer that may point anywhere, the NULL guidelines are the only which do now not factor anywhere that is which do not point to any object or any feature.
Q24. Which Format Specifier Is Used For Printing A Pointer Value?
%p is used to show the corresponding argument that may be a pointer.
%x also can be used to print values in hexadecimal form.
Q25. What Are Structures And Unions?
While managing real international problems we come upon situations whilst we want to apply specific information type as one, C lets in the consumer to define it own statistics kind known as systems and unions.Structures and unions gathers collectively special atoms of informations that comprise a given entity.
Q26. What Is The Use Of Register Keyword With The Variables?
Register key-word means that of possible to keep variable inside the sign in than store it in sign up.
Variables are commonly saved in stacks and are passed from side to side to processor on every occasion required.
Also register key-word whilst used redused code length that's an essential aspect in embeded machine.
Q27. Describe Linkages And Types Of Linkages?
When we claim identifiers within the identical scope or inside the distinctive scopes they can be made to refer the equal object or function with the assist of likages.
There are 3 varieties of linkages:
External linkage
Internal linkage
None linkage
EXternal Linkages me 'international, non-static' features or variable.
Example: extern int a1
Internal Linkages me static variable and functions. Example: static int a2
None Linkages me local variables.
Example : int a3
Q28. Define Pointers?
Pointes are special type of variables which can be used to shop the reminiscence address of the other variables.
Pointers are declared normallt as different variables withe diffrence of * this is present in front of the pointer identifier.
There are two operators which might be used with the guidelines one is '&' and another one is '*'.
& is referred to as address of operator and * is known as dereferncing operator, each are prefix unary operators.
Q29. What Is The Disadvantage Of Using A Macro?
The fundamental disadvantage related to the macro is :
When a macro is invoked no kind checking is carried out.Therefore it's far important to claim a macro coreectly in order that it offers a accurate wer on every occasion it's far referred to as inside the application.
Q30. What Is The Use Of 'vehicle' Keyword ?
The auto key-word broadcasts a neighborhood variable whose scope remains within the block of code, it's miles a variable with the local scope.
When we declare a variable with the car key-word it specify that it belongs to an car garage class.
These variables are visible only in the bolck wherein they're declared.
These forms of variables are not initialised routinely as a substitute want to be initialised xplicitly.

