Basic Programming Interview Question Answers
This is a simple collection of problems for interview from the basic knowledge of C programming.
Part 1: Write Short Procedure or Pseudocode
 Write a program to print numbers from 1 to 100 without using loops.
 Write a C program to swap two variables without using a temporary variable.
 What is the 8 queens problem? Write a C program to solve it?
 Write a C program to print a square matrix helicaly.
 Write a C program to reverse a string.
 Write a C program generate permutations.
 Write a C program for calculating the factorial of a number.
 Write a C program to calculate pow(x,n)?
 How do you calculate the maximum sum of a list of numbers?
 How to generate fibonacci numbers with recurison? Can you optimize it?
 Solve the Rat In A Maze problem using backtracking.
 Write C code to solve the Tower of Hanoi problem (generalize form).
 Write a C program which produces its own source code as its output.
 Write a C program to convert from decimal to any base (binary, hex, oct etc…).
 Write C code to check if an integer is a power of 2 or not in a single line?
 Write a C program to find the GCD of two numbers.
 Write code to remove duplicates in a sorted array.
 Find the maximum of three integers using the ternary operator.
 Write C code to dynamically allocate one, two and three dimensional arrays (using malloc()).
 How would you find the size of structure without using sizeof()?
 Write a C program to multiply two matrices.
 Write a C program to check for palindromes.
 Write a C program to convert a decimal number into a binary number.
 Write C code to implement the Binary Search algorithm.
 How do you compare floating point numbers?
 Write a program to check if a given year is a leap year or not?
 Is there something we can do in C but not in C++?
 Can you write general sieve method for finding prime numbers?
 What is the difference between scanf(“%s”, str) and gets(str)?
 Write your own sqrt() function in C.
 How can we sum the digits of a given number in single statement?
Part 2: Find The Output
1. Find the output –


2. What is the value of EOF..??
Ans: 1
3. What is the output?


Ans: 1
4. What is the output?


Ans: 4 4
5. What is the output?


Ans: electronicsia
Explanation: printf(“electronics”) first print “electronics” and return a int value which the length of the string, that means 11, adding this 11 to the address of the “samsung india” will eventually point 11th character results in printing “ia”.
6. What is the output?


Ans:
7. What is the output?


Ans: linker error
8. How to access the next element of arr?
struct book arr\[10\];
Ans: Since arr is an array of 10 variables of book type, so to access the next element add the sizeof(struct)
in the base address of the arr.
9. What is the output?


Ans: case constant already used..10 and 5*2 are same..error
Part 3: OS Related
 Threads don’t share their ****___********with other threads. Ans: stack,register,and counter
 Advantage of using large pages and small pages in paging ****___****.
 Which program loads first when system starts? Ans: bootstrap loader.
 What does CPU do when interrupt occurs? Ans: CPU at once switches over it control to the interrupt.
 Technique used for avoiding page fault frequency? ans:locality of reference.
Part 4: Data Structure
 Recursive function uses more******__******than non recursive function. Ans: stack space.
 In heap each node is ___. Ans: each node is greater than its left and right child node.
 Complexity of binary search. Ans: nlognr
 Total no. of nodes in a full binary tree of 4 levels. Ans:15