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.
1.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 middle level programming language.
2.Structured oriented programming Language: C program is structure oriented programming language means it will execute the statement in sequence
3.Modularity: In c programming language we can reduce the more line number of code by using modularity
4.Portability: C programming language is platform independent means with minor modifications we can reuse the code on different platforms also.
5.Powerful Data Structure: With help of data structures we can implement the complex application easily
1.Predefined data types
2.User defined data types
1.Predefined Data types:
Int, char, float and double are the predefined data types
2.User defined data types:
Arrays, Pointers, strings and structures are user defined data types
1. Compile Time Errors
2. Run Time Errors
1.Pre-processor errors:Pre-processor errors will occur at the time of pre-processing
Here “stdi.h” is the fatal error
2.Translate Errors:This errors also called as syntactical errors.
EX: printf(“Hello\n”) //Here missing semicolon “;”
3.Linker Error: Linking errors are occur while linking the modules , methods or functions
Ex:print(“Hello\n”); //Here printf is the error
1.Segmentation Fault: Un authorized memory access called as segmentation fault
2.Bus Error: Memory is not at all existing still programmer trying to access it
1. Pre Defined Functions
2. User defined Functions
Ex: sqrt,pow etc
1. Function declaration
2. Function definition
3. Function call
1. Conditional Statements
2. Iterative Statements
3. Jump Statements
1. if statements
2 .if-else statement
3. if-else if –else statement
4. nested if statement
5. switch-case statement
1. for loop
2. While loop
3. do-while loop
Is also known as library file.it contain definition and prototype of program.header file contains set of function.
Eg.stdio.h it contains defination and prototype of commands like scanf and printf.
assembler is used to convert assembly lang.into machine lang. assembly lang. is noting but low level languge.
It convert high level lang.into machine language.
Compiler takes the program as a whole and converts it into object code before execution.
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.
int-integer data type.
Char-character data type.
Float-floating point value.
Double-a double precision floting point value.
Void-valueless special purpose type.
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.
local variable,global variable and static variable.
1.The variable that are define within the body of a function or a block is known as local variable .These variable are created when function is entered and are destroyed whwn function is exited.
2.Golable variable define outside any function and is used for whole program. These variable are automatically initialized to 0 at time of declaration.
3.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;
yes due to modern gcc compiler support it.
32 Keywords are used in c (0-31)
it is a case of automatic variable.it is used to store data.
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.
token is a smallest basic component of source code.tokens are ( constant,identifier ,operator,reserved word,separater)
Basic difference is that declaration has many form but definition has only one. declaration makes the variable as a part of program that can be used in program. and definition tells compiler to set a storage for variable.
No ,is not a Boolean variable.
1.sign 2.exponent 3.mantissa,
when keywords is not supported some special character.
keyword have some predefined meaning and it can not be changed.
constant have fixed values and they can not be change during execution of program.
The function is a block of statement that perform some specific task,function is the fundamental modular unit,it is reusable .
5.size of operator.
6.conditional operator./ternary operator.
9.increment and decrement operator.
If function will not return any value at that time we use void keyword at leftmost part of header function.
The lgorithm provides a step by step procedure on how a solution can be derived.
Due to semicolon compiler knows where each statement ends. and also it can divide the statement Into smaller statement for syntax checking.it acts as delimiter.
Q37.the % symbol ha sa special use in a printf statement.how would place this character as a part of output on the scrren?
you can do by using %% in the printf stetment.eg you can write printf(“10%%”)to have the op appear a s10%on the screen.
Yes it is possible to create a customized header file.it can be create by using #include directive followed by the name of your header file.
Text file contain data can be easily understand by humans.it include number ,letter and other character. on other hand binary files contains 1s and 0s that computer can interpret.
1) Compile time error_ a)Preprocessor error b) linker error c) syntax error.
2)Run time error_ a) segmentation error b) bus error
This error occur when program being executed.one common instance where in run time error can be happen is when you are trying to divide a number by zero.when run time error occur program execution will pause ,showing which program line caused the error.
logical error occure at compile time.this happen when a wrong formula was inserted into the code wrong sequence of command was performed.on other hand syntax error occur due to incorrect command that are not recognized by the compiler.
control structure decide which instruction are to be performed
in program.and also define how the control is transferred to other part of program. i.e it control the flow of program.
- selection statement_ if …else, switch.
- Iterative statement_ while,do..while, for
- jump statement _ goto, break, continue.
If we have more than one condition to check on single variable or a single expression then switch is better than if. In switch statement program execution jumps to matching value.and if we use if condition it check one by onecodition.
In entry controlled loop loop body is checked after checking condition,ie condition is checked first and after that body will be executed. Eg. For loop, while loop.
In exit controlled loop loop body is executed first and then loop test condition is checked.eg.do while 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.
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.
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
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.
No,continue statement can be used within the loop only.if we used without loop there will be compiler error “misplaced continue”.
No,it can transfer programs control within the function only.
Array is a collection of same data type elements.Arrays are always fixed.
array contain data type ,array name and size of array
It can be delare as eg. int arr; or int arr;
No,we can not change the array size.
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.
when you pass an array as a function the base address of an array will be passed.
The return 0 value in main function considered as exit status of program or application.In some program return 0 is a success status of program.
In c program we cannot return whole array as an argument to an function.but you can return a pointer to an array by specifying array name without an index.
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.
Array is a data structure consisting of a collection of elements each is identify by array index or key.
array holds multiple values,whereas normal variable holds single value
One diamensional array is a type of linear array.accessing its elements involves a single subscript which can be row or column index.