We Offer 100% Job Guarantee Courses (Any Degree / Diploma Candidates / Year GAP / Non-IT / Any Passed Outs). Placement Records
Hire Talent (HR):+91-9707 240 250

Interview Questions

C and C++ Interview Questions and Answers

C and C++ Interview Questions and Answers

C and C++ Interview Questions & Answers

Here are the list of most frequently asked C and C++ Interview Questions & Answers in technical interviews. These questions and answers are suitable for both fresher’s and experienced professionals at any level. These C and C++ Interview Questions and Answers will guide you to clear all Interviews.

Best C and C++ Interview Questions and Answers

C and C++ Interview Questions and Answers for beginners and experts. List of frequently asked C and CPP Interview Questions with answers by Besant Technologies. We hope these interview questions and answers are useful and will help you to get the best job in industry. This C and C++ interview questions and answers are prepared by Professionals based on MNC Companies expectation. Stay tune we will update New C and C++ Interview questions with Answers Frequently.

Best C and C++ Interview Questions & Answers for Job Placements

Besant Technologies supports the students by providing C and C++ interview questions and answers for the job placements and job purposes. We provide the C and C++ online training also for all students around the world through the Gangboard medium. These are top interview questions and answers, prepared by our institute experienced trainers.
Here are the list of most frequently asked C and C++ Interview Questions and Answers in technical interviews. These questions and answers are suitable for both freshers and experienced professionals at any level.

Q1. What are the features in c programming?

C programming language supports multiple features. They are

  • Middle-Level Programming Language: C programming supports high-level features like Pointers, Structures data structures and as well as it will supports assembly code also so we conclude c as a middle level programming language.
  • Structured oriented programming Language: C program is structure oriented programming language means it will execute the statement in sequence
  • Modularity: In c programming language we can reduce the more line number of code by using modularity
  • Portability: C programming language is platform-independent means with minor modifications we can reuse the code on different platforms also.
  • Powerful Data Structure: With the help of data structures we can implement the complex application easily
Q2. What are the data types in c?

Data types divided into two types. They are

  • Predefined data types
  • User defined data types

Predefined Data types: Int, char, float and double are the predefined data types
User-defined data types: Arrays, Pointers, strings, and structures are user-defined data types

Q3. Types of errors in c?

Errors in c programming are divided in two types. They are

  • Compile Time Errors
  • Run Time Errors
Q4. What are the Compile Time Errors ?

Here we can discuss about the compile time they are

  • Pre-processor errors: Pre-processor errors will occur at the time of pre-processing   EX: #include<stdi.h>
    Here “stdi.h” is the fatal error
  • Translate Errors: These errors also called as syntactical errors. EX: printf(“Hello\n”) //Here missing semicolon “;”
  • Linker Error: Linking errors occur while linking the modules , methods or functions Ex: print(“Hello\n”); //Here printf is the error
Q5. What are the Run time errors?

Here we can discuss the compile-time they are

  • Segmentation Fault: Un authorized memory access called as segmentation fault
  • Bus Error: Memory is not at all existing still programmer trying to access it
Q6. What is a function in c? Types of Functions?

The function is nothing but a collection of a set of statements called function. Functions are divided into two types they are

  •  Pre Defined Functions
  • User defined Functions
Q7. What are Pre Defined Functions?

The functions which are coming with compiler by default that functions we can call it as pre defined functions
Ex: sqrt,pow etc

Q8. What is User Defined Functions?

The functions which are written by the programmer, then we can call it as user defined functions. To write user defined function need three components. They are below

  • Function declaration
  • Function definition
  • Function call
Q9. Control Statements or Control Flow ?

Control statements are divided into three types. They are

  • Conditional Statements
  • Iterative Statements
  • Jump Statements
Q10. Conditional statements in c ?

These statements are decision making statements in source code. This are several types

  • if statements
  • if-else statement
  • if-else if –else statement
  • nested if statement
  • switch-case statement
Q11. Iterative ( loop) statements in c?

When we are going to use repeated code we will use iterative statements. These are several types

  • for loop
  • While loop
  • do-while loop
Q12. Jump statements in c ?

Jump statements are used to break the loops , continue the loop and jump to the required statement. These are several types

  • break
  • continue
  • goto
Q13. What is a header file?

It is also known as a library file.it contains definition and prototype of the program. header file contains a set of functions.

Eg.stdio.h it contains a definition and prototype of commands like scanf and printf.

Q14. What are the translator in c?
  • assembler
  • compiler
  • interpreter.
Q15. What is assembler?

assembler is used to convert assembly lang.into machine lang. assembly lang. is noting but low level languge.

Q16. what is compiler?

It convert high level lang.into machine language.

Compiler takes the program as a whole and converts it into object code before execution.

Q17. what is variable?

variable is name given to mamory space that may  be used to store data.its value can be change depends on user reqirements.

Eg: int x=4 and int  x=8.

Q18. what are the different data types associated with variable ?
  • int-integer data type.
  • Char-character data type.
  • Float-floating point value.
  • Double-a double precision floting point value.
  • Void-valueless special purpose type.
Q19. what is variable declaration in c ?

In program first variable is declare and this variable is used in whole program .variable declaration tells compiler two things first name of variable and data type.

Q20. what are different types of variable?

a local variable, global variable, and static variable.

local variable

The variable that is defined within the body of a function or a block is known as a local variable. These variables are created when the function is entered and are destroyed when the function is exited.

Example:

void func(void)

{

int a,b;

}

Global variable

The global variable defines outside any function and is used for whole program.  These variable are automatically initialized to 0 at the time of declaration.

Static variable

static variable are declared by writing keyword static in front of the declaration.if static variable is not initialized then it is automatically initialized to 0.a static variable is initialized only one.

Static type var_name;

Q21. Can we declare variable anywhare in c ?

yes  due to modern gcc compiler support it.

Q22. How many keywords used in c?

32 Keywords are used in c (0-31)

Q23. What is register variable in c?

it is a case of automatic variable.it is used to store data.

Q24. What is extern in c ?

extern is a keyword which is used to extends the visibility of c variable and c function .and also due to extern variable memory is allocated for that variable.

Q25. What are the token in c program?

token is a smallest  basic component  of source code.tokens are ( constant,identifier ,operator,reserved word,separater)

Q26. Difference between declaration and definition?

The basic difference is that declaration has many form but the definition has only one. the declaration makes the variable as a part of a program  that can be used in the program. and definition tells the compiler to set storage for the variable.

Q27. Does c have a boolean variable type?

No,  is not a Boolean variable.

Q28. What is the basic component of the IEEE floating point?
  • sign
  • exponent
  • mantissa,
Q29. Why we use trigraph character?

when keywords are not supported some special character.

Q30. What is the keyword?

keyword hassome predefined meaning and it can not be changed.

Q31. What is constant?

constant have fixed values and they can not be changed during the execution of the program.

Q32. What is a function?

The function is a block of statement that perform some specific task, the function is the fundamental modular unit,it is reusable.

Q33. what are the different types of operator?
  • arithmetic operator.
  • logical operator.
  • relational operator.
  • comma  operator.
  • size of the operator.
  • conditional operator./ternary operator.
  • assignment operator.
  • bitwise operator.
  • increment and decrement operator.
  • other operator
Q34. when is the “void” keyword used in a function?

If function will not return any value at that time we use the void keyword at the leftmost part of the header function.

Q35. what is the significance of an algorithm to c programming?

The algorithm provides a step by step procedure on how a solution can be derived.

Q36. What is the use of semicolon?

Due to semicolon compiler knows where each statement ends. and also it can divide the statement Into smaller statements for syntax checking.it acts as the delimiter.

Q37. the % symbol ha sa special use in a printf statement.how would place this character as a part of the output on the screen?

you can do it by using %% in the printf statement.eg you can write printf(“10%%”)to have the op appear an s10%on the screen.

Q38. It is possible to create your own header file?

Yes, it is possible to create a customized header file.it can be created by using #include directive followed by the name of your header file.

Q39. What is the difference between the text file and the header file?

Text file contains data can be easily understood by humans.it include number, letter and another character. on the other hand binary files contains 1s and 0s that computer can interpret.

Q40. What are the different types of errors?

1) Compile-time error_ a)Preprocessor error b) linker error c) syntax error.

2)Run time error_ a) segmentation error b) bus error

Q41. What is the run time error?

This error occurs when the program being executed.one common instance wherein run time error can happen is when you are trying to divide a number by zero.when run time error occurs program execution will pause, showing which program line caused the error.

Q42. What are logical error and how does it differ from syntax error?

logical error occurs at compile time. this happen when a wrong formula was inserted into the code wrong sequence of command was performed.on the other hand syntax error occurs due to incorrect command that is not recognized by the compiler.

Q43. What are the control structures?

control structure decides which instruction are to be performed in program.and also define how the control is transferred to another part of the program. i.e it controls the flow of the program.

  1. selection statement_ if …else, switch.
  2. Iterative statement_ while,do..while, for
  3. jump statement _ goto, break, continue.
Q44. when is a switch statement can be better than an if statement?

If we have more than one condition to check on a single variable or a single expression then switch is better than if. In a switch statements, program execution jumps to matching value. and if we use it if the condition it checks one by one condition.

Q45. Difference b/w entry controlled and exit controlled loop?

In entry controlled loop body is checked after checking the condition, ie condition is checked first and after that body will be executed. Eg. For loop, while loop.

In exit controlled loop body is executed first and then loop test condition is checked.eg.do while loop.

Q46. Difference b/w sentinel control loop and counter control loop?

In counter control loop ,we know that exactly how many times loop body will be executed while in sentinel loop we don’t know about the loop recurrence,execution of loop is based on condition not on counter.

Q47. What is fall down property?

switch case statements follows fall down property. It means when case block is executed and break statements is not used after the block statements,then it will execute next case or default statements until break not reached or switch not finished.

Q48. What are the jumping statements in c lang.and how these work?

It is used to transfer the program control from one location to other location .

1.goto_ is used to jump program control from one locationto de

fine label

2.break_ is used in switch and loop statements it is used to break the execution of the switch and transfer the control after switch statement.

3continue_ is used in looping statement it transfer programs control in the starting of the loops body.

4.return_generally return is used in function body it transfer programs control from called to calling function.

Q49. Can we used continue statement without using loop?

No,continue statement can be used within the loop only.if we used without loop there will be compiler error “misplaced continue”.

Q50. can goto statements transfer program control from one function to another function?

No,it can transfer programs control within the function only.

Q51. what do you mean by array?

Array is a collection of same data type elements.Arrays are  always fixed.

Q52. How to creat array?

array contain data type ,array name and size of array

It can be delare as eg. int arr[5];  or int arr[];

Q53. Can we change the array size at run time?

No,we can not change the array size.

Q54. What is the default value of array?

default values of array is as follow

1.For byte ,short ,long ,int  default value id 0.

2For float ,double default values is 0.0.

3.For boolen default value is false.

4.For object default value is null.

Q55. When you pass array to an function what actually pass?

when you pass an array as a function the base address of an array will be passed.

Q56. what is the return 0 statement in main function indicate?

The return 0 value in the main function considered as the exit status of program or application. In some program return 0 is a success status of the program.

Q57. Can you return an array in c?

In c program, we cannot return the whole array as an argument to a function. but you can return a pointer to an array by specifying an array name without an index.

Q58. How does an array work?

array is a collection of similar data type elements. the length of array is established when the array is created .each atom is called elements of array,and each elements is accessed by its numerical index.

Q59. What is array indexing

The array is a data structure consisting of a collection of elements each is identified by array index or key.

Q60. How arrays are different from a normal variables

the array holds multiple values, whereas the normal variable holds a single value

Q61. What is dimensional array?

One dimensional array is a type of linear array.accessing its elements involves a single subscript which can be row or column index.

Q62. Features of C++?
  • C++ is an object-oriented programming language having features like abstraction, polymorphism, encapsulation, dynamic binding, and inheritance.
  • C++ provides a set of the library called STL to perform various functionalities like creating dynamic arrays like vectors.
  • It’s powerful and fast as compilation and execution take very less time. C++ provides allocation of memory dynamically(at run time).
Q63. What is the class?

Class is a user-defined datatype that has its own member function and member variables. Consider the example of a laptop. Let the laptop be a class. It will have member variables in parts such as a keyboard, mouse, ram, hard disk, etc. If we want to manipulate these members we need a set of functions called member functions.

Examples of Class Laptop

{

Char *keyboard; Char *mouse; Char *ram;

};

Q64. What is a reference?

Reference is another name for a variable used in the program.

FOR example, I have a variable called x x

Right now x is a variable let us suppose it is present at memory address 80. If I create a reference of x

Int &y = x

Now y , called reference of x is created. It will be just an alternate name of x, which means it will be pointing to the same memory location as that of x.

x y

Alternatively, I can also say that if someone’s name is “Ramesh” and his nickname is “Ram”.

both are the same person only.

Q65. Difference between pointer and reference?

Pointer contains the address of a variable. Let us take an example below :

A variable x we have, stored at address 80. Ptr contains the address of a variable. Int x = 10;

Int *ptr = &x;

X ptr

0X7ef999ef80

We can say ptr will contain a value of 80. ptr

0X7ffffeed300

The main difference between pointer and reference is

  • Reference is the alias of the variable, whereas the pointer contains the address of a variable.
  • Once a reference is created for a variable, it cant be made to point to some other variable, whereas a pointer can be referred to some other variable.
  • Reference must be initialized when created, whereas no such restriction is there in

the case of the pointer. If the pointer isn’t initialized it will be called a wild pointer.

Q66. What is an access specifier? What are the different types of specifiers?

Access specifiers are the keyword used in C++ to define the scope of visibility outside class.  three types of access specifier in C++

  • Public
  • Private
  • Protected

Example:

Class A

{

Public:

Int x;

Private:

Int y; Protected:

Int z;

};

Public access specifier means variables is accessible / viewed even from outside class.

Private access specifier means variables is not accessible/visible outside class. Only class members can see and access it. If we try to access it from outside class directly. The compiler will generate an error. Though Friend class can access private members.

Protected access specifier is similar to protected in the sense that it can’t be accessed outside class unless it with help of a friend class or by a derived class.

Q67. What is encapsulation?

Encapsulation is binding together data and functions that manipulate data . A good example we already discussed above is class.

example

Void A::setX()

{

X = a;

}

Int A::getX()

{

Return x;

}

Here in above example data x cant be modified directly so using member function setX we modified it and to get value of x also we can get directly using function getX we fetched it. Above class defined is example of encapsulation as it binds data (called x in above example) and member function that modifies them (getX,setX in above example) together.

Q68. What are inline functions?

When proram executes function in C++. Int fun(int x)

{

Return x;

}

Int Main()

{

Int y = fun(x);

}

  • During compilation as soon as program sees function call instructions CPU stores memory address of instruction following function call.
  • It also stores argument of function in stack(in above case x wil be stored in stack).
  • CPU then executes function code, stores the value returned by function in some memory location and returns the control to function who called this function(in above case control goes back to main).

This whole set of above process takes some time to execute called as execution time.

What if we have a function that is just returning the value or just setting value example getter setter which we explained in above question. In that case spending too much times in function call can impact total execution so to avoid this what if we have any such functionality which could retuce our function calls ,we can make such function as inline.

By specifying keyword inline in front of function, compiler sees instructions and if function doesn’t take much time it replaces function calling with function definition like when fun(x) is called it replaces definition of fun(x) in main thereby reducing our function calls.

Note: keyword inline is just a suggestion to compiler, its not an instruction, compiler may or may not make function inline. If function is very large doing some input output

operation in that case replacing whole function won’t help.

Q69. Difference between actual and formal parameters?

Let us see this with help of example:

Int sum(int a, int b)

{

Here a, b are formal paramters.

Return a+b;

}

Int main()

{

Int x = 3,y = 5; x, y are actual paramters. Int output = Sum(x,y);

Return output;

}

Formal as name indicates, are just a placeholder or we can say variables present in function declaration/ definition and they receive their value from some function call.

Actual parameters as name says these are actual parameter which is having some value and some address. Here x and y are some value variable with value 3, 5 and some valid address.

Q70. What is a constructor?

A constructor is a member function that initialized object of class It has same name as that of class and no return type.

There are different types of the constructor:

  • Default

Default contructor is one that doesn’t take any argument.

Class A

{

Private:

Int x; Int y; A()

{

x = 10;

y = 20;

}

};

  • Parametrized

In Parameterized ctr, we pass paramters.

Class A

{

Private:

Int x;

Int y;

A(int a, int b)

{

x = a; y = b;

}

};

  • Copy

o Used to Initialize new object of class using another object .

Class A

{

Private:

Int x;

Int y;

A(int a, int b)

{

x = a; y = b;

}

};

Int main()

{

A a(20,30); // object created using parametrized ctr A b = a; //copy ctr called

}

If we don’t define out own copy ctr compiler will create default copy ctr for us.

  • Syntax of copy constructor? When it is called ? className(const className &obj)

copy conctructor is called

  • when a new object from existing object of class.
  • Object is returned by value.
  • Compiler generates temporary object.
  • Obj of class is passed to function by value as an argument.
Q71. What would happen if we remove const in the copy constructor? What will happen if the const is removed?

className(const className &obj)

As we saw earlier in the example copy constructor is called when a new object is created from existing object.

Let us take an example

Class A

{

};

A fun()

{

}

A(){}

A a; Return a;

Int main()

{

A b = fun(); // fun function is called, it return an temporary object , thereby calls copy

//constructor. Now compiler created temporary object cant be modified. So its bound to

// const in copy constructor..

}

To avoid such scenarios const is added in copy constructor.

  • Use of & in copy constructor? What will happen if & is removed?

& means we are passing by reference, which we already discussed in call by value and call by reference. If we pass by reference that means we are not creating new object, we are passing reference of existing object.

A (const A &obj);

If we remove & , it will be A(const A obj)

Copy constructor itself is a function, if we pass argument by value, it will again call copy constructor, thereby making a chain of calls. So compiler doesn’t allow to make call by value.

Q72. What is function overloading? Discuss some scenarios where overloading is not possible?

Function overloading is when two or more functions have the same name but a different number of parameters/types of parameters.

Class A

{

};

Int fun(int i );

Int fun(double f);

Above two function fun(int i), fun(double f) are overloaded functions.

Now below are some scenarios which aren’t overloaded function:

These functions are the same but differ by return type.

So these aren’t overloaded functions.

Both functions are the same, one is an array, the Other is *, both are equivalent.

Q72. What is function overriding?

Function overriding is the re-definition of a function from base class to derived class i.e it has the same return type as well as parameters.

Fun is overridden function in below classes A and B. Class A

{

Void fun()

{

Cout<<” A class fun is called”<<endl;

}

};

Class B: public A

{

Void fun()

{

Cout<<” B class fun is called”<<endl;

}

};

Int main()

{

B b;

b.fun(); // it wil print fun of B class

//now if we say we have reference of A class but object of dervived class B b2;

A &test = b2;

test.fun(); // base class fun will be called.

}

To overcome such a scenario we make the base class function which is overridden as virtual. My marking function is virtual. The compiler will resolve that call at run time.

Now what we mean by run time.

As compiler executes below piece of code if virtual isn’t added.

B b2; // creats object of B class.

A &test = b2; // when compiler reference of A , test is created

test.fun() // test is mapped to fun at compile-time, as a reference is of the base class, so base class fun is called

Now if mark function as virtual, compiler understands mapping need to be done at run time instead of compile time. So when object b2 is created. It sees object is of class B, it maps with the object of B class now if we mark a base class function as virtual instead of class base class fun it will call derived class fun.

Q73. What are virtual functions in c++?

Virtual functions is a member function defined in the base class and overridden in the derived class. We use the virtual keyword for that.

Explanation already did in above.

Q74. Difference between struct and class?

Class and struct both are except few difference.

  • In Class, default access specifier is private, where default access specifier in struct is public.
  • Struct aren’t secure as they cant hide implementation details from user. Class are more secure.
Q75. Size of empty class?

When an object is created for a class , each object contains its own copy of member variables and a unique copy of member functions.

Member variables contributes to size of object

Class B

{

}

Int x;

Char b;

Int main()

{

B obj;

Cout<<”size of obje”<<sizeof(obj)<<endl;

}

Size of class B = size of int(x) + size of char (b)

= 4 + 1

= 5

Padding is done , so compiler will return 8.

Class A

{

};

Int main()

{

A a;

A b;

}

By looking it may look, as it doesn’t contain any member variable so size should be 0. But it compiler doesn’t work this way.

To assign each object a unique copy of member variables a, bit should be allocated to a unique address.

Both a and b will have a unique address. Hence size should be 1.

Q76. What is friend function?

A friend function is given special privilege to access private and protected members of the class.

We can make a function friend by adding a keyword friend in the beginning of the function. It can be a function of some other class or it can be global also.

Class A

{

Private: Public :

Int a;

friend void B::setVariable() ; // now this function can access private variable a.

though class B is independent of class A, still by making it friend it can access it, members.

};

Class B;

{

Void setVariable();

};

Friendship isn’t mutual. The function of class B can private/protected variables of A doesn’t

permit class A to access B class private variables.

Q77. What is a static keyword?

The static keyword could be added with variables, function,s or objects.

When used with variables, it becomes a shared variable for all members of that scope.

Void fun()

{

Static int count = 0; // count isn’t initialized every time. Only once initialized and same

updated value is used .

Count+=1;

}

Int main()

{

Int I = 0;

While(I < 5)

{

Fun();

}

Return 0;

}

//at the end count will b 5.

When static is given with class variables, static variables belong to the class, instead of belonging it with the object. Only one copy will be shared across all objects.

When declared with function, they can be called with an object, directly with class names they can be called

Class A

{

Static int fun();

};

A::fun() // can be called lik this.

Q78. Can the constructor be private? Why do we make a private constructor?

Yes, the constructor can private. If we have such scenarios where we want to make only one object per class

Class A

{

Private :

A *ptr; A();

Public :

};

Static Void fun();

Static void A:: fun()

{

If(!ptr)

Ptr = new A(); //public function can call private

Return ptr;

}

Int main()

{

A::fun(); // function is static so can be called without objects

}

The above case makes sure only one object is created.

Q79. What is a destructor? Can destructor be private ?
  • Destructor is a member function which is used to delete object.
  • Similar to constructor it has same name as that of class, no return type
  • It has no argumemt.

~A()

  • Add a tilde symbol before class Name. destructor is called automatically when object leaves current scope.
  • Only one destructor exists per class.
Q80. Can constructor be virtual ?

No, we cant make a constructor virtual.

Type of object is decided at compile time and virtual calls are resolved at run time. These conditions contradict each other.

If we make a constructor virtual, we wont be able to find out type of object at compile time, so compiler will generate an error.

Q81. What are pure virtual functions ?
  • A pure virtual function is such virtual function which doesn’t have any definition.
  • In declaration it is assigned 0 value. Virtual void fun() = 0;
  • It is also called the abstract function.
Q82. What is an abstract class?

A class having at least one pure virtual function, becomes abstract class, and its object cant be created. If a function is declared pure virtual in base class, it must be overridden in derived class. If not overridden in derived class, then derived class also becomes abstract class.

Class A

{

};

Public :

Virtual void fun() = 0; Void display();

Class B:public A

{

Public:

}

Void display();

Int main()

{

An obj; //error, as its abstract class, object cant be created. B obj2 // error, fun not overridden in derived class.

}

Instead, if we modify a class with below class Class B:public A

{

Public:

}

Void display(); void fun();

B obj // works fine.

Q83. How can we dynamically allocate memory in c++?

We can allocate memory to object dynamically using new operator.

It requests memory allocation from free store, same way as malloc, calloc.

Dynamic creation of memory means rather than allocating memory at run time, memory is allocated to object at run time.

Int * p = new int;

A * ptr = new A();

Q84. How free ptr know, how much memory to free?

When memory is allocated using a new operator, the compiler allocated one block of memory extra to denote how much memory needs to be allocated.

In the above example

Class A

{

};

Int a; Char b;

A * ptr = new A();

When memory is allocated to ptr, 8 bytes, at beginning compiler says how much memory to be allocated then add extra 8 byes to ptr.

As soon as we call delete(ptr), the compiler goes to the ptr location, checks how much memory needs to be freed, that corresponding blocks it frees and moves them back to free store.

Q85. What is a preprocessor?

As soon as the program is created, during the compilation phase, 1st phase is preprocessing, it’s done by the preprocessor.

Preprocessor handles preprocessor directives such as macros, file inclusion, conditional compilation. It replaces it with actual piece of code.

  • During preprocessing, macros like #define sum 5
  • Wherever sum is found in the program it’s replaced with 5.
  • All calls of #include<iostream> are resolved. Preprocessor tells the program to add this file in the source program.
  • Other directives like #pragma
  • #ifdef is also resolved by the preprocessor.
Q86. Difference between including a file using <> and “ ”?

When preprocessor sees file with <> , it instructs compiler to check file in standard library path. when preprocessor sees “ ” , it knows these are user defined files and instructs compiler to search in same directory. If program contains large piece of independent code. Its always a good practice to split code in different header file and include that header file separately.

Q87. Why it is required to include header files in your C program?

Header files are used to call the build-in function into the particular class

Q88. What is the meaning of the #include statement? Indicate its use?

Preprocessor directives begin with a # (hash). Preprocessor directives are the instructions given to the compiler.it used to call the build in function

Q89.Why is the main() function is so special?

The program starts running with the main function, so it’s special

Q90.State the use of comment symbol in a program?

Comments are used to understand the program flow and its explains the code written in the program

Q91.Describe the types of constants? Give example?

Numeric constant

Eg) int a=10;

Character constant

Eg) char s=’u’;

Q92.What is the usage of ?

Use to create a new line

Q93.Describe the different specifiers in scanf() function?

Specifiers in scanf are %c,%d,%s,%f,%x,etc..

Q94.Explain the process of initializing a string?

We can initialize a string like

Eg) char data[]={‘h’,’e’,’l’,’l’,’o’};

Q95.Explain with examples the different ways of reading strings from the user?
  • Read string in C using scanf() with %s.
  • Read string in C using scanf() with %c.
Q96.Difference between a pointer variable and normal variable?

normal variable—-

value=èeg) a=10

addressèeg) &a=12233

pointer variable—-

valueèeg *a=10

addressèeg) a=12233

Q97.Define dynamic memory allocation?
  •   Used to allocate additional memory available space or to release the unwanted memory space at point of runtime
  •   Used to optimize the use of storage space
  •   The programmer can allocate memory whenever he decides and releases it after using the memory
Q98.What is the header file used for DMA? What is the build-in function in DMA?

build in functionè

malloc()

calloc()

realloc()

free()

header fileè

#include<alloc.h>

Q99.What is the syntax for malloc()?

Ptr_name= (*cast type) malloc(int size);

Q100.What is the use of free() function in c?

free() is used to deallocate the memory created by allocation method

Q101.What is calloc() function? Describe the syntax?

calloc() used to allocate multiple blocks of contiguous  memory in bytes. All the blocks are of same size.

Syntax:

Ptr_name= (*cast type) calloc (No.of blocks,int size);

Q102.What is the types of file handling?

Binary file

Text file

Q103.What is mode for read a file?

‘r’ mode

Q104.List out the operations in c?

Basic file operations in c

  • Naming a file in c
  • Opening a file in c
  • Reading data from a file in c
  • Writing data to a file in c
  • Closing a file in c
Q105.Explain the use of fseek() function in files?

Used to go to a particular position

Q106.Explain the concept of I/O in files with the help of fscanf() and fprintf() functions?

Fprintfè used to print content in file

Fscanfè used to get data from file

Q107.Describe the basic concepts of OOPS?

Class,object,inheritance,polymorphism,abstraction.

Q108.Explain briefly Classes & Objects?

CLASS IS A collection of data member and member function

The object is an entity, used to call the functions in a class

Q109.State the use of #include directive in C++?

Used to call the predefined function

Q110.List the various benefits of Object-Oriented Programming?
  • OOP can also be used for design applications
  • Codesharing possible in OOPs
  • Errors can handle easily
Q111.State the use of typecast in C++?

Used to reduce the size of the variable

Q112.Explain the declaration of variables in C++?

Variables should be declared anywhere within the program

Q113.Explain the use of memory management Operators in C++?

Memory management Operators in c++ are new,delete.

Q114.Explain the declaration of variables in C++?

Syntax:

Datatype var;

Q115.Describe the use of Array of Objects?

Store multiple lists of data in a single object

Q116.What is the scope resolution operator?

`:` used to declare the function outside of the class

Q117.Define Function Overloading?

Same function with different types of argument

Q118.Explain Function overloading with a different number of arguments with an example?

C++ enables two or more functions with the same name but with different types of arguments or a different sequences of arguments or a different numbers of arguments. It is also called “Function Polymorphism”

Eg)

void display(char c, int n)

{for ( ;n>0;n–)

cout<<c<<” “;}

void display(int a, int b)

{for (;b>0;b–)

cout<<a<<” “;}

Q119.Define “friend “ keyword & its use?

The concept behind the encapsulation and data hiding restrict the non-member function from accessing the private members of the class by using the friend keyword.

Q120.Describe about friend class?

The private members of one class can be accessed from the member functions Of another class by making them friends.

Q121.Define parameterized constructor?

Used to initialize the data members of a class with different values when they are created. This is achieved by passing arguments to the constructor functions when the objects are created.

Q122.What is the copy constructor?
  • This constructor function designed to copy objects of the same class type.
  • It accepts a single argument and returns a copy of an object
  • It can also be called if you initialize a new object with another object of the same type
  • Arguments cannot be passed by value
  • provide a way to create an object by making a copy of an existing object
Q123.What is operator overloading?

Operator Overloading refers to giving the normal C++ Operators, such as +,*,<= etc., additional meanings when they are applied to user-defined data types. Simply defined as to create new definitions for operators.

Q124.Define pure virtual function?
  • A body-less virtual function is otherwise called. Simply defined as virtual functions with nobody
  • we use the pointer of the base class to refer all the  derived objects
  • It is a normal practice to have a function in base class just for implementing virtual function but the actual coding will be done in derived class only and also the class cannot be used for creating objects.
Q125.what is an abstract class?

A class that contains at least one pure virtual function is said to be an abstract class.

NOTE : you can use an  abstract class only act as a base class for deriving other classes but does not create objects

Q126.what is a manipulator? explain its syntax?

Manipulator function is special stream functions that change certain characteristics of input and output. All the manipulator functions prototypes are defined in the

SYNTAX:

header file <iomanip.h.>

Q127.What are all the building functions in manip.h?
  1. endl (new line character)
  2. setbase(covert the base value in to another bases value)
  • setw( set the width of the output)
  1. setfill(fills the given character in the unused field)
  2. setprecision(displays the number of digits after the decimal point in the floating numbers Etc..
Q128.what is the use of this pointer in c++?

It is a special pointer that exists for a class while a non-static  Member function is executing. It is used to access the address of the Class itself and may return data items to the caller.

Q129.Define streams?

A Stream is generally referred to flow of data.

Q130.Different streams are used to represent different kinds of data flow?

Each stream is associated with a particular class that contains member functions and definitions for dealing with that particular kind of data flow

Q131.what is the syntax for closing a file?

Close()

Q132.How to detect end of file?

Eof()

Besant Technologies WhatsApp