• By
  • June 20, 2019
  • C and C++ Programing


1) How to clear console in C language?

   Ans- clrscr() function is used clear console in C programming.

   This  function is included in <conio.h> header file.

2) What is the difference between variable declaration and variable definition?

Ans- Declaration tells you that what type of variable is whereas definition assigns value to a variable.

3) What are the different types of real data type in C ?

Ans- Floating point data types are called as real data types. They are float, double, and long double.

4) When is a switch statement can be better than an if statement?

Ans- The switch statement is better than if statement when we  have more than one condition to check on single variable or a single expression. If we use switch , program’s execution jumps to the matching value if found. If we use if condition, it checks one by one condition. Learn more at C and C++ Course in Pune.

5) What is the difference between  strlen() and sizeof in case of character array() ?

Ans- strlen() function is used to calculate length of string whereas sizeof() returns the number of occupied bytes by character array.

6) What is the difference between printf() and puts() ?

Ans- The function printf() writes the data on standard output device with the  formatted string using %c, %d, %s,  s .. etc and printf does not add new line after displaying text. Puts() is used to  writes the string on standard output device

7) What is a main() ?and difference between void main() and int main()?

Ans- main() is an predefined function which is already known to compiler. main() is an entry point of an execution. Actual execution of program starts from main() function. Every function returns a value to the calling function, at that time main will be a called function for compiler/OS and it will return some value to the compiler before exit, here void and int defines that main will return a void ( nothing) and int will return an integer values to the compiler. It means successful execution of program.

8) What is difference between  ++a and a++?

Ans-  There is two type of increment i.e pre-increment and post increment.++a is pre increment, where value will be incremented first and then expression evaluate. a++ is a post increment, in that case where expression evaluates first and then value increments.

9) How many types of errors that you know in C language?


1. Compiler Error or Syntax error

2. Linker Error

3. Run time error

4. Logical error

10) What is a pointer variable?

Ans- A pointer is a variable which is used to store address of another variable.

For Free Demo classes Call:   8237077325

Registration Link:Click Here!

11) What are the advantages & disadvantages of pointers ?



 With the use of pointers we can return multiple values from the  function.

 Using the pointers we can allocate memory to the variable at run time and of  we can reallocate it while execution time.

With the use of pointer we can design complex data structure like Stack Queue, Linked List, and Tree etc.

We can not change the value of variable in a function but using pointers i.e by using call by reference we can change the actual values of the parameters.


One of the disadvantage of pointer have  direct memory access.

If pointer is not initialized, it can causes segmentation fault.

Pointers variables are slower than other  variables.

Pointers need free dynamically allocated memory.

12) What is a null pointer?


a) To initialize a pointer variable when that pointer variable does not have any memory address.

b)To pass a null pointer as an  function argument when we don’t want to pass any valid memory address.

13) What is void* (void pointer)?

Ans- void* is a pointer, which is used to  points the memory address which does not has the specific data type.

14) What is dangling pointer?

Ans- A dangling pointer is  a pointer points to unknown address.

15) What is a volatile variable?

Ans- Compiler access the variables and stores it into registers as per the frequently usages, if actual value of a variable change, it will not use in expression, volatile keyword tells the compiler that the variable’s value may change at any time, so the variable (defined as volatile) should not be optimized by the compiler. read more at C and C++ Training in Pune.

16) What is Dynamic Memory Allocation (DMA)? And Which function are used to allocate memory dynamically?

Ans- Dynamic Memory Allocation  allows us to allocate memory at run time.

Following are the functions that are used to allocate and free the memory at run time:

malloc(): To allocate dynamic memory for one dimensional array i.e. contiguous memory allocation.

calloc(): To allocate dynamic memory for two dimensional array i.e. memory allocates in row and column manner.

realloc(): To re allocate dynamic memory.

free(): To free dynamically allocated memory.

17) What is memory leak ?

Ans- Memory leak means it occurs when program does not manage the memory allocation correctly.

18) What is the difference between malloc() and calloc()?

Ans- malloc() and calloc() both allocate the memory at the run time, these functions are very useful to allocated dynamic memory, when we are dealing with a large amount of data or want to create memory according our need at run time.

for example if we want to create memory for N number of students then these functions are needed.

malloc() is used to allocates the memory in single block according to given size, while calloc() allocates in multiple blocks according to given size.

19) What was languages before c?

Ans- Pascal, Fortran, Assembly, & Algol

 20) Why C language is called as C?

Ans- Because it was named after the language, that was called B.

21) What are the return type of malloc() and calloc()?

Ans- malloc() and calloc() both functions return void* (a void pointer).

22) What is a static function?

Ans- When we want to restrict a function to call in another file, static keyword is used  restrict function in the file where it is declared, it can not be access in another file

23) Can we define a function with in a function?

Ans- No, we can not define a function with in a function. But we can declare a function with in the function, which will accessible for that function only

For Free Demo classes Call:   8237077325

Registration Link:Click Here!

24) What are the jumping statements in C Language and how these work?

Ans- Jumping statements are used to transfer program control to one location to other location.

 jumping statements are used in c:

  1. goto
  2. break
  3. continue
  4. return

1) goto

Ans- It is used to jump program’s control from one location to define label.

2) break

Ans- It is used in switch and loop statements, it is also used to break the execution of the switch and loop’s body and transfer control after the loop/switch statement.

3) continue

Ans- It is used in looping statement, it transfer program’s control in the starting of the loop’s body.

4) return

Ans- This is used in function’s body, it transfers program’s control from called to calling function.

25) What is infinite loop?

Ans- A loop which is never finished is known as infinite loop, it means the looping condition is always true, so that loop never terminate. Infinite loop is very useful in embedded systems

26) Can we use continue statement without using loop?

Ans- No we cant use continue statement without loop.It can only be used within the loops only, it can be any loop while, do while or for.If it is used in loop it gives compile error.

27) What is wild pointer in c?

Ans- A wild  pointer  which has not been initialized

28) What are advantages and disadvantages of array?

Ans- Advantages:

(a) Easily access of  each element of array.

(b) Not important to declare too many variables.

(c) Elements of array are stored in continuous memory location.


(a) Wastage of memory space.

(b) It stores same type of data.

29) Write a program to print Hello world without using any semicolon.


void main()


    if(printf(“Hello world”)){



30) What are different storage class specifiers in C?
Ans- auto, register, static, extern

31) What are entry control and exit control loops?
Ans- It has two loops.

Entry Control: There are two entry control loop.

a. while loop
b. for loop

Exit control: There is only one exit control loop.
a. do while loop.

32) What are stack and heap areas?


Heap Area:It is used for the objects allocated dynamically (Using malloc() and calloc()).

Stack Area:It is used to store local variables and arguments of a method.

33) What is the use of the function in C?

Ans- Uses of C function are:

Function is used to avoid the rewriting the same code again and again in our program.

When a program is written using function then any part of our program can easily be tracked.


34) What is recursion in C?

Ans- A function which will call itself in its defination is called    as recursion.

35) What is the structure?

Ans- Structure is user defined data type which is collection of different types of data.

36) What is a union?


The union is a user-defined data type which stores different types of data.Size of union is memory of the largest member only.

In case of union, we can access only one variable at a time

37) What is the purpose of sprintf() function?

Ans- The sprintf() stands for “string print.” The sprintf() function does not print the output on the console screen. It transfers the data to the buffer..

38) Can we compile a program without main() function?

Ans- Yes, we can compile program without main() but it can’t be executed.

But, if we use #define, we can compile and run a C program without using the main() function.

39) What is the difference between getch() and getche()?

Ans- The getch() function reads a single character from the keyboard. It doesn’t use any buffer, so entered data will not be displayed on the output screen.

The getche() function reads a single character from the keyword, but data is displayed on the output screen. Press Alt+f5 to see the entered character.

40) What is the difference between near, far and huge pointers?

Ans- A virtual address is combination of the selector and offset.

In case of near pointer, it doesn’t have explicit selector whereas far, and huge pointers have explicit selector. If we  perform pointer arithmetic on the far pointer, the selector is not modified, but in case of a huge pointer, it can be modified.

These are the non-standard keywords and implementation specific. These are irrelevant in a modern platform.

41) What is typecasting?

Ans- The typecasting is a process of converting one data type into another is known as typecasting. If we want to store the floating type value to an int type, then we will convert the data type into another data type explicitly.

42) What are the functions to open and close the file in C language?

Ans- The fopen() function is used to open file whereas fclose() is used to close file.

43) How to Read a File?

Ans- We can read file by using  functions:

  • fscanf()
  • fgetc()
  • fgets()

44) How to write a File?

Ans- We can write data into file by using functions:

  • fprintf()
  • fputc()
  • fputs()

45) What is file pointer?

Ans- File pointer is a structure pointer which holds address of file.

For Free Demo classes Call:   8237077325

Registration Link:Click Here!

46) What is Realloc?

Ans- Realloc() is dyamic memory allocation function which is used to allocate memory dynamically which is already allocated using malloc() and calloc().

47) Define auto storage class?

Ans- Memory is allocated automatically to the variables when the function is called and deallocates automatically when the function exits in case of auto.

All variables declared inside a function  is considered as auto storage class by default.

48) Define static storage class

Ans- When the function is called,static storage class is  created once,even though the function gets repeated it retains the same value and exists until the program terminates.

49) Define register storage class?

Ans- A variables which are stored in CPU register instead of memory in case of register storage class .

50) Define extern storage class?

Ans- It is used to represent external variable.


1) What is C++?

Ans- C++ is an object-oriented programming language which was developed by Bjarne Stroustrup in 1985.C++ is a superset of C with addition of classes in C language.Initially, Stroustrup called C++ as  “C with classes”. After that it was renamed as  C++.

2) What are the advantages of C++?

Ans- C++ has  all aspects from C language.It has some additional features.

Additional Features:

It is portable language  that means  the software developed using  this language that  can run on any platform.

It is an object-oriented programming language which has features classes, objects, inheritance, polymorphism, abstraction.

It has feature of inheritance which provides reusability.

Data hiding provides security from attacker.

Message passing is a  used for communication between the objects.

3) What is the difference between C and C++?


C C++
This language was developed by Dennis Ritchie. This language was developed by Bjarne Stroustrup.
It is a structured programming language. It  supports both structural and object-oriented programming language.
It is a subset of C++. It is a superset of C.
C does not support the data hiding. So that  the data can be used by the outside world. C++ supports data hiding. So that  the data cannot be accessed by the outside world.
C supports neither function nor operator overloading. C++ supports both function and operator overloading.
The function cannot be implemented inside the structures. The function can be implemented inside the structures.
Reference variables are not supported in C language. C++ supports the reference variables.
It does not support the virtual and friend functions. It supports both virtual and friend functions.
 scanf() and printf() are mainly used for input/output. It uses cin and cout to perform input and output operations.

4) What is the difference between reference and pointer?


Reference Pointer
It is a temporary variable. It stores the address of another variable.
It  does not require any indirection operator to access the value. It can be used directly to access the value. It requires an indirection operator to access the value of a variable
It cannot be reassigned. It can be reassigned.
A null value cannot be assigned. A null value can be assigned.
It is required to initialize the variable at the time of declaration. It is not requied  to initialize the variable at the time of declaration.

5) What are the different types of polymorphism in C++?

Ans- Polymorphism  takes more than one form. It means having more than one function with the same function name but with different parameters.


i)Runtime polymorphism

ii)Compile time polymorphism

6)Define namespace in C++.

  Ans- Namespace is used to resolve naming conflict.

The namespace defines the scope where the identifiers are  declared.

It is used  to remove the ambiguity.

Ambiquity occurs when the different task occurs with the same name.

7) What are the C++ access specifiers?

Ans- The access specifiers are used to define how members of class can be accessed outside the class.

There are three types of access specifiers:

Private: Members of class  declared as private can be accessed only within the same class, and they cannot be accessed outside the class they are declared.

Public: Members of class declared as public can be accessed from anywhere within the class as well as outside the class .

Protected: Members of class  declared as protected cannot be accessed outside the class which is accessed in child class.

8) What is the difference between new() and malloc()?


i)new() is a preprocessor while malloc() is a function.

ii)There is no need to allocate the memory while using “new” but in case  of malloc() we  have to use sizeof().

iii)”new” initializes the new memory to 0 while malloc() gives random value.

iv)The new() operator allocates the memory and calls the constructor for the object initialization whereas  malloc() function allocates the memory but does not call the constructor for the object initialization. v)The new() operator is faster than the malloc() function.

9) Define friend function.

Ans- Friend function  is used to access the private and protected members of the class. It is not a member of the class, but it must be used in the class definition. Outside function i.e not the member of class cannot access the private data of the class. Sometimes, it is necessary for outside function to access the data. Friend function has the ability to access the private data of the class.

10) What is a virtual function?

Ans- A virtual function is a member function which is present in the base class and redefined in  the derived class.

When we use the same function  in both base and derived class, the function in base class is declared as virtual.

When the function is made virtual, then C++ determines at run-time which function is to be called based on the type of the object pointed by the base class pointer. So that by  making the base class pointer to point different objects, we can execute different versions of the virtual functions.

11) What is a destructor?

Ans- A Destructor is a special member function which is called when object of class is destroied.

For Free Demo classes Call:   8237077325

Registration Link:Click Here!

12) What is an overflow error?

Ans- It occurs  when the result of an arithmetical operation been greater than the actual space provided by the system.It is a type of arithmetical error.

13) What is overloading?

Ans- A single object has the same name, but it provides different properties  of the same function.  We can specify more than one definition for a function name or an operator in the same scope. It is called function overloading and operator overloading.

14) What is virtual inheritance?

Ans- Virtual inheritance provides  to create only one copy of each object even if the object appears more than one.

15) What is a constructor?

Ans- A Constructor is a special function which is called when object of that class . It has  same name as class name.

16) What is the use  of the delete operator?

Ans- The delete operator is used to free the dynamic memory created by new operator.

17) Why C++ provides this extensibility for new function?


  1. Performance: The built-in memory allocator function is a general purpose function and it fits for predefined data-types. For user-defined data-types that have very specific data to be allocated, and by customizing the way they’re allocated you can speed up memory management considerably.
  2. Debugging & statistics: Possessing the control over the way the memory is being spent provides great flexibility for debugging, statistics and performance analysis.

18) What is difference between in structure and class?

Ans- Members of a class are private by default while  members of struct are public by default.

19) Can we make copy constructor private?

Ans- Yes, a copy constructor can be made private

20) What Is Inheritance?

Ans- Inheritance means capability of a class to derive properties  from another class . It is one of the most important feature of OOP.

21) What is Static Member?

Ans-  Static elements are allocated storage only once in static storage area. Static members  have a scope till the program lifetime.

Static member functions do not have this pointer.

A static member function cannot be virtual.

22) What is copy construtor?

Ans- A copy constructor is a special  member function which initializes an object using another object of the  same class. 

Syntax:ClassName (const ClassName &old_obj);

23) Which of the  type of class allows only one object of it to be created?

Ans- Singleton class.

24) Which method is invoked at run time?

Ans-    Dynamic Binding method

25) Can we create object  of an abstract class ?

Ans- No.

26) Which is  the approach is adapted by C++?

Ans- Bottom up apporach.

27) What is default access specifier of class?

Ans-     Private.

28) Which function/type of function cannot have default    arguments?

Ans-   Structure.

29) What is the use of ‘using’ declaration?

Ans- It is used to refer a name from the namespace without the scope resolution operator. Read more at C and C++ Classes  in Pune.

30) What is the diffrence between method overloading and method overriding?

Ans- Method overloading is nothing but functions with the same name but different argument list. This is a form of compile-time polymorphism.

Method overriding is nothing same function name as well as same parameters in base class as well as in derived class. Method overriding is used while dealing with run-time polymorphism or virtual functions.

For Free Demo classes Call:   8237077325

Registration Link:Click Here!

Call the Trainer and Book your free demo Class now!!!

call icon

© Copyright 2019 | Sevenmentor Pvt Ltd.

Submit Comment

Your email address will not be published. Required fields are marked *