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.
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
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
Errors in c programming are divided in two types. They are
- Compile Time Errors
- Run 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
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
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
The functions which are coming with compiler by default that functions we can call it as pre defined functions
Ex: sqrt,pow etc
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
Control statements are divided into three types. They are
- Conditional Statements
- Iterative Statements
- Jump Statements
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
When we are going to use repeated code we will use iterative statements. These are several types
- for loop
- While loop
- do-while loop
Jump statements are used to break the loops , continue the loop and jump to the required statement. These are several types
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.
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.
a local variable, global variable, and static 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.
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 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)
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.
No, is not a Boolean variable.
when keywords are not supported some special character.
keyword hassome predefined meaning and it can not be changed.
constant have fixed values and they can not be changed during the execution of the program.
The function is a block of statement that perform some specific task, the function is the fundamental modular unit,it is reusable.
- 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
If function will not return any value at that time we use the void keyword at the leftmost part of the header function.
The algorithm 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 statements for syntax checking.it acts as the delimiter.
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.
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.
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.
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 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.
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.
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.
- 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 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.
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.
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 the main function considered as the exit status of program or application. In some program return 0 is a success status of the program.
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.
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.
The array is a data structure consisting of a collection of elements each is identified by array index or key.
the array holds multiple values, whereas the normal variable holds a single value
One dimensional array is a type of linear array.accessing its elements involves a single subscript which can be row or column index.