Skip to main content

Interview Related C Programming Questions and Answers

C Programming Interview Questions and Answers


Here are some of the most frequently asked C Programming questions in the interview time. Refer this blog further for head "Your Hired!" at the interview time.☺so, let's get star.

1) What is C language?

C is a high-level and general-purpose programming language that is ideal for developing firmware or portable applications. Originally intended for writing system software, C was developed at Bell Labs by Dennis Ritchie for the Unix Operating System in the early 1970s.
_________________________________________________________________________________

2) Why C is known as a mother language?

C language is considered as the mother language of all the modern languages because most of the compilers, JVMs, Kernals etc. are written in C language and most of languages follows c syntax e.g. C++, Java etc.

It provides the core concepts like array, functions, file handling etc. that is being used in many languages like C++, java, C# etc.
_________________________________________________________________________________

3) Why C is called a mid level programming language?

C is called middle-level language because it is actually bind the gap between a machine level language and high-level languages. User can use c language to do System Programming (for writing operating system) as well as Application Programming (for generate menu driven customer billing system ).
_________________________________________________________________________________

4) What are the features of C language?

C is the widely used language. It provides a lot of features that are given below.

1. Simple
2. Machine Independent or Portable
3. Mid-level programming language
4. Structured programming language
5. Rich Library
6. Memory Management
7. Fast Speed
8. Pointers
9. Recursion
10.Extensible
_________________________________________________________________________________

5) What is the use of printf() and scanf() functions?


printf scanf in C

The printf() and scanf() functions are used for input and output in C language. Both functions are inbuilt library functions, defined in stdio.h (header file).

printf() function

The printf() function is used for output. It prints the given statement to the console.

scanf() function

The scanf() function is used for input. It reads the input data from the console.
_________________________________________________________________________________

6) What is the difference between call by value and call by reference in C?

We can pass value to function by one of the two ways: call by value or call by reference. In case of call by value, a copy of value is passed to the function, so original value is not modified. But in case of call by reference, an address of value of passed to the function, so original value is modified. 
_________________________________________________________________________________

7) What is recursion in C?

When function is called within the same function, it is known as recursion in C. The function which calls the same function, is known as recursive function.

A function that calls itself, and doesn't perform any task after function call, is know as tail recursion. In tail recursion, we generally call the same function with return statement. An example of tail recursion is given below.

Let's see a simple example of recursion.

recursionfunction()
{  
recursionfunction();//calling self function  
}

Example of tail recursion in C

Let's see an example to print factorial number using tail recursion in C language.

#include<stdio.h>  
#include<conio.h>  
int factorial (int n)  
{  
    if ( n < 0)  
        return -1; /*Wrong value*/  
    if (n == 0)  
        return 1; /*Terminating condition*/  
    return (n * factorial (n -1));  
}  
  
void main(){  
int fact=0;  
clrscr();  
fact=factorial(5);  
printf("\n factorial of 5 is %d",fact);  
  
getch();  
}  

Output

factorial of 5 is 120
We can understand the above program of recursive method call by the figure given below:

_________________________________________________________________________________

8) What is pointer in C?

The pointer in C language is a variable, it is also known as locator or indicator that points to an address of a value.

Advantage of pointer

1) Pointer reduces the code and improves the performance, it is used to retrieving strings, trees etc. and used with arrays, structures and functions.

2) We can return multiple values from function using pointer.

3) It makes you able to access any memory location in the computer's memory.
_________________________________________________________________________________

9) What are the usage of pointer in C?

1. Accessing array elements
2. Dynamic memory allocation
3. Call by Reference
4. Data Structures like tree, graph, linked list etc.
_________________________________________________________________________________

10) What is NULL pointer in C?

A pointer that doesn't refer to any address of a value but NULL, is known as NULL pointer. For example:

int *p=null;
_______________________________________________________________________________

11) What is far pointer in C?

A pointer which can access all the 16 segments (whole residence memory) of RAM is known as far pointer.
_______________________________________________________________________________

12) What is dangling pointer in C?

If a pointer is pointing any memory location but meanwhile another pointer deletes the memory occupied by first pointer while first pointer still points to that memory location, first pointer will be known as dangling pointer. This problem is known as dangling pointer problem.
_______________________________________________________________________________

13) What is static and dynamic memory allocation?

static memory allocationdynamic memory allocation
memory is allocated at compile time.memory is allocated at run time.
memory can't be increased while executing program.memory can be increased while executing program.
used in array.used in linked list.

Static memory allocation
        In case of static memory allocation, memory is allocated at compile time and memory can't be increased while executing the program. It is used in array.

Dynamic memory allocation
        In case of dynamic memory allocation, memory is allocated at run time and memory can be increased while executing the program. It is used in linked list.
_________________________________________________________________________________

14) What is the difference between malloc() and calloc()?

malloc(): The malloc() function allocates single block of requested memory. It has garbage value initially.

calloc(): The calloc() function allocates multiple block of requested memory. It initially initializes all bytes to zero.
_______________________________________________________________________________

15) What is the purpose of sprintf() function?

It is used to print the formatted output into char array.
_______________________________________________________________________________

16) Can we compile a program without main() function?

Yes, we can compile but it can't be executed.
But, if we use #define, we can compile and run C program without using main() function. For example:
#include<stdio.h>
#define start main
    void start() 
{
       printf("Hello");
    }
_______________________________________________________________________________

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

The getch() function reads a single character from keyboard. It doesn't uses any buffer, so entered data is not displayed on the output screen.

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

18) What is the difference between near, far and huge pointers?

A virtual address is composed of selector and offset.

near pointer doesn't have explicit selector whereas far and huge pointers have explicit selector. When you perform pointer arithmetic on far pointer, selector is not modified but in case of huge pointer it can be modified.

These are the non-standard keywords and implementation specific. These are irrelevant in modern platform.
_______________________________________________________________________________

19) Write a program to print "hello world" without using semicolon?

There are various ways to do so. Let's see a program to print "hello world" using if.

  1. #include<stdio.h>    
  2. void main(){    
  3.    if(printf("hello world")){}    
  4. }    
_______________________________________________________________________________

So,these are some important interview question that might be helpful you in your interview.
Here are some C Programs which also ask you in exam. Refer that at least one time.




Comments

Popular posts from this blog

15 Amazing Websites You Should Know- Make Your Work Easy

15 Amazing Websites You Should Know Hello Reader, Today i'm going to share some websites which are very useful in our college life and for other stuff which we like to do. Internet have to millions of millions websites and lots of websites names and it's functionalities we don't know.So,here top 15 amazing websites which you should know and use it in your work. So,lets get started. 1.  http://www.zamzar.com/ Zamzar is an online file converter, It allows user to convert files without downloading a software tool, and supports over 1,000 different conversion types. You just need to upload your file and the choose your file in which you want to convert and the hit the submit. You can also use different options like manage files,URL converter and develop API. It's have four simple steps and you get converted file through e-mail.It have almost all the option for file conversion. Here the look of the website. 2.   https://www.mailinator.com/  ...

Basic Introduction of Python (about libraries)

Basic Introduction on Python Hello Guys, Today i'm going to taking about python programming language.I'm going to make some other blog for more on python programming language.So i hope you get something from this blog and if you have any question then ask i will solve your queries. Python is a widely used high-level programming language for general-purpose  programming, created by Guido van Rossum.  Aninterpreted language, Python has a design philosophy which emphasizes code readability (notably using whitespace indentation to delimit code blocks rather than curly braces or keywords), and a syntax which allows programmers to express  concepts in fewer lines of code than possible in languages such C++ or Java.  It is a high-level open source programming language. It is a powerful ,fast and dynamic. It is Object-oriented and Inheritance which is easy to lean. In C programming language or any language when our application or project require s...