C Programming Interview Questions

C programming interview questions

C is the general and basic programming language that will create a base for other programming languages. C programming language was designed by Dennis Ritchie in Bells Lab. And it appeared around 46 years ago that is in 1972 and it was stably established on 11 December 2011. It is a crucial language of computer and it is coded in assembly language and it can run on from supercomputers to the embedded systems. ANSI C (American National Standards Institute) has standardized the C programming language since 1989 and even by the International Organization for Standardization (ISO).

Read Top C programming interview questions and answers

Download C programming interview questions PDF

C programming interview questions

Flag values are used to make decisions between two or more options during the execution of a program. Generally, flag values are small (often two) and it tries to save space by not storing each flag according to its own data type.

The best way to store flag values is to keep each of the values in their own integer variable. If there are large number of flags, we can create an array of characters or integers. We can also store flag values by using low-order bits more efficiently.

Bit fields are used to store multiple, logical, neighboring bits, where each of the sets of bits and single bits can be addressed.

Bit masking refers to selecting a particular set of bits from the byte(s) having many values of bits. Bit masking is used to examine the bit values and can be done by 'AND' operation of byte, bitwise.

Call by value: 
A process in which the values of the actual parameters sent by the calling function are copied to the formal parameters of the called function.

Call by reference: 
A process in which the parameters of a calling function are passed to the parameters of the called function using an address.

C language allows the use of the prefix register in primitive variable declarations. Such variables are called register variables and are stored in the registers of the microprocessor. The number of variables which can be declared register are limited. If more variables are declared register variables, they are treated as auto variables. A program that uses register variables executes faster as compared to a similar program without register variables. It is possible to find out the allocation of register variables only by executing and comparing the performance with respect to the time taken by the program (perceptible in large programs). It is the responsibility of the compiler to allow register variables.

In case the compiler is unable to do so, these variables are treated as auto variables. Loop indices, accessed more frequently, can be declared as register variables. For example, index is a register variable in the program given below.

//Illustration of register variables in C language

#include <stdio.h>
#include <string.h>
int main()
{
  char Name[30];
  register int Index;
 
  printf( "Enter a string: ");
  gets( Name );
 
  printf( "The reverse of the string is : ");
  for( Index = strlen( Name ) - 1; Index >= 0; Index-- )
	  printf( "%c", Name[Index]);
  printf( "\n" );
  return 0;
}
OutPut:
Enter a string: Apple is Red
The reverse of the string is : deR si elppA

The printf is a library function that prints output. requires the \n newline character, even separately like printf(“\n”);. The first argument is the string of characters to be printed, with each % indicating where one of the other arguments is to be substituted, and in what form it is to be printed.

A pointer can be used with a function-

  • When an address is to be passed to a function
  • When an array elements are to be accessed through a function. Passing base address will give access to the whole array.

Recursion: A function, which calls itself, recursion is simple to write in program but takes more memory space and time to execute.

Advantages of using recursion:-

  • Avoid unnecessary calling of functions
  • Substitute for iteration
  • Useful when applying the same solution

Factorial program in c using Recursion

#include 

int factorial(unsigned int i) {

   if(i <= 1) {
      return 1;
   }
   return i * factorial(i - 1);
}

int  main() {
   int i = 15;
   printf("Factorial of %d is %d\n", i, factorial(i));
   return 0;
}

Yes. As pointers have access to a particular memory location, the security level decreases and restricted memory areas can be accessed. Other demerits include memory holes, process and memory panics, etc.

In Programming Languages data types are used to define a variable before its use.

Below are list of some basic data types in C language.

  • Integer: used to define integer numbers, denoted as int
  • Floating point: decimal
  • Character: defines character
  • Void: void type has no value and only one operation: assignment. Plays a role of generic data type.

Void pointer is a generic pointer in programming. If the pointer type is unknown, we make use of the void pointer.

Normalization is the process by which an address is converted to a form such that if two non-normalized pointers point to the same address, they both are converted to normalized form, thereby having a specific address

Continue is a jump statement that transfers control back to the beginning of the loop, bypassing any statements that are not yet executed. It can be used only in an iteration statement.

Application of C Programming Language

  • To develop embedded software
  • It is to create a computer application
  • It is effective to create a compiler for various computer languages to convert them into low-level language that is the machine understandable language.
  • It can be used to develop an Operating system and UNIX is one which is developed by the C .programming language.
  • It is used for creating software for various applications and even hardware.