C and C++ Interview Questions & Answers

C and C++ Interview Questions

Have you prepared to attend the job interview? Are you confused in job research? Then no problem we have the right answer to you in in our Wisdomjobs site page. If you are aware with the C and C++ Interview Questions then there are numerous leading companies that offer job roles like Software Developer, Developer / Sr. Developer, System Analyst, Optimizer Feature Developer many other leading roles too. If you are preparing for C and C++ Interview Questions interview and don’t know how to crack interview and what level or difficulty of questions to be asked in job interviews then go through C and C++ Interview Questions page to crack your job interview. Underneath are the commonly asked C and C++ Interview Questions and answers and C and C++ Interview Questions jobs role which can make you feel relaxed to face the interviews:

C And C++ Interview Questions And Answers

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

      Answer :

      • C is a procedural language on the other hand c++ is an object oriented language.
      • C follows top down approach, c++ follows bottom up approach.
      • C is a low level language, c++ is a middle level language.
      • Input and putput functions differs in the two languages, c uses printf and scanf whereas 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.

    2. 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.


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

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

      Answer :

      To maintain the consistency between several files firstly place each definition in '.c' file than using external declarations put it in '.h' file after it is included .h file we can use it in several files using #include as it will be in one of the header files, thus to maintain the consistency we can make our own header file and include it where ever needed.

    4. Question 4. What Do You Mean By Translation Unit?

      Answer :

      A Translation Unit is a set of source files that is seen by the compiler and it translate it as one unit which is generally.file and all the header files mentioned in #include directives.

      When a C preprocessor expands the source file with all the header files the result is the preprocessing translation unit which when further processed translates the preprocessing translation unit into translation unit, further with the help of this translation unit compiler forms the object file and ultimately forms an executable program.

    5. Question 5. Describe Linkages And Types Of Linkages?

      Answer :

      When we declare identifiers within the same scope or in the different scopes they can be made to refer the same object or function with the help of likages. 

      There are three types of linkages: 

      • External linkage 
      • Internal linkage 
      • None linkage

      EXternal Linkages means 'global, non-static' functions or variable.

      Example: extern int a1

      Internal Linkages means static variable and functions. Example: static int a2

      None Linkages means local variables.

      Example : int a3

    6. 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 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.

    7. Question 7. What Are Structures And Unions?

      Answer :

      While handling real world problems we come across situations when we want to use different data type as one, C allows the user to define it own data type known as structures and unions.Structures and unions gathers together different atoms of informations that comprise a given entity.

    8. Question 8. What Is The Difference Between Structures And Unions?

      Answer :

      • Conceptually structures and unions are same, the differnce between them lies in their 'Memory Management' or in simple words the memory required by them.
      • Elements in structures are stored in contiguous blocks, where as in unions the memory is allocated in such a way that the same memory allocated for one variable serves as its memory at one occassion and as memory for another varioable at some other occassion. 
      • Therefore, the basic difference lies in the way mrmory is allocated to both structures and unions.

    9. Question 9. What Do You Mean By Enumerated Data Type?

      Answer :

      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.

    10. Question 10. What Are Preprocessor Directives In C?

      Answer :

      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 answers in details

    11. Question 11. How C Functions Prevents Rework And Therefore Saves The Programmers Time As Well As Length Of The Code ?

      Answer :

      As we know that c allows us to make functions and cal them where ever needed, it prevents rework by calling the same function again and again where ever requires intead for example if we make a funtion that adds two numbers, it can be called anywhere in the program where ever the addintion is needed and we do not need to code again for adding any number. 

      It also shortens the length of the program as we do not need to code again the same thing for next time we can simple call the funtion and use it whenever needed.

    12. Question 12. Keyword Mean In Declaration?

      Answer :

      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.

    13. Question 13. Can Union Be Self Referenced?

      Answer :

      No, Union cannot be self referenced because it shares a single memory for all of its data members.View answers in details

    14. Question 14. Define Pointers?

      Answer :

      • Pointes are special type of variables that are used to store the memory address of the other variables.
      • Pointers are declared normallt as other variables withe diffrence of * that is present in front of the pointer identifier.
      • There are two operators that are used with the pointers one is '&' and another one is '*'.
      • & is known as address of operator and * is known as dereferncing operator, both are prefix unary operators.

    15. Question 15. Which Format Specifier Is Used For Printing A Pointer Value?

      Answer :

      • %p is used to display the corresponding argument that is a pointer.
      • %x can also be used to print values in hexadecimal form.

    16. Question 16. What Is The Use Of 'auto' Keyword ?

      Answer :

      • The auto keyword declares a local variable whose scope remains within the block of code, it is a variable with the local scope.
      • When we declare a variable with the auto keyword it specify that it belongs to an auto storage class.
      • These variables are visible only within the bolck in which they are declared.
      • These types of variables are not initialised automatically instead need to be initialised xplicitly.

    17. Question 17. What Is The Use Of Register Keyword With The Variables?

      Answer :

      • Register keyword signifies that of possible to store variable in the register than store it in register. 
      • Variables are usually stored in stacks and are passed to and fro to processor whenever required.
      • Also register keyword when used redused code size which is an important thing in embeded system.

    18. Question 18. What Do You Mean By Global Variables?

      Answer :

      These are the variables which remains visible throughout the program and are not recreated when they are recalled.

      These types are by default initialised to zero and allocated memory on Data Segment.View answers in details

    19. Question 19. What Do You Mean By Static Variables?

      Answer :

      Static is an access qualifier that limits the scope of the variable but causes the variable to exist for the lifetime of the program. This means a static variable is one that is not seen outside the function in which it is declared as its scopeis limited to the block of code in which it has been created but its lifespan remains until the program terminates.

      The value of such a variable will remain and may be seen even after calls to a function also the declaration statement of such type of a variable inside a function is executed only once.

    20. Question 20. What Is The Difference Between Global Variables And Static Variables?

      Answer :

      • The scope of the variable describes that the variable is accessible at certain point in the program or not.
      • The difference between global variables and static variables lies in this concept only. 
      • The scope of the global variables remains through out the program also the life span of these variables is through out the program.
      • The scope of the static Variables remains within the block of code in which they are created but the life span remains through out the program.
      • Thus, the main difference is between the scope of both type of variables.

    21. Question 21. What Is The Difference Between Global Variables And Local Variable?

      Answer :

      • First, Global variables are the variables which can be accessed from anywhere through out the program whereas local variables are those which can only be accessed within the block of code in which they are created.
      • Second, global variables are visible throughout the program whereas local variables are not known to the other functions in the programs i.e. they are visible within the block of code in which they are created.
      • Third, global variables are allocated memory on Data Segament whereas local variables are allocated memory on the stack.

    22. Question 22. What Do You Mean By Volatile Variable?

      Answer :

      Variables prefixed with the keyword volatile acts as a data type qualifier. The volatile keyword attempts to alter the default way in which the variables are stored and the way the compiler handles the variables.

      It is a kind of instruction to the optimizer to not to optimize the varabli during compilation.

    23. 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 continuous dots) are known as called ellipsis which indicates the variable number of arguments.

    24. Question 24. Define Macro?

      Answer :

      • Macros are the identifiers that represent statements or expressions in other words macros are fragment of code which is been given a name. #define directive is used to dedine a macro.
      • Example, we have define a macro i.e SQUARE(x) x*x. 
      • Here the macro determines the square of the given number. Macro Declaration: #define name text.

    25. Question 25. What Is The Disadvantage Of Using A Macro?

      Answer :

      The major disadvantage associated with the macro is :

      When a macro is invoked no type checking is performed.Therefore it is important to declare a macro coreectly so that it gives a correct answer whenever it is called inside the program.

    26. Question 26. What Is A Void Pointer?

      Answer :

      When we declare a variable as a pointer to a variable of type void, it is known as void pointer. Another name for it is generic pointer.

      In general we cannot have a void type variable,but if the variable is of void type it do not point to any data and due to this it cannot be de-referenced.

    27. Question 27. What Is A Unnitialised Pointer?

      Answer :

      When we create a pointer the memory to the pointer is allocated but the contents or value that memory has to hold remains untouched. Unitialised pointers are those pointers which do not hold any initial value.

      Example: int *p; is said to be an unitialise pointer, it is recomended to initialise the pointer before actually using it as it an error.

    28. Question 28. What Is Dangling Pointer?

      Answer :

      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.

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

      Answer :

      • 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.

    30. Question 30. What Is Null Pointer?

      Answer :

      NULL pointer is not the unitialised pointer that can point anywhere, the NULL pointers are the one which do not point anywhere that is which do not point to any object or any function.

Popular Interview Questions

All Interview Questions

C And C++ Practice Test

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

C++ Tutorial