What are static variables and functions?
The variables and functions that are declared using the keyword Static are considered as Static Variable and Static Functions. The variables declared using Static keyword will have their scope restricted to the function in which they are declared.
Differentiate between calloc() and malloc()
calloc() and malloc() are memory dynamic memory allocating functions. The only difference between them is that calloc() will load all the assigned memory locations with value 0 but malloc() will not.
Differentiate between Actual Parameters and Formal Parameters.
The Parameters which are sent from main function to the subdivided function are called as Actual Parameters and the parameters which are declared a the Subdivided function end are called as Formal Parameters.
C Interview Questions
Can a C program be compiled or executed in the absence of a main()?
The program will be compiled but will not be executed. To execute any C program, main() is required.
What do you mean by a Nested Structure?
When a data member of one structure is referred by the data member of another function, then the structure is called a Nested Structure.
What is a C Token?
Keywords, Constants, Special Symbols, Strings, Operators, Identifiers used in C program are referred to as C Tokens.
Advance C Interview Questions
What is Preprocessor?
A Preprocessor Directive is considered as a built-in predefined function or macro that acts as a directive to the compiler and it gets executed before the actual C Program is executed.
Why is C called the Mother of all Languages?
C introduced many core concepts and data structures like arrays, lists, functions, strings, etc. Many languages designed after C are designed on the basis of C Language. Hence, it is considered as the mother of all languages.
What is the purpose of printf() and scanf() in C Program?
“printf() is used to print the values on the screen. To print certain values, and on the other hand, scanf() is used to scan the values. We need an appropriate datatype format specifier for both printing and scanning purposes. For example,
%d: It is a datatype format specifier used to print and scan an integer value.
%s: It is a datatype format specifier used to print and scan a string.
%c: It is a datatype format specifier used to display and scan a character value.
%f: It is a datatype format specifier used to display and scan a float value.”
C Interview Questions
What is the main difference between the Compiler and the Interpreter?
Compiler is used in C Language and it translates the complete code into the Machine Code in one shot. On the other hand, Interpreter is used in Java Programming Language and other high-end programming languages. It is designed to compile code in line by line fashion.
Can I use int datatype to store 32768 value?
No, Integer datatype will support the range between -32768 and 32767. Any value exceeding that will not be stored. We can either use float or long int.
How is a Function declared in C Language?
“A function in C language is declared as follows,
return_type function_name(formal parameter list)
{
Function_Body;
}”
Advance C Interview Questions
What is Dynamic Memory allocation? Mention the syntax.
“Dynamic Memory Allocation is the process of allocating memory to the program and its variables in runtime. Dynamic Memory Allocation process involves three functions for allocating memory and one function to free the used memory.
malloc() – Allocates memory
Syntax:
1
ptr = (cast-type*) malloc(byte-size);
calloc() – Allocates memory
Syntax:
1
ptr = (cast-type*)calloc(n, element-size);
realloc() – Allocates memory
Syntax:
1
ptr = realloc(ptr, newsize);
free() – Deallocates the used memory
Syntax:
1
free(ptr);”
Where can we not use &(address operator in C)?
We cannot use & on constants and on a variable which is declared using the register storage class.
Write a simple example of a structure in C Language
“Structure is defined as a user-defined data type that is designed to store multiple data members of the different data types as a single unit. A structure will consume the memory equal to the summation of all the data members.
struct employee
{
char name[10];
int age;
}e1;
int main()
{
printf(“”Enter the name””);
scanf(“”%s””,e1.name);
printf(“”n””);
printf(“”Enter the age””);
scanf(“”%d””,&e1.age);
printf(“”n””);
printf(“”Name and age of the employee: %s,%d””,e1.name,e1.age);
return 0;
}”
C Interview Questions
Differentiate between getch() and getche().
” Both the functions are designed to read characters from the keyboard and the only difference is that
getch(): reads characters from the keyboard but it does not use any buffers. Hence, data is not displayed on the screen.
getche(): reads characters from the keyboard and it uses a buffer. Hence, data is displayed on the screen.
//Example
include
include
int main()
{
char ch;
printf(“”Please enter a character “”);
ch=getch();
printf(“”nYour entered character is %c””,ch);
printf(“”nPlease enter another character “”);
ch=getche();
printf(“”nYour new character is %c””,ch);
return 0;
}”
Explain toupper() with an example.
“toupper() is a function designed to convert lowercase words/characters into upper case.
//Example
include
include
int main()
{
char c;
c=a;
printf(“”%c after conversions %c””, c, toupper(c));
c=B;
printf(“”%c after conversions %c””, c, toupper(c));”
Write a code to generate random numbers in C Language.
“Random numbers in C Language can be generated as follows:
include
include
int main()
{
int a,b;
for(a=1;a<=10;a++)
{
b=rand();
printf(“”%dn””,b);
}
return 0;
}”
Advance C Interview Questions
Can I create a customized Head File in C language?
It is possible to create a new header file. Create a file with function prototypes that need to be used in the program. Include the file in the ‘#include’ section in its name.
What do you mean by Memory Leak?
“Memory Leak can be defined as a situation where programmer allocates dynamic memory to the program but fails to free or delete the used memory after the completion of the code. This is harmful if daemons and servers are included in the program.
include
include
int main()
{
int* ptr;
int n, i, sum = 0;
n = 5;
printf(“”Enter the number of elements: %dn””, n);
ptr = (int*)malloc(n * sizeof(int));
if (ptr == NULL)
{
printf(“”Memory not allocated.n””);
exit(0);
}
else
{
printf(“”Memory successfully allocated using malloc.n””);
for (i = 0; i<= n; ++i)
{
ptr[i] = i + 1;
}
printf(“”The elements of the array are: “”);
for (i = 0; i<=n; ++i)
{
printf(“”%d, “”, ptr[i]);
}
}
return 0;
}”
Explain Local Static Variables and what is their use?
“A local static variable is a variable whose life doesn’t end with a function call where it is declared. It extends for the lifetime of the complete program. All calls to the function share the same copy of local static variables.
include
void fun()
{
static int x;
printf(“”%d “”, x);
x = x + 1;
}
int main()
{
fun();
fun();
return 0;
}”
C Interview Questions
What is the difference between declaring a header file with < > and ” “?
If the Header File is declared using < > then the compiler searches for the header file within the Built-in Path. If the Header File is declared using ” ” then the compiler will search for the Header File in the current working directory and if not found then it searches for the file in other locations.
When should we use the register storage specifier?
We use Register Storage Specifier if a certain variable is used very frequently. This helps the compiler to locate the variable as the variable will be declared in one of the CPU registers.
Which statement is efficient and why? x=x+1; or x++; ?
x++; is the most efficient statement as it just a single instruction to the compiler while the other is not.
Advance C Interview Questions
Can I declare the same variable name to the variables which have different scopes?
“Yes, Same variable name can be declared to the variables with different variable scopes as the following example.
int var;
void function()
{
int variable;
}
int main()
{
int variable;
}”
Which variable can be used to access Union data members if the Union variable is declared as a pointer variable?
Arrow Operator( -> ) can be used to access the data members of a Union if the Union Variable is declared as a pointer variable.
What are the different storage class specifiers in C?
“The different storage specifiers available in C Language are as follows:
auto
register
static
extern”
C Interview Questions
What is typecasting?
“Typecasting is a process of converting one data type into another is known as typecasting. If we want to store the floating type value to an int type, then we will convert the data type into another data type explicitly.
Syntax:
(type_name) expression;”
Write a C program to print hello world without using a semicolon (;).
include
void main()
{
if(printf(“”hello world””)){}
}
//Output:
hello world”
Write a program to swap two numbers without using the third variable.
include
include
main()
{
int a=10, b=20;
clrscr();
printf(“”Before swapping a=%d b=%d””,a,b);
a=a+b;
b=a-b;
a=a-b;
printf(“”nAfter swapping a=%d b=%d””,a,b);
getch();
}
//Output
Before swapping a=10 b=20
After swapping a=20 b=10″
Advance C Interview Questions
How can you print a string with the symbol % in it?
” There is no escape sequence provided for the symbol % in C. So, to print % we should use ‘%%’ as shown below.
printf(“there are 90%% chances of rain tonight”);”
How can you remove duplicates in an array?
“The following program will help you to remove duplicates from an array.
include
int main()
{
int n, a[100], b[100], calc = 0, i, j,count;
printf(“”Enter no. of elements in array.n””);
scanf(“”%d””, &n);
printf(“”Enter %d integersn””, n);
for (i = 0; i < n; i++)
scanf(“”%d””, &a[i]);
for (i = 0; i<n; i++)
{
for (j = 0; j<calc; j++)
{
if(a[i] == b[j])
break;
}
if (j== calc)
{
b[count] = a[i];
calc++;
}
}
printf(“”Array obtained after removing duplicate elementsn””);
for (i = 0; i<calc; i++)
{
printf(“”%dn””, b[i]);
}
return 0;
}”
Which structure is used to link the program and the operating system?
“The answer can be explained through the following points,
The structure used to link the operating system to a program is file.
The file is defined in the header file “stdio.h”(standard input/output header file).
It contains the information about the file being used, its current size and its location in memory.
It contains a character pointer that points to the character that is being opened.
Opening a file establishes a link between the program and the operating system about which file is to be accessed.”
C Interview Questions
What are the limitations of scanf() and how can it be avoided?
“The Limitations of scanf() are as follows:
scanf() cannot work with the string of characters.
It is not possible to enter a multiword string into a single variable using scanf().
To avoid this the gets( ) function is used.
It gets a string from the keyboard and is terminated when enter key is pressed.
Here the spaces and tabs are acceptable as part of the input string.”
Differentiate between the macros and the functions.
“The differences between macros and functions can be explained as follows:
Macro call replaces the templates with the expansion in a literal way.
The Macro call makes the program run faster but also increases the program size.
Macro is simple and avoids errors related to the function calls.
In a function, call control is transferred to the function along with arguments.
It makes the functions small and compact.
Passing arguments and getting back the returned value takes time and makes the program run at a slower rate.”
How binary trees are similar to the linked lists?
Here binary trees are the extension of the linked lists and linked lists are the nodes which are connected with each other in a list that list is called a linked list. This list can only be created by using the pointers. This helps in making efficient use of the memory space in a program. The binary list also takes the use of two-pointers and those pointers are right and left pointers. So basically every node has two pointers at the ends.
Advance C Interview Questions
Explain the meaning of queue and FIFO in C programming?
Queue is a kind of data structure present in the C programming and all the data present in this queue is stored in the format called FIFO. The full form of FIFO is first-in-first-out. In every queue, the first data is available on the first line.
What is the importance of linked list in the C programming?
When nodes are connected with each other, a list is called a linked list. This list can only be created by using the pointers. This helps in making efficient use of the memory space in a program.
What is the exact role played by sequential access file in C programming?
Its main function in C programming is to store and retrieve the data in the file and then transforming that file into different forms. These are always arranged and stored in sequential order. In order to get access to one particular file, we are facilitated by reading only one data at a time.
C Interview Questions
What do you know about logical errors and bring out the difference between syntax and logical errors.
“Logical errors: Logical errors always take place in complication processes and can pass it very easily, but we will not get the desired results in that case. Such errors occurred when we pass the wrong formula into code.
Syntax error: The mistakes that occur in the programming language is called syntax error. It usually takes place when the program misspells the command and because of that, it performs the wrong function. It can also take place when the command is to be given in lower case but by mistake, it is given in the upper case. Moreover, sometimes we make use of wrong symbols. All such problem and mistakes bring errors in the C programming.”
Explain the term memory leak and why it is important to know about this term in C programming?
Memory leak in C programming takes place when the memory is kept on storing in the memory space without deleting any information that had been used up in the process of coding. In such a situation there may be a chance of memory leak. This will definitely prove harmful for the user if the user has a daemon and servers in the program. This can leak the information to the competitors and other rivalry firms.
Explain the meaning and role of the auto keyword in the C programming?
Every local variable function present in C programming is called automatic or auto variable. It is very important to know that local variables are those variable that is inside the function block. The other name of the local variable is the auto variable. If the local value does not hold any key value in it then it will only show the garbage value.
Advance C Interview Questions
Explain the role of the union in C programming.
Union basically allows the user to store multiple types of data in a single unit and it is a kind of user-defined data. Its unique feature is that it does not store the memory of all the data entered into a program but it stores in the memory of the largest member only. This helps to solve the problem of overloading memory. In this, we can only have access to one kind of variable at one time.
What are the different types of array that are supported by C programming?
“When the elements of similar types are arranged together, that stage is called array and supports continuous memory location. It is also responsible for making the process of coding quite easy and it also makes that code sorted. These are array are generally of two types. The first one is one dimension array and other is a multidimensional array.
One dimension array: Here elements are stored in a process of sequence that is one element is stored after another.
Multi dimension array: The condition when the array contains more than one array, that situation is called a multi-dimension array.”
What are the different types of recursion supported by C programming? Also, explain its types.
“The process in which the function of C programming calls itself, that process is called recursion and the function that calls itself is known by the name of recursion function in C programming. This recursion is of two-phase. The first one is the winding phase and other is unwinding phase.
Winding Phase: When we reach a condition in the end while the function calls itself, then it is called a winding phase.
Unwinding Phase: It starts when condition-stage is reached, in this case, the control returns to its original call.”
C Interview Questions
For which purpose do we use the function in C programming?
“The use of functions are given as follows-
It does not allow the duplication of codes and information in the program. It means the rewriting of the same codes is avoided.
The function of C programming is also called any number of times and that can be from any place from our program.
The function helps track any kind of program very easily, which can only happen when the program is divided into functions.
It is very easy to break the big tasks into a smaller one thus it performs the unique function of reusability. This process of breaking down of data makes the C programming more understandable.”
Explain fast speed and memory management as a unique feature of C language?
“Fast speed: The operators and data types used in C programming are very effective and powerful that increases the speed of working. Hence it helps in fastening up the speed.
Memory management: It has a unique feature of building memory that can handle a large amount of data very effectively and efficiently. This helps in improving the overall performance of C programming.”
What is the exact meaning of C language in computer science?
C is a middle-level language that is also known as a structural programming language. because it has a very unique feature that makes it to act like a higher-level language. But at the same time, it facilitates to use low-level methods in interacting with hardware. It also supports the use of the English type of words in its functioning. All such feature makes it to act as high-level language. Moreover, it has a unique feature of storing the memory structure.
Advance C Interview Questions
Why do we generate random symbol in the C programming?
“Basically rand() command is used to generate the random symbol in the C programming.
For example- if we give the command for any Num equal to rand(), in that case, it will generate an integer in number that commence from 0, it should be considered that the number is a variable of type integer.”
What is the exact meaning of syntax error?
The mistakes that occur in the programming language is called syntax error. It usually takes place when the program misspells the command and because of that, it performs the wrong function. It can also take place when the command is to be given in lower case but by mistake, it is given in the upper case. Moreover, sometimes we make use of wrong symbols. All such problem and mistakes bring errors in the C programming.