SUMMER TRAINING Free Tutorials  Go To Your University  Placement Preparation 
Project Based Best Summer Training Courses in Jaipur
Investing in yourself is easy. Udemy online courses now from INR 455
0 like 0 dislike
1.2k views
in Technical Questions by Goeduhub's Expert (5.8k points)
edited by
C and C++ Interview Questions with answers

1 Answer

0 like 0 dislike
by Goeduhub's Expert (5.8k points)
edited by
 
Best answer

C and C++ Interview Questions Set 1

Q.1. What are the differences between C and C++ language?

Answer:-

  • C++ is a kind of super set of C, most of C programs work in C++ as well.
  • C is a procedural programming language, but C++ supports both procedural and Object Oriented programming.
  • Since C++ supports object oriented programming, it supports features like function overloading, templates, inheritance, virtual functions, friend functions. These features are absent in C.
  • C++ supports exception handling at language level, in C exception handling is done in traditional if-else style.
  • C++ supports references, C doesn’t.
  • In C, scanf() and printf() are mainly used input/output. C++ mainly uses streams to perform input and output operations. cin is standard input stream and cout is standard output stream.

Q.2. Difference between Declaration and Definition of a variable.

Answer:- Declaration of a variable is merely specifying the data type of a variable and the variable name. As a result of the declaration, we merely tell the compiler to reserve the space for a variable in the memory according to the data type specified. For example:-     int result; char c;

Whereas, a definition is an implementation/instantiation of the declared variable where we tie up appropriate value to the declared variable, so that linker will be able to link references to the appropriate entities. For example:- result=10; c='A';


Q.3. Explain what is a class in C++?

Answer:- A class in C++ can be defined as a collection of function and related data under a single name. It is a blueprint of objects. A C++ program can consist of any number of classes.


Q.4. Explain what is the use of void main () in C++ language?

Answer:- To run the C++ application it involves two steps, the first step is a compilation where conversion of C++ code to object code take place. While second step includes linking, where combining of object code from the programmer and from libraries takes place. This function is operated by main () in C++ language.


Q.5. Explain Local and Global scope of a variable.

Answer:-  Local Scope: A variable is said to have a local scope or is local when it is declared inside a code block. The variable remains active only inside the block and is not accessible outside the code block.

Global Scope: A variable has a global scope when it is accessible throughout the program. A global variable is declared on top of the program before all the function definitions.


Q.6. How many ways are there to initialize an int with a Constant?

Answer:- There are two ways:

  • int result = 10;
  • int result (10);

Q.7. What is a array?

Answer:- An array is a series of elements of the same type in contiguous memory locations 


Q.8. What is the difference between equal to (==) and Assignment Operator (=)?

Answer:- Equal to (==) is equality relational operator that evaluates two expressions to see if they are equal and returns true if they are equal and false if they are not.

The assignment operator (=) is used to assign a value to a variable. Hence, we can have a complex assignment operation inside the equality relational operator for evaluation.


Q.9.  What is the explanation for the dangling pointer in C? 

Answer:-  When there is a pointer with pointing to a memory address of any variable, but after some time the variable was deleted from the memory location while keeping the pointer pointing to that location. 


Q.10. What is the difference between ++a and a++? 

Answer:- ‘++a”  is called prefixed increment and the increment will happen first on a variable. ‘a++’ is called postfix increment and the increment happens after the value of a variable used for the operations.


Q.11.  What is an Inline function in C++?

Answer:- Inline function is a function that is compiled by the compiler as the point of calling the function and the code is substituted at that point. This makes compiling faster. This function is defined by prefixing the function prototype with the keyword “inline”. Such functions are advantageous only when the code of the inline function is small and simple. Although a function is defined as Inline, it is completely compiler dependent to evaluate it as inline or not.


Q.12. What are different storage class specifiers in C?

Answer:- There are 4 storage class specifiers:- auto, register, static and extern


Q.13. Why pre-processor directive does not have a semi-colon at last?

Answer:- Semi-colon is needed by the compiler and as the name suggests Pre processors are programs that process our source code before compilation. Therefore the semi-colon is not required.


Q.14.  Explain what is Copy Constructor and what is it used for?

Answer:- Copy Constructor is a technique that accepts an object of the same class and copies its data member to an object on the left part of the assignment.


Q.15. What is a Reference Variable in C++?

Answer:- A reference variable is an alias name for the existing variable. This means that both the variable name and the reference variable point to the same memory location. Hence, whenever the variable is updated, the reference is updated too.


For any queries or doubts refer to comment section mentioning question number  with doubt


C and C++ Interview Questions Set 2

For more Technical MCQ's and Interview Questions Click here

Our Mentors(For AI-ML)


Sharda Godara Chaudhary

Mrs. Sharda Godara Chaudhary

An alumna of MNIT-Jaipur and ACCENTURE, Pune

NISHA (IIT BHU)

Ms. Nisha

An alumna of IIT-BHU

Related questions

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 
...