C Interview Questions – Set 02

When was C language developed?

C language was developed in 1972 at bell laboratories of AT&T.

What is an array in C?

An Array is a group of similar types of elements. It has a contiguous memory location. It makes the code optimized, easy to traverse and easy to sort. The size and type of arrays cannot be changed after its declaration.

Arrays are of two types:

One-dimensional array: One-dimensional array is an array that stores the elements one after the another.
Syntax:

data_type array_name[size];
Multidimensional array: Multidimensional array is an array that contains more than one array.
Syntax:

data_type array_name[size];

What is the difference between getch() and getche()?

The getch() function reads a single character from the keyboard. It doesn’t use any buffer, so entered data will not be displayed on the output screen.

The getche() function reads a single character from the keyword, but data is displayed on the output screen. Press Alt+f5 to see the entered character.

What is pointer to pointer in C?

In case of a pointer to pointer concept, one pointer refers to the address of another pointer. The pointer to pointer is a chain of pointers. Generally, the pointer contains the address of a variable. The pointer to pointer contains the address of a first pointer.

What is an auto keyword in C?

In C, every local variable of a function is known as an automatic (auto) variable. Variables which are declared inside the function block are known as a local variable. The local variables are also known as an auto variable. It is optional to use an auto keyword before the data type of a variable. If no value is stored in the local variable, then it consists of a garbage value.

Write a program to reverse a given number in C?

#include
#include
main()
{
int n, reverse=0, rem; //declaration of variables.
clrscr(); // It clears the screen.
printf(“Enter a number: “);
scanf(“%d”, &n);
while(n!=0)
{
rem=n%10;
reverse=reverse*10+rem;
n/=10;
}
printf(“Reversed Number: %d”,reverse);
getch(); // It reads a character from the keyword.
}

What are the functions to open and close the file in C language?

The fopen() function is used to open file whereas fclose() is used to close file.

Write a program to print Fibonacci series using recursion?

#include
#include
void printFibonacci(int n) // function to calculate the fibonacci series of a given number.
{
static int n1=0,n2=1,n3; // declaration of static variables.
if(n>0){
n3 = n1 + n2;
n1 = n2;
n2 = n3;
printf(“%d “,n3);
printFibonacci(n-1); //calling the function recursively.
}
}
void main(){
int n;
clrscr();
printf(“Enter the number of elements: “);
scanf(“%d”,&n);
printf(“Fibonacci Series: “);
printf(“%d %d “,0,1);
printFibonacci(n-2);//n-2 because 2 numbers are already printed
getch();
}

What is the purpose of sprintf() function?

The sprintf() stands for “string print.” The sprintf() function does not print the output on the console screen. It transfers the data to the buffer. It returns the total number of characters present in the string.

What are the features of the C language?

The main features of C language are given below:

Simple: C is a simple language because it follows the structured approach, i.e., a program is broken into parts
Portable: C is highly portable means that once the program is written can be run on any machine with little or no modifications.
Mid Level: C is a mid-level programming language as it combines the low- level language with the features of the high-level language.
Structured: C is a structured language as the C program is broken into parts.
Fast Speed: C language is very fast as it uses a powerful set of data types and operators.
Memory Management: C provides an inbuilt memory function that saves the memory and improves the efficiency of our program.
Extensible: C is an extensible language as it can adopt new features in the future.