Interview Questions.

Top 100+ Basic C Interview Questions And Answers


Top 100+ Basic C Interview Questions And Answers

Question 1. What Are Volatile Variables?

Answer :

Volatile variables get special attention from the compiler. A variable declared with the volatile keyword can be modified externally from the putting forward characteristic.
If the keyword volatile isn't used, the compiler optimization algorithms might don't forget this to be a case of countless loop. Declaring a variable volatile shows to a compiler that there could be outside procedures that would possibly alter the price of that variable.

A variable that might be concurrently changed via multiple threads may be declared risky. Variables declared to be volatile will no longer be optimized by using the compiler. Compiler have to expect that their values can exchange at any time. However, operations on a risky variable are nevertheless no longer guaranteed to be atomic.
Question 2. Explain The Meaning Of "segmentation Violation"?

Answer :

A segmentation violation generally suggests an try and access reminiscence which doesn't even exist. 

Segmentation violation typically happens at the time of a application’s attempt for accessing memory place, which isn't always allowed to get admission to. The following code need to create segmentation violation.

Most important() 

char *hi there = “Hello World”;

*hello = ‘h’;

At the time of compiling this system, the string “hi there world” is located within the binary mark of the program that's read-only marked. When loading, the compiler locations the string along side different constants in the read-handiest segment of the memory. While executing a variable *hi there is ready to factor the character ‘h’ , is tried to put in writing the person ‘h’ into the memory, which cause the segmentation violation. And, compiler does now not take a look at for assigning study handiest locations at bring together time.

DBMS Interview Questions
Question 3. What Is "bus Error"?

Answer :

A bus errors indicates an attempt to access memory in an unlawful way,possibly because of an unaligned pointer. 

A ‘bus mistakes’ is positive undefined behavior end result type. The reason for such mistakes on a gadget couldn't be targeted by way of the C language. The memory accessibility which CPU couldn't deal with bodily, ‘bus errors’ occurs. Also, any fault detected with the aid of a tool by the pc gadget can also be a ‘bus error’. These errors as a result of applications that generate undefined behavior which C language no longer specifies what can take place.

Question 4. Define Recursion In C.?

Answer :

A programming method in which a function may also name itself. Recursive programming is particularly well-proper to parsing nested markup structures 
Calling a function by way of itself is referred to as recursion. Any function can call any feature such as itself. In this state of affairs, if it takes place to invoke a characteristic with the aid of itself, it's far recursion. One of the commands within the feature is a name to the characteristic itself, typically the closing announcement. In some ways it is much like looping. When the end result of ‘one time name of a characteristic is the enter for the next time call of the function’, recursion is one of the exceptional approaches. For instance, calculating factorial, wherein the fabricated from preceding digit factorial is the enter for the following digit’s factorial.
The system of calling a function with the aid of itself is referred to as recursion. Recursion is normally used whilst the end result of the modern characteristic name is the enter to the successive call of itself. For example, ‘factorial of a digit’. By definition, the factorial of the cutting-edge digit is the factorial of its previous digit and the digit. In order to get the factorial of the previous digit, the same characteristic need to return the factorial.
Thus the result of the preceding execution of the characteristic is one of the inputs of the contemporary execution. The technique continues until an exit condition returns authentic.
C#. NET Tutorial
Question 5. What Does Static Variable Mean In C?

Answer :

Static variable is available to a C application, at some stage in the life time. At the time of beginning this system execution, static variables allocations takes vicinity first. In a state of affairs in which one variable is to be used by all of the features (that is accessed by using predominant () characteristic), then the variable want to be declared as static in a C program. The fee of the variable is continued among successive calls to capabilities. One more massive function of static variable is that, the address of the variable may be surpassed to modules and functions which aren't inside the same C file.

Static is an get entry to qualifier that limits the scope however reasons the variable to exist for the lifetime of this system. This way a static variable is one which isn't visible out of doors the feature in which it's miles declared but which stays till the program terminates. It also manner that the value of the variable persists between successive calls to a characteristic. The value of this kind of variable will remain and may be seen even after calls to a function. One extra factor is that a declaration assertion of the sort of variable inner a function may be achieved simplest once.

C#. NET Interview Questions
Question 6. List Out Differences Between Structures And Arrays?

Answer :

The following are the differences among systems and arrays:

Array elements are homogeneous. Structure elements are of various information kind. 
Array allocates static memory and uses index / subscript for having access to elements of the array. Structures allocate dynamic reminiscence and makes use of (.) operator for having access to the member of a structure.
Array is a pointer to the first detail of it. Structure isn't a pointer
Array element get right of entry to takes much less time in assessment with systems.
Question 7. Define Macros. What Are The Advantages And Disadvantages Of Macros?

Answer :

A macro is a call given to a block of C statements as a pre-processor directive. Being a pre-processor, the block of code is communicated to the compiler earlier than getting into the actual coding (most important () feature). A macro is defined with the preprocessor directive, #define.

The benefit of using macro is the execution velocity of this system fragment. When the actual code snippet is for use, it may be substituted by using the call of the macro. The same block of statements, alternatively, want to be time and again hard coded as and when required.

The downside of the macro is the scale of this system. The reason is, the pre-processor will update all the macros inside the application by its real definition previous to the compilation process of the program.

Adv Java Tutorial Adv Java Interview Questions
Question 8. List Out Differences Between Pass By Reference And Pass By Value?

Answer :

Pass via price usually invokes / calls the characteristic or returns a fee this is primarily based on the cost. This value is surpassed as a consistent or a variable with cost.

Pass by way of reference continually invokes / calls the feature by means of passing the deal with or a pointer to a memory region which contains the value. The memory vicinity / pointer is populated with a cost, so the characteristic may want to study the price via that region. The function can update the fee available within the reminiscence place by referencing the pointer. 

A string in C language is exceeded by way of reference.

Question nine. Define Static Identifier In C?

Answer :

The static identifier is used for initializing best as soon as, and the cost retains during the lifestyles time of this system / utility. A separate memory is allotted for ‘static’ variables. This value can be used between characteristic calls. 

The default value of an uninitialized static variable is 0. A function can also be described as a static characteristic, which has the identical scope of the static variable.

Microsoft Entity Framework Interview Questions
Question 10. What Are The Auto Variables? Where Are They Stored?

Answer :

The car variables are stored in the most important memory of the device.
The key-word 'vehicle' is optional. 
Many of the variables utilized by this system or application are 'vehicle' variables, being the main reminiscence is quicker. 
These variables are stored inside the reminiscence runtime stack.
It is de-allocated at the of completion of its block execution.
It is a neighborhood variable that is allotted and deallocated automatically when this system drift enters and leaves the variable's scope.
Microsoft Entity Framework Tutorial
Question eleven. List Out Differences Between Arrays And Linked List?

Answer :

The difference among arrays and connected lists are:

Arrays are linear information systems. Linked lists are linear and non-linear information systems. 
Linked lists are linear for accessing, and non-linear for storing in reminiscence
Array has homogenous values. And every detail is independent of each other positions. Each node in the related list is connected with its preceding node which is a pointer to the node. 
Array factors can be changed without problems via figuring out the index cost. It is a complex method for modifying the node in a related listing.
Array elements can not be introduced, deleted as soon as it's miles declared. The nodes in the connected listing may be brought and deleted from the list.
LINQ Interview Questions
Question 12. Explain The Term Enumerations In C?

Answer :

A set of named integer constants is referred to as an enumeration. The enumeration kind statement includes the call of the enumeration tag and the definition of a set of named integers. 

Ex: enum CITY  Mumbai, Bangalore, Chennai, NewDelhi  metros ;

Variables of enumeration kind persists one of the current values of the enumeration set. The enum type variables might be applied in indexing expressions, as operands of all mathematics and relational operators. ANSI C enum expressions are usually have int type, which occupies the memory area that occupied by the int kind. 


enum DAY /* Defines an enumeration kind */

saturday, /* Names day and proclaims a */

sunday = 0, /* variable named workday with */ 

monday, /* that kind */


wednesday, /* wednesday is associated with three */




saturday inside the above example is related to cost 0 by using default. The identifier sunday is explicitly assigned with 0. The final identifiers are given values 1 thru 5 through default.

DBMS Interview Questions
Question 13. Describe About Storage Allocation And Scope Of Global, Extern, Static, Local And Register Variables?

Answer :

The storage allocation / magnificence decide the reminiscence element in which the storage space is allocated for variables, capabilities and how long the allocation of storage maintains to exist. 

The scope of a variable is special by using its storage allocation. This is designated by the keywords – car, extern, static and register.

‘vehicle’ variables stores in the reminiscence garage. Majority of the variables in a program / software are of kind ‘automobile’. Their scope might be local or international.
‘extern’ variables are of world variables and can be declared in some other supply report which can be outside / outdoor the contemporary software scope,
‘register’ variables are allotted within the CPU registers. These variables storage and accessibility is plenty faster than different variables, being they may be stored in CPU itself. The variables of repeated utilization or get entry to time is important, may be declared as sign in variables.
‘static’ variables offers a life-time over the program, and gives a manner for limiting the scope of such variables. These variables are mechanically initialized to 0 and might be exact for ‘car’ and ‘extern’ variables. The values are retained, despite the fact that they're declared in local scope, among the repeated characteristic calls to the same feature.
LINQ Tutorial
Question 14. What Is The Use Of Typedef?

Answer :

The keyword typedef is used for defining person defined statistics kinds. A new definition of existing records sorts is created by the usage of typedef. It is used to outline person described identifiers which may be utilized in substitution of kind specifiers including int, float etc. It does not reserve memory area. The names described by using typedef are synonyms for the records sorts.

For instance typedef int integer;

Instead of int the brand new definition integer may be used for higher clarity.

Question 15. Can We Specify Variable Field Width In A Scanf() Format String? If Possible How?

Answer :

It is possible to specify variable field width in a scanf() format string by using the usage of %s manage string.
The %s reads a string of variable discipline width as much as the primary white area man or woman.

scanf("%s", call);   // where name is a person array

The scanf() shops the effects away in variables which you offer within the argument listing and reads the statistics from the console or from a FILE circulate and parses it.
Windows Presentation Foundation(WPF) Interview Questions
Question 16. Out Of Fgets() And Gets() Which Function Is Safe To Use And Why?

Answer :

The fgets() characteristic is safer to apply.
It assessments the bounds, i.E., the size of the buffer and does no longer purpose overflow at the stack to arise. 
The gets() function does now not check the bounds.
The receives() characteristic is an insecure and careless use can result in errors.
Windows Presentation Foundation(WPF) Tutorial
Question 17. List Out Differences Between Strdup() And Strcpy()?

Answer :

The feature strcpy() will no longer allocate the reminiscence area to duplicate. A pointer to the string to replicate and a pointer to location to duplicate it to need to accept.

The function strdup() will occupy / grab itself the memory area for copying the string to. This memory area desires to be freed up later whilst it is of little need anymore.

Windows Communication Foundation (WCF) Interview Questions
Question 18. What Is The Difference Between Char *a And Char A[]?

Answer :

For char[] array, such size isn't well-known through the compiler. If the scale is exact, the subsequent are the differences between char *a and char a[]:

The unary increment (++) or decrement (--) operators can not be used on arrays, where as they may be utilized in pointers (pointer mathematics).
The cope with of an element of the array is regular; where because the cope with of an element of the pointer isn't always.
The variable *a is a regular pointer, wherein as a[] isn't always.
The array cannot be assigned to some other array, wherein as the pointer to char can be assigned to any other char pointer.
The char array allocates same to size of the string, where because the char pointer holds simplest the cope with of the first person of the string.
C#. NET Interview Questions
Question 19. Define Void Pointer?

Answer :

A void pointer is pointer which has no designated statistics kind. The key-word ‘void’ is preceded the pointer variable, because the information kind isn't unique. It is also called a usual pointer. The void pointer can be pointed to any kind. If needed, the sort may be cast.

Ex: go with the flow *float_pointer; 

int *int_pointer;

void *void_pointer; 

. . . . . . . .

. . . . . . . .

Void_pointer = float_pointer;

. . . . . . . . 

. . . . . . . . 

Void_pointer = int_pointer;

A void pointer is commonly used as function parameters, whilst the parameter or return type is unknown.

Windows Communication Foundation (WCF) Tutorial
Question 20. What Is A Const Pointer?

Answer :

A const pointer isn't the pointer to regular, it's miles the consistent. For instance, int* const ptr; shows that ptr is a pointer, which is a consistent. A pointer is preceded with the aid of ‘*’. In the above example it is not, Hence it isn't the pointer to constant.
The ptr can't be used to point to some other integer. The integer pointed by using ptr can be modified. The const pointer can't be modified to factor to other memory place, due to the fact the pointer is steady
Data Structure & Algorithms Interview Questions
Question 21. Explain Memory Leak?

Answer :

An unwanted increase in applications is referred to as a memory leak is C language.
The intake of this system will increase inside the memory with the aid of an unintended consumption of the reminiscence. 
If the program is getting corrupted and outcomes in errors, it manner the memory leak. 
In case there's a leak by using any application, the characteristic of the machine may additionally forestall and violate running gadget files.
It is the sluggish lack of to be had pc memory while a program time and again fails to go back reminiscence that it has received for temporary use.
It will become exhausted and this system will become no longer to perform well.
It is the end result of a software worm.
Question 22. What Is Static Memory Allocation And Dynamic Memory Allocation?

Answer :

Static Memory Allocation: Memory is allocated for the declared variable by way of the compiler. The cope with may be acquired by way of the usage of ‘address of’ operator and can be assigned to a pointer. The reminiscence is allotted for the duration of compile time. Since maximum of the declared variables have static reminiscence, this sort of assigning the deal with of a variable to a pointer is called static memory allocation.

Dynamic Memory Allocation: Allocation of reminiscence at the time of execution (run time) is known as dynamic memory allocation. The features calloc() and malloc() aid allocating of dynamic memory. Dynamic allocation of reminiscence area is executed by way of the use of those features while value is returned by means of features and assigned to pointer variables.

Data Structure & Algorithms Tutorial
Question 23. What Is The Purpose Of Main( ) Function?

Answer :

The characteristic essential() calls / invokes different capabilities inside it. The execution of the program continually begins with predominant() feature.

The essential() characteristic is :

The first characteristic to begin a application
Returns int cost to the environment which referred to as this system
It may be known as recursively.
It is a person defined feature, except the name
Like other features, principal(zero feature can obtain arguments. It has a) argument depend and b) argument vector(string argument)
Dot Net Framework Interview Questions
Question 24. What Is The Difference Between #outline And Constant In C?

Answer :

A #define is used as on the spot steady or as a macro. Where as the constant is a variable whose fee can't change.
Pointer may be declared to a consistent, however no longer for #outline. 
#define can't outline externally, and there may be no manner to apply it for availability to the linker. Where because the consistent can be worldwide .
Adv Java Interview Questions
Question 25. What Are Storage Class In C?

Answer :

The scope and lifetime of a variable or / and feature inside a C application is defined via garage elegance. There are four garage lessons in C

auto - It is the default garage class for all variables and / or capabilities.

Check in - Allows for outlining variables to shop in CPU register in place of RAM. Unary operator isn't implemented for register variable.

Static – The static garage elegance allows the updated variable values available for the following time when the characteristic, in which the variable is defined , is invoked for the subsequent time.

Extern - It allows a global variable to be seen to all of the software documents / external files ( C applications).

Question 26. Define Register Variables. What Are The Advantages Of Using Register Variables?

Answer :

The variables of 'check in' kind modifier tell the compiler for storing the variables in a check in of the CPU.
These variables are saved inside the registers, so the velocity of processing is grow to be extra than the normal variables.
Advantages of Register variable:

Access optimization and velocity of program execution: The operations of these variables are faster through orders of importance.
It is beneficial when you need to refer a variable frequently.
It allocates fast reminiscence inside the form of a sign in.
It helps to hurry up application execution.
Advanced C# Interview Questions