Hello everyone, how are you all?. In this video we are going to discuss top 10 Most asked interview questions for C programming.
Here we will be seeing those 10 questions which are mostly asked in C programming interviews.
Apart from these questions, there are many other questions which you can discuss and you can read about them so that you can crack your C programming interview but, these are those 10 questions which are asked too many times in the interviews, that's why we will be discussing all of those questions in this video.
So, we will consider the questions one by one and then we will see that how the answers should be put forward so that the interviewer gets the points that he expects related to that question.
Here we will study the questions one by one and we will discuss their answers.
So, without any delay we will start quickly and we will see our very first question, the first question is, “What is C programming language?” Now, this question is very simple but how this question should be answered we will see that over here.
So, “C is a procedural programming language.
The procedural programming language is a structured programming language and it is a technique in which large programmes are broken down into smaller modules.”
Now, C programming language is a type of procedural programming language and if we talk about the procedural programming language, if we talk about this concept, so, it tells us here that any programming language which is written in a structured way that we call as procedural programming language and here there is one more special thing about it that here whichever large programs are there, we divide them in small modules, suppose this part of the program is performing some other functionality, the other part is performing some other functionality, if we combine them all together then our big logic, the large program gets completed.
So, these kinds of programming language, we call them as procedural programming language and C programming language is a type of procedural programming language.
C programming language is that type of programming language, along with that what is the meaning of procedural type, all these things you can answer for this question.
So, we will see our next question, what is C programming language and after that what else can be asked in interviews.
So, this is the second question, in which they are saying, what is the use of printf and scanf function.
So, we had spoken about our input and output operations through our terminal, so through those situations, which functions we would be using? We use printf and scanf functions.
So if we talk about printf function, “The printf function is used to print the integer, character, float and string values onto the screen”.
Whereas talking about scanf function, “The scanf function is used to take input form the user through the terminal.” So, here you can explain both the functions one by one and you can see how we can implement their use in C programming language.
So, if we talk about printf function, it helps us put any type of value on the output screen or on the terminal, in the same way scanf function basically helps us take in the input through the terminal, which means whichever input the user is typing, he is putting on our terminal.
That brings our scanf function in the program and in those values or inputs basically we are able to perform the operations.
This is the special thing about our printf and scanf functions.
Now, we will go ahead and see our next question.
The next question is what is the difference between call by value and call by reference? This is a very common question that is asked, this call by value and call by reference.
Which are the calling ways with any function argument, what is the difference in it, what is the main difference in both the ways? So, if we talk about call by value method, so, “it passes a copy of the value to the function and the original value is not modified.” Whereas talking about call by reference, “It passes the value to the function as an argument then the original value is modified.” So, if we talk about our formal parameters or the actual parameters, in call by value method, whatever changes that we make on our formal parameters, those changes basically don’t affect the actual parameter.
In the same way if we talk about call by reference method.
Here we pass the values of the address in the function definition as an argument and what happens with it? The changes that we make on formal parameters, all those affect our actual parameters and on actual values.
All the things that we change in the function definition that affects the value stored in the variables as well.
So, this is the difference between call by value and call back reference method, there is one more difference, call by value the normal arguments that we pass, there we do not use any extra operator, but if we talk about call by reference method, here in front of the variable’s name, we also put one Asterix symbol and this Asterix symbol helps us to fetch the address of that particular value.
So, in the same way, since we pass the address in call by reference method of that value.
So that our actual parameters, even their value changes, that's why we are putting a extra Asterix symbol, as compared to call by value method.
So, this is the basic difference between call by value and call by reference method.
Now we will go ahead and see our next question which is asked in the interviews this is “What is recursion in C?” So, if you talk about this question, when a function calls itself in its definition, it is known as recursion and these types of functions are known as recursive functions.
So, if we talk about the function’s definition so, we usually see that our function definition that is there, that we write outside of the main function along with that our function call is usually there in some other function, let's suppose in the main function that function call is happening but if we make such a scenario where the function which a definition, again if we call the same function in it, if we write the definition in the function call.
With this what will happen is when the functions definition statements would be running one by one at that time, they would be executing, at the same time, or function call will also get executed.
And again, the function definition will start executing one by one, in that situation in that function call the parameters that were passed, for that.
So, in this way, if when we put a function call in a function definition, we put it in the same function definition, at that time, recursion concept is created.
And this kind of functions, we call them as recursive function.
So, this was about how recursion function works in C programming language? We will go ahead of it and we will see what is the next question which is asked in the interview very often.
So, this question is “what is the difference between single and multidimensional arrays” So, “single dimensional arrays are linear that is List View whereas, multi dimensional arrays are more like tables.” So, if we talk about our single dimensional arrays, we all know that they are like any linear structure and its values are attached one after the other, their blocks are adjusted next to each other.
But if we talk about our multidimensional arrays? It can be two dimensional, three dimensional, four dimensional arrays, what happens in this? Arrays levels keep on increasing, let's suppose in our two dimensional arrays, the situation is created in this way that it is a normal linear type array but its elements in it, instead of being a nominal value, those are arrays in their own sense.
So, what happens in this situation, when we talk about 2d array, it starts to look like a tabular format and that's why we say that this two dimensional arrays look like similar to a table.
In the same way if we talk about three dimensional arrays, what happens in that, we have a linear array and its elements are arrays amongst themselves and these array’s elements are also arrays.
So, in this way as and when our dimension increases, our arrays degree, one inside the other the errors that we are making, even those keep increasing.
So, this is the basic difference between a single dimensional array and in a multi dimensional array.
We will go ahead and see our next question.
What is that next question? This question is “How are structure and union different?” We had seen that in derived data types structures also come as well as unions.
So, if we talk a little about structures, these both concept of structure and unions so, these are similar in writing because even they have member variables, But their basic concept difference, what exactly is that, that is what we have being asked here.
So, “structure is a user defined data type that allows to combine data items of different kinds to make one single data type.” So, if we talk about our structure, what does the structure do? It makes a group of different data types and after making that group what it does is, if we have a variable’s group and the same types of values we have to store constantly.
So that type of structure is made by the variable.
Let's suppose that we have to store some students information, in that comes, student’s names, student’s contact number, student’s address.
So, all these three things we will have to store in some variable, right? And we have to store this kind of information for multiple students.
So, what will I do is I will make a structure in which I will define student’s name, student’s contact number and student’s address, with this information and with this structure, I will make different multiple variables to store the information of different students and if we talk about union.
So, “union helps to store various types of data in the same memory location, but not simultaneously.” So, if we talk about unions in unions, there are different types of variables that are written, but what happens in that the identifier names as unions.
With that name we can store different types of values like we said in union we have written int and float as well and character also.
So, at one time with the same name, we can also store int value in it, after that we will store float type value in the same name with the help of union.
So, these things doesn't happen together.
But, if we say that in one name, we want to store different types of value, next time.
In that situation we can use the unions very efficiently.
So, this is the basic difference, on one side the structure makes up the entire structure in which we have to combine different data types of variable and make a single data type.
Whereas union helps us store different types of values but not simultaneously, at different times.
So, this was about the difference between structure and union.
Now, we will go ahead and see our next question, next question is how can we execute a program without writing the main function? So, we have seen that till now no matter how many programs we have made, in that we have definitely written the main function, but if such scenario comes where without writing the main function, I want to execute my program.
So, at that time what I can do? We had seen that #define preprocessor command, with that what can we do? We can give a different name for any value and whenever we will call that name in our program, corresponding to that the value that we had written with the help of #define, that value will be called in its place.
So, if I want that I should not write the main function, with the help of #define, I will write some other name, which would basically mean main.
So, where we start the main function there if I write another name, which was given by #define.
Let's suppose we wrote #define start and after that main, it means that whenever I’ll write start name anywhere, in my program.
Instead of using it, it will basically use main.
So, where we used to write int main or void main, there we can write int start or void start and when we are writing this start name, start will basically redirect with the help of #define and it will bring the main names, which will not be seen from front but at the backend process, this thing would be going on.
So, in this way, with the help of #define function, we can change the name of the main function and we can keep it as a main function.
So, this was about how we can execute the program without the main function.
Now we will go ahead and see our next program.
This question is “Pointer int*a points to a variable Q, what can Q contain?” Now, they want to ask a that the a is the pointer with us which data type is int and it is pointing at some Q variable.
Now, the question here is that inside Q which type of value would be stored.
So, “Q variable will contain an integer value as the pointer pointing on it has a return type of int, and we know that data type of pointer defines what value will be stored in the variable.” So, the pointers data type or the pointers return type on that it is dependent that on what type of variable it can point.
Since, we were not told the Q's data type.
Because our pointers data type is also int and we know that why this pointer is pointing at Q variable, in that case our Q variable’s data type will also be an integer and that's why we will be able to store only integer values in it.
So, these kinds of questions can also be asked in our interviews where the concepts, which can be related to pointers or structure or related to functions, that concept can be turned or twisted a little and can be asked in the interviews.
In that situation we have to remember the concept and we have to give the answers as per that.
Now, we will move ahead to our next question and this question is “what is the difference between i++ and ++ i operation.
So, here we have two types of operations ++ which is an increment operator, which is written in front of the i variable and in one place it is written behind.
So, here there is a difference in writing them but the main difference is of logic, if we want to see that what will that be, that has been asked us here.
So, “expression i++ returns the old value of i and then increments the value of i by 1”, which means, when we want to write i++, where we have written i++ at that point i’s earlier value will be printed and it would be used.
But after that, whenever i’s topic will be raised, i will be used.
I’s value would have become +1, it must have incremented but if we talk about ++i expression, wherever we will write this expression, on that point i’s value will be incremented and used.
“So, ++i expression increments the value and then returns the new value.” Wherever i++ is written, there i’s normal value will be used and in the next call or in the next use i’s value will be increased by +1 but if we talk about ++ i expression, in that case wherever this expression is written at that point in the i’s value plus one is increment and from there the i’s value would have become +1 and then i+1 would be used.
So, this is the basic difference between i++ and ++ i.
So, how we can use these two different operations and expressions in our programming language because in i++, the value is not changed early on.
The value is used as it is.
In the next iteration or in the next use, its value is increased and in ++i expression the value is increased early on and then it is used.
Now, we will move on to our next question and this question is “what is the program to check a prime number.” So, we all know that in math we have prime numbers with us like 3, 5, 7 or these kinds of numbers which are divided by itself or by 1.
So, these types of numbers, we call them as prime and if we wish to make one program where we would be testing these prime numbers whether one number that has been given to us is prime or not.
If we want to test that, how would we do it? How will we write its program? If this is being asked to us in an interview, how do we have to give the answer for that, we will be discussing that over here.
So, let's suppose what we will do is, we will make one logic and the logic is somewhat this way.
Suppose we have considered number five.
So, we will see that 5 can be divided with which all numbers.
So, we can see that 5 can be divided by 1, it can also be divided by 2 but not completely.
It cannot be divided with 3, right? If we divide it by 3, its value will be Zero point something.
It will be something like that.
So, here the logic is that the number that we have, it would be divided only by the half value of that number, right? like we have got the value 10, so our10 would not be divided by 6 completely, which means 10s half which is 5, till there we can try to divide the 10, it can be by 1, by 2, it will not happen by 3 completely, but it can happen by 5 but, as soon as we want to divide it with the number more than it's half, if you try to divide 10 by six, it will never be completely divided, it can be 10 divided by 7, 10 divide by 8, 10 divided by 9.
Till the time the number itself will not come, which means till the time it is not 10 divided by 10.
Till that time it cannot be divided by any other number.
So, here the logic is that suppose my number is 10, its half that is there, till there we will divide and check from which number it is getting divided because if we try to divide after the number’s half, it will never perfectly divide and give us.
So, here the concept here is that if our number in N then till N/2 we can divide all the numbers and see one by one.
As soon as n/2 number comes to us.
After that we will stop the division process.
And then we will print the conclusion that has come.
Taking ahead this process or this logic we have written one for loop, we have not written an entire program here, you might have to write the entire program but, for now, just for the understanding we have written one for loop here and in for loop we have started i with 2.
You can see that we have initialised i with 2.
Here why we have not initialised it with 1? Because if we see, 1 basically, obviously divides every number, so it is not necessary to divide it and check.
So, we have started to divide it by 2.
Now you can see that our condition is i less than equal to n by two.
So, we have a number which we have stored in n variable and we have to divide it and check whether it's a prime number or not.
We will divide it one by one and we will start with 2.
With 1 every number gets divided.
So, we will divide it by 2 and see whether n is coming out as a prime number or is it getting perfectly divided or not? In that case, we will start with 2 and we will only divide it by n/2 because we have just spoken about it that n/2, which means till any numbers half value are the only chances of the number getting completely divided.
And after half it cannot be completely divided after half, till the time it doesn't divide by its own number.
That's why we will run the loop only till n/2 for the i’s value and here we have put the increment operator.
Now, we will come inside our for loop and here you can see that we have put a condition to check the non-prime number.
So, you can see here now that we have a percentage sign here and what is written in if condition is that whichever number is mod of i and we will check the remainder that will come, the remainder is equal to zero or not.
I’s value will start from2, then it will 3, 4 and till n/2, it will go on.
So, here whichever number is there, let's suppose it is 10.
So, 10 divided by, if i’s value is two.
So, we will divide 10 by 2 and check i’s value and if it comes equal to zero.
So, we will write here, flag=1.
Now, what is this flag, flag is the variable that we have made and what is the condition that we will be keeping in it, after our entire for loop gets over, the flag remains zero because at the start we have initialised the flag variable with zero, we have assigned it.
So, if after our entire for loop gets over, flags value is zero.
So, our number is prime, if it successfully satisfies this condition and the number comes in the if condition.
We will make the flag’s value as one and going ahead after it comes into the for loop, we will tell that flag’s value has become one because of which this is not a prime number.
This is a composite number, in this way, we will also break it and again our for loop will not be working.
So, we will take 10 number over here and one by one we will divide 10 and check whether this number is prime or not.
So, we have started from i, 2 and in n we have kept 10.
So here our 10 comes in this for loop.
And we can see that when 10 mod of i’s value is 2.
So, 10 mod of two ==0.
So, what does this means? It means that this condition is successful.
And in if statement will come our compiler.
And here you can see that now we have equal the flag with 1.
After that it will also break.
So, after breaking, for loop will not work again.
And we will get a conclusion here, that ahead of for loop, we are again putting a condition and checking that the flag’s value was 0 or it became 1.
If the value has become 1.
If its value has become 1, we would say that the number that you have given was not prime, it was composite.
And it the flag’s value was left at 0.
So, we would say that your number is a prime number.
So, we will test this with a real prime number.
If we consider n’s value as 3.
Then we have again come into the for loop and you can see here that here 3/2 is 1.5.
It is 1.5, so what does this mean? We will be running it till the time it is 1 or less than 1.
So, as soon as we will enter the for loop.
You can see that the condition itself is not getting satisfied.
Because i we have started with 2.
And when we talk about the condition, 3/2 becomes 1.5 and i is bigger than 1.5, which means 2 is bigger than 1.5.
At the start itself while entering the for loop, that condition will not be satisfied.
So, our flag’s value will also never be 1.
So, because of that if we write out of the for loop and we will check if the flag’s value was 0 or 1.
At that time, flag’s value will remain zero.
And with this it will proved that the 3 number that you had passed, is a prime number.
So, in this way you can design the logic.
Prime number can have a slightly different logic.
We can approach any concept differently can use the logic and we can write the entire program.
Here we have one more assignment for you, you have to write the entire prime number’s logic.
Where you will take the number from the user and then we will check if that number is prime or not.
If it is prime, you will print that your number is prime.
If it is not prime.
The number provided is composite.
So, these types of questions can be asked to you in the interviews, related to the C programming.
Apart from these questions, there are many such questions which will be asked by them in the interview when you would be giving C programming interviews.
So, in this you have to pay attention that you have understood all the concepts of C programming thoroughly.
And any question related to any concept comes to you in the interview, you can easily solve it, this is basically you have to pay attention to.
So, you have to read these questions and go, no matter which interview you go to.
Along with this you have to keep in the mind other concepts of C programming, so that you can answer any question.
So, you keep practising C programming.
We will meet you later.
If you think that
there is any part of this video or this topic, you might have not understood
then you can ask us any query or question related to that topic without any inhibition.
You just have to go on forums.learnvern.com, you have to type your query there in your own language and we will come up with the solution or the answer as soon as possible in your own language.
Apart from this if you wish to have a discussion on any topic.
Even that you will be able to do on forums.learnvern.com.

See More
## Share a personalized message with your friends.