0% found this document useful (0 votes)
30 views12 pages

Interrview Preparation For Languages

The document contains a comprehensive list of interview questions and answers related to the C and C++ programming languages. It covers fundamental concepts such as data types, memory management, pointers, functions, and object-oriented programming principles. Additionally, it includes code examples and explanations of various programming constructs and features.

Uploaded by

balaji waghmare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views12 pages

Interrview Preparation For Languages

The document contains a comprehensive list of interview questions and answers related to the C and C++ programming languages. It covers fundamental concepts such as data types, memory management, pointers, functions, and object-oriented programming principles. Additionally, it includes code examples and explanations of various programming constructs and features.

Uploaded by

balaji waghmare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 12

**********C LANGUAGE INTERVIEW QUESTIONS*********************

What is the C language ?


- C is a high-level and general-purpose programming language that is ideal for
developing firmware or portable applications.

what are the basic datatypes supported inn c language ?


-Basic datatypes ,(Short-1BYTE, char-BYTE1,int-2BYTE,long-4BYTE,float-
4BYTE ,double, long-4BYTE double-8BYTE & unassigned all for this
Derived data types,Enumeration Datatypes ,void Datatype

What is the difference between <stdio.h> & <conio.h> header files ?


-stdio.h contains declarations of printf() & scanf
whwer conio.h contains declaration of clrscr() & getch()

What do you mean by the pointer variable


-It is a variable which is declare to store the adress of the other variable

What do you mean by the Scope of the variavble ?


-It is defined as the part of the code area where the variables declared in the
program can be accessed directly. In C,all identifiers are
lexically(or statically)scoped.

What are the Static variables and functions ?


-Static variables are initialized only once. The compiler persists with the
variable till the end of the program. Static variables can be
defined inside or outside the function. They are local to the block. The default
value of static variables is zero.

Differentiate between the Calloc & malloc ?


-Calloc & malloc are both the dynamic memory allocation functions ,malloc()
function creates a single block of memory of a specific
size. calloc() function assigns multiple blocks of memory to a single variable.

Wher can we apply break control statement ?


-Break control statment is valid to be used inside a loop and the switch control
statment.

How can a negative integer be stored ?


-Negative number are stored as signed number where last bit on left is sign bit, if
it is 1 then its negative 0 mean positive,
remaining bits are data bit which are compliment of the positive bit.

Differentiate between Actual & Formal parameter ?


-The Actual parameters are the variables that are transferred to the function when
it is requested. The Formal Parameters are the values
determined by the function that accepts values when the function is declared. In
actual parameters, only the variable is mentioned, not the data types.

Can i compile c program without main ?


-The program will be compiled bt it will not be executed , main() is requied for
executing the c program

What is the nested structure ?


-when the data member of one structure is reffered by the data member of another
fuction , then the structure is called the nested structure

What is the C token


-Keywords, constant, special symbol, strings,operators identifires used in C
program are referred to as a C tokans

What is the pre processor ?


-Pre processor directive is consider as a built in pre defined function or the
macro that acts as a directive to the compiler and it gets executed before
the actual C prgram is executed EX-STDIO.H

How is C is the mother of all languages ?


-C introduces many core concepts and data structure like arrays, lists, functions,
strings, etc.Many languages designed after C are designed on the basis
of C language

Mention the feature of the C programming languages ?


-Hign level language, structure language, Rich library, extensible,memory
managment,faster, pointer, recursion

What is the use of the printf & scanf ?


-printf() is used to print the values on a screen, scanf() is used to scan the
values ,we need an appropriate data type format specifier for both printing
and scanning purpose

What is an array ?
Araay is an data structure which store similar kind of elements into it in a
sequential order , their are mainly three types of arrays 1.one dimensional
array,2.two dimensional array,3.three dimensional array

What is the null character ?


the symbol ( /0 ) mentionned is called as the Null character, It is considered as
the terminating character used in strings to notify the end of the string
to the compiler

Differntiate between compiler and the interprator ?


compiler trasnlates the complete code into the machine code in one shot ,
Interprator is designed to compile code in line by line fashion(interprator is in
java)

Can i used int datatype to store the 32768 value ?


-No, Intege data type will support the range between -32768 and 32767 ,Any value
exceeding that will not be stored in ,We can either use float or long int

How is function is declared in a C language ?


-Syntax :: return_type_functionz_name(formal parameters)
{
Function_body;
}

What is the Dynamic memory allocation ? Mention its syntax ?


-Dynamic memory allocation is the process of assigning the memory space during the
execution time or the run time.
Syntax: ptr = (cast-type*) malloc(byte-size);
ptr = (cast-type*) calloc(n,element-size);
ptr = realloc(ptr,newsize);
free(ptr)
Example: ptr = (int*) malloc(100 * sizeof(int));

Where we cannot use &(adress operator) in C ?


-We can not use & on constants and on a variable, which is declared using the
register storage class.
What is the structure and its example ?
-Structure is defined as the user defined datatype that is designed to store
multiple data members of the difeerent data types as a single unit
or
Structure is a constructed building or a specific arrangement of things or people,
especially things that have multiple parts. An EXample of
structure is a newly built home. An example of structure is the arrangement of DNA
elements. noun.

What is the difference between call by value and the call by reference ?
-In call by reference, the memory allocation is similar for both formal parameters
and actual parameters. All the operations in the function
are performed on the value stored at the address of the actual parameters, and the
modified value gets stored at the same address.

Differnce between getch() & getche()


-getch()- It does not reads from the keyboard but does not use buffers .So data is
not displayed onthe screen .
getche((- It reads from the keyboard & it uses buffer So data displayed on the
screen.

Explain toupper() with an example ?


-toupper() is a function designed to convert lowercase words/characters into upper
case

Write a simple code to generate random numbers in C ?


-Computer generates random number which are usually junk values .

Can i create customized header file in C ?


-It is possible to create a new header file .Create a file with functions
proptotypes that need to be used in the program .Include the file in the
#include section in its name

What do you mean by the memory leak ?


-Memory leak can be defined as a situation where programer allocates dynamic memory
to the program but fails to free or delete the used memory after a
complition of a code .

Explain static local variables and what is their use ?


- A static local variable is a variable whoes life dosent end with a function call
where it is declared .It extends for the lifetime of the
complete program

Differentiate between declaring header files with < > and ""
-< > - compiler searches for the header file within the built -in path
" " - the compiler will searches for the header files in the current working
directory. If not found, it searches for the file in other location.

When should we use register storge specifier ?


-we use register storage specifier if acertain variable is used very
frequently .The variable will be declared in one of the CPU registers

Which statment is efficent and why ? x++ / x=x+1 ?


-x++ , is most efficient statment as it just a single instruction to the compiler
while the other is not .

Can I declare same variable in two different scopes ?


-Yes , same variable name can be declared to the variables with a different
variable scopes

How to access members of a union of a pointer type ?


- Arrow operator (->) can be used to acces the data member of a union if the union
variable is declared as the pointer variable

Mention operations in C language ?


- Function Operation
fopen() to open a file
fclose() to close a file
fgets() to read a file
fprint() to write into a file

What are the storage class specifier in the C ?


- auto , register ,static,extern

What is the typecasting ?


- Typecasting is the process of connverting one data type in to another or we can
say lower data type to the higher
ex- into to float

Explain dangling pointer in the C language ?


- A pointer in c language is used to point the memory location of an existing
variable in case if that particular variabble is deleted and the pointer
is still pointing to the same memory location , then that particular pointer
variable is called as a Dagling pointer variable

Print a string with a % symbol in it ?


- there is no escape sequence provided for the symbol % in C ,to print % wee should
use '%%' as shown below .

Explain #pragma Directive ?


-This is preprocessor directive used to turn on or off certain features ,It have a
two type #pragma startup,#pragma exit ,& pragma warn

Howw to remove duplicates in an array

What is bubble sort


- it arranges the number in array according to assending or decending by depend on
condition .

What is round robbin algorithm ?


-It is one of the algorithm employed by the process and network scheduler in
computing in order to evenly distribute resources in the system .

How do i link program with the operating System ?


-File links the operating system to a program ,the file is defined in the header
file "stdio.h",It contains the information about the file being used ,
its current size ,its location in a memory

How to avoid the limitations of the scanf() ?


-scanf() cannot work with the string of the characters.
we cannot enter the multiword strring into a single variable using scanf(). to
avoid the gets() function is used .

Difference between macros and the function ?


- The macro call make a program run faster but also increases the program size ,It
simple and avoid errors related to the function call.
In function , call control is tranfered to the function along with the arguments
.This makes the function small & compact

#######PROGRAMS IN C LANGUAGE
#########

Q1 what is the output of the following C program fragment ?


-#include<stdio.h>
int main()
{
printf("%d",printf("%s","Helllo word !"));
return 0;
}
--->%s is used to print "string" of characters
printf not only prints the content on the screen , It also returns the number of
character that it
successfully prints on the screen .
OUTPUT is -- hello world 12

Q2 what is the output of the following C program fragment ?


--#include<stdio.h>
int main()
{printf("%10s","hello");
return 0;
}
-->%10s creates void ( empty space ) and then it prints the printf statment
OUTPUT is -- ( void of 10 letters )hello

Q3 what is the output of the following C program fragment ?


--#include<stdio.h>
int main()
{
char c =255;
c = c + 10;
printf("%d", c);
return 0;
}
-->all data types follow the airthmatic module ( 2^n ) & n is equal to 8 bcoz char
data type is 8 bits
long then (255+10=265) :: 265/255 = 9
OUTPUT is -- ( 9 )

Q4 Q3 what is the output of the following C program fragment ?


----#include<stdio.h>
int main()
{unassigned i=1 ;
int j=-4;
printf("%u",i+j);
return 0;
}
--> (i+j=1+(-4)= 3 bt its wrong (%u is a integer value that prints on machine to
machine ex-4294967293
****************C++_Language_interview_Qustions____

1.What is the difference betn C & C++ ?


->C language is the process oriented language,C++ is partially object oriented
language
It follows top down approch ,It follows bottom-up approch
It dosent support function or operator overloaing,It supports functtion as well
as function overloading
C lang dosent support virtual & friend function,C++ lang support both virtual &
friend function
C have 32 keywords ,C++ have 52 keywords

2.What are classes & objects in C++ ?


-A class is a user defined datatype with data members and member function and is
defined with keyword class.
Objects are defined as an intance of a class. Once the object is created, then it
can operate on both data members & member functions

3.What are the access modifiers ?


-Acces modifier are used to define accessibility for the class members.It defines
how the members of the class are accessed outside the class
scope .There are the three types of the accees modifiers 1.Private 2.Public
3.Protected

4.What is the C++ OOPS concept ?


-OOPS stands for the object oriented programming ,there are some concepts of OOPS
that is object,class,inheritance,polymorphism,encapsulation,
abstraction

5.What is the difference between while & the Do while loop ?


-while loop verifies the condition if its true ,then it iterates the loop till the
condition becomes the false
SYNTAX:
while(condition)
{
statments
}
If the condition in a while loop is false, then not a single statment will execute
inside the loop
*Do while loop first iterates the loop body once, then it checks for the condition
SYNTAX :
do
{
statments
}
while(condition);
If the condition in a do-while loop is false, then also the body will execute once

6.What is the constructor ?


- A constructor is a memeber function that is invoked whenever we create an
object;it has the same name as that of the class
There are 2 types of construcctors 1.Default constructor 2.Parameterizedd
constructor

7.Which of the following operator cannot be overloaded ?


-( ?: ) ternary operator ,bcoz overloading this operator not synthatically possible

8.Write a program to find factorial of a number ?


-#include <iostream>
using namespace std;

int main() {
int n;

int fact=1;
cout<< "Enter a positive integer: ";
cin >> n;

if (n < 0)
{
cout << "Error";
}
else {
for(int i=1; i<=n;++i)
{
fact *= i;
}
cout << "Factorial of " << n << " = " << fact;
}
return 0;

9.What is the Operator Overloading ?


-Operator overloading is a mechanism in which a special meaning is given to an
operator. EX- We can overload an operator '+' in a class
like string to concatenate two strings by only using '+'.

10. What if we compile the program without the main fuction, but we cannot run or
execute the program bcoz the main() function is the entryb point
from where all the execution begins and without the entry point , the program is
not executable

11. What is operator overloading & the function ovrloading ?


-Operator Overloading - It allows operator to have an extended meaning apart fro
their predefined meaning .
Function Overloading - It defines a method i such a way that there are multiple
waysto call them

12.What is the difference betn equal to(==) and assignment operator(=) ?


-The equal to operator(==) checks wheter two values are equal or not , If equal
then its true; otherwise ,it will return false .
The assignment operator (=) assigns the value of the right variable to the left
variable

13.When void() return type is used ?


-void() return type is used when we dont want to return any value. It specifies
that the function dosent returns a value. Function with void returns
type complete its task and then returns the controll to the caller

14.What is call by value & call by reference in C++ ?


-Both are the methods to pass the value to the functions
Call by value - we pass the copies of actual parameters to the functions formal
parameter .This means if their is any
change will not affect the actual values
Call by reference -The reference or adress of actual parameter is sent to the
functions formal parameter is sent to the functions formal parameter is sent
to the functions formal parameter ,This means any change in value inside the
function will be reflected in the actual value.
15.What is the innline function ?
-The inline function is expanded in line when its called, when this function is
called, the whole code of the inline function gets inserted or subtituted
at the inline function call.
SYNTAX :
Inline return-type function-name(parameters)
{
}

16.What are the pointers in C++ ?


-Pointers are the variable that holds the memory adress of another variable ,the
type of variable must be correspond with the type of pointer
SYNTAX: *name

17.What is scope resolution operator ?


-A scope resolution operator is represented as::
This operator is used to associate function defination to a particular class .
This operator is used for the following purposes
-To access a global variable when we have a local a variable with the same
name ,To define a function outsside the class

18.What is th std in C++ ?


-std is a standard namespace in C++.

19.How to input string in C++ with spaces ?


-#include<stdio.h>
#include<string>
using namespaces std;

int main()
{
string s;
cout <<"Enter the sentence with spaces "<<end1;
getline(cin,s)
cout<< s;
return 0;
}

20.Whar is diff. betn new() & malloc() ?


-new() is an operator , mallloc() is a function
new() calls the constructor , malloc() is not a cconstrutor
No need to specify memory size while using new(), we have to specify memory while
using malloc()
new opeerator can be overloaded ,malloc can neveer be overloaded

21.What is the diff. betn Prefix & Postfix ?


-In Prefix (++i), first the value is incremented , and then the value is assigned
to the expression
In Postfix(i++), the value is assigned to the expression and then the variables
value is incrmented

22.Tell any function which is not amember of a class ?


- friend function is not a member of a class

23. What is STL ?


-STL stands for the standard template library .It is a library of container
template that provide generic classes and functions
STL components are the containers,algorithm,iterations and function objects.
24.What is the copy constructor ?
-A copy constructor is the member function that intilizes an object using another
object within the same class
This cconstructor is of two types default copy constructor and user defined copy
constructor.

25.How does the strings are stored in the memory ?


- Characters of string are store contigously in the memory

26.What is inharitance ?
-Inheritance is the mechanism in which we can create a new class i.e child classs
from the existing class i.e parent class. this child class is also known
as a derived class and the parent class is also called as the base class .

27.What is the abstraction ?


-Abstraction can be defined as the technique in which we only show functionality to
the user i.e the details that we want the user to see and hiding the
internal details or the implementation details.

28.What is used to return the number of character in the string ?


- Size & length

**************JAVA INTERVIEW
QUESTIONS*******************
What is Java?
--> Java is the high-level programming language which is based on the principles of
object-oriented programming and can be used to develop large-scale applications.

1. what is JVM ?
-->java virtual machine is the abstract machine that provides runtime environment
to exicute the code.

2. Which class is a superclass of all classes?


--> Java.lang.The object is the root class for all the java classes and we don’t
need to extend it.

3. What is the static keyword?


--> The static keyword is used with a class level variable to make it global so all
the objects will be able to share the same variable.

4. What is Type casting in Java?


--> When we assign a value of one data type to a different data type then these two
data types might not be compatible with each other and needs conversion.
syntax : dataType variablename = (dataType) variableToConvert;

5. What is break and continue statement?


--> In a while or do-while loop, we use break for a statement to terminate the
loop. We use a break statement in a switch statement to exit the switch case.
The continue statement is used for skipping the current iteration of a for,
while or do-while loop.

6. What is an interface?
--> The interface provides a way to achieve abstraction in Java and used to define
the contract for the subclasses to implement.

7. What is aggregation in Java?


--> Aggregation is defined as the entity reference where it represents the
relationship between two classes.
Aggregation represents a has-a relationship.

8. What is the use of System class in Java?


--> System class belongs to the package (java.lang). Standard input and access to
externally defined property and environment variable.
e.g. = System.out.print()

9. What is an instance of keyword?


--> We can use instanceof keyword in java to check whether an object belongs to a
class or not. We should avoid much usage of it.

10. How to get the database server details in Java program?


--> we can use DatabaseMetaData object to get the database server details. When the
database connection is created successfully,
we can get the metadata object by calling getMetaData() method.

11. Why is Java a platform independent language?


--> it does not depend on any hardware or software due to the fact that the
compiler compiles the code and then converts it to
platform-independent byte code which can be run on multiple systems.

12. Difference between Heap and Stack Memory in java. And how java utilizes this ?
--> Stack memory is the portion of memory that was assigned to every individual
program. And it was fixed.
Heap memory is the portion that was not allocated to the java program but it
will be available for use by the java program when it is required,
mostly during the runtime of the program.

* Java Utilizes this memory as -


--When we write a java program then all the variables, methods, etc are
stored in the stack memory.
--when we create any object in the java program then that object was created
in the heap memory.

13. How is Java different from C++ ?


--> C++ is only a compiled language, whereas Java is compiled as well as an
interpreted language.
Java programs are machine-independent whereas a c++ program can run only in
the machine in which it is compiled.
C++ allows users to use pointers in the program. Whereas java doesn’t allow
it. Java internally uses pointers.
C++ supports the concept of Multiple inheritances whereas Java doesn't
support this.

14. What do you understand by an instance variable and a local variable ?


--> Instance variables are those variables that are accessible by all the methods
in the class. They are declared outside the methods and inside the class.
Local variables are those variables present within a block, function, or
constructor and can be accessed only inside them.

15. What do you mean by data encapsulation ?


--> Data Encapsulation is an Object-Oriented Programming concept of hiding the data
attributes and their behaviours in a single unit.
16. Briefly explain the concept of constructor overloading ?
--> Constructor overloading is the process of creating multiple constructors in the
class consisting
of the same name with a difference in the constructor parameters.

17. Can the main method be Overloaded ?


--> Yes, It is possible to overload the main method.

18. Comment on method overloading and overriding ?


-->method overloading is made possible by introducing different methods in the same
class consisting of the same name.
Method overriding is the concept in which two methods having the same method
signature
are present in two different classes in which an inheritance relationship is
present.

19. What do we get in the JDK file ?


--> JDK- For making java programs, we need some tools that are provided by JDK
(Java Development Kit).
JDK is the package that contains various tools, Compiler, Java Runtime
Environment, etc.

JRE - To execute the java program we need an environment. (Java Runtime


Environment) JRE contains a library of Java classes + JVM.

JVM - (Java Virtual Machine) JVM is a part of JRE that executes the Java
program at the end. Actually, it is part of JRE,
but it is software that converts bytecode into machine-executable code to
execute on hardware.

20. Difference between a Class and an Object in java?


--> An object is an instance of a class. Class is a blueprint from which the
instance/object is created.
An object is a physical entity whereas Class is a logical entity.

21. What is Object in OOP ?


-->Created from classes, represent a particular state of the class.

22. What is the abstraction in Java ?


-->An OOP technique to hide complexities from clients.

23. What is Inheritance in Java ?


-->An object-oriented technique to reuse code and functionalities.

24. What is Encapsulation or data hiding in Java ?


-->An oop way to hide data so that you can change it later without impacting
others.

25. Why Java doesn’t support Multiple Inheritance in Java ?


--> Consider a case where class B extends class A and Class C and both class A and
C have the same method display().
Now java compiler cannot decide, which display method it should inherit.

26. What do you understand by the terms variables and methods of an Object?
--> variables : Values assigned to the instance variables of an object make up the
object's state.
functions/methods : Methods/functions are where the class logic is stored.
This is where the
data gets manipulated or algorithms get executed. Functions are also called
procedures or methods.

27. What are the 4 OOPs principles in java?


--> a. Abstraction
b. Encapsulation
c. Polymorphism
d. Inheritance

28. Why do we use OOPs in java?


--> Reduces complexity and also improves the maintainability of the system.

29. What is Method Overloading and Overriding in java?


--> A class with multiple methods by the same name but different parameters called
Method Overloading.
In Method Overriding a subclass/child class has the same method name, same
method signature and same
return types as a method in its parent class, then the child class method has
overridden the parent class method.

30. What is the use of the final and super keyword in java?
--> By declaring the variable as final, the value of the final variable cannot be
changed.
By declaring the method as final, method cannot be overridden.
By declaring the class as final, class cannot be extended.

The super keyword is used to access superclass (Parent class) variables and
methods by subclass objects

31. Can we stop method overriding without using the final keyword?
--> Yes, we can stop the method overriding by declaring the method as private or
static.

32. What are the access modifiers available in java?


--> Public, private, protected, default

You might also like