Find frequently asked programs in technical interviews. The following C Programs are mostly asked in placement papers and intervies.
• Linked Lists Programs
o How do you reverse a singly linked list? How do you reverse a doubly linked list? Write a C program to do the same.
o Given only a pointer to a node to be deleted in a singly linked list, how do you delete it?
o How do you sort a linked list? Write a C program to sort a linked list.
o How to declare a structure of a linked list?
o Write a C program to implement a Generic Linked List.
o How do you reverse a linked list without using any C pointers?
o How would you detect a loop in a linked list? Write a C program to detect a loop in a linked list.
o How do you find the middle of a linked list? Write a C program to return the middle of a linked list
o If you are using C language to implement the heterogeneous linked list, what pointer type will you use?
o How to compare two linked lists? Write a C program to compare two linked lists.
o How to create a copy of a linked list? Write a C program to create a copy of a linked list.
o Write a C program to free the nodes of a linked list
o Can we do a Binary search on a linked list?
o Write a C program to return the nth node from the end of a linked list.
o How would you find out if one of the pointers in a linked list is corrupted or not?
o Write a C program to insert nodes into a linked list in a sorted fashion
o Write a C program to remove duplicates from a sorted linked list
o How to read a singly linked list backwards?
o How can I search for data in a linked list?
• Write Your Own Programs
o Write your own C program to implement the atoi() function
o Implement the memmove() function. What is the difference between the memmove() and memcpy() function?
o Write C code to implement the strstr() (search for a substring) function.
o Write your own printf() function in C
o Implement the strcpy() function.
o Implement the strcmp(str1, str2) function.
o Implement the substr() function in C.
o Write your own copy() function
o Write C programs to implement the toupper() and the isupper() functions
o Write a C program to implement your own strdup() function.
o Write a C program to implement the strlen() function
o Write your own strcat() function
• C and C++ PROGRAMS
o Write a C program to swap two variables without using a temporary variable
o What is the 8 queens problem? Write a C program to solve it.
o Write a C program to print a square matrix helically.
o Write a C program to reverse a string
o Write a C program to reverse the words in a sentence in place.
o Write a C program generate permutations.
o Write a C program for calculating the factorial of a number
o Write a C program to calculate pow(x,n)?
o Write a C program which does wildcard pattern matching algorithm
o How do you calculate the maximum subarray of a list of numbers?
o How to generate fibonacci numbers? How to find out if a given number is a fibonacci number or not? Write C programs to do both.
o Solve the Rat In A Maze problem using backtracking.
o What Little-Endian and Big-Endian? How can I determine whether a machine's byte order is big-endian or little endian? How can we convert from one to another?
o Write C code to solve the Tower of Hanoi problem.
o Write C code to return a string from a function
o Write a C program which produces its own source code as its output
o Write a C progam to convert from decimal to any base (binary, hex, oct etc...)
o Write C code to check if an integer is a power of 2 or not in a single line?
o Write a C program to find the GCD of two numbers.
o Finding a duplicated integer problem
o Write code to remove duplicates in a sorted array.
o Find the maximum of three integers using the ternary operator.
o How do you initialize a pointer inside a function?
o Write C code to dynamically allocate one, two and three dimensional arrays (using malloc())
o How would you find the size of structure without using sizeof()?
o Write a C program to multiply two matrices.
o Write a C program to check for palindromes.
o Write a C program to convert a decimal number into a binary number.
o Write C code to implement the Binary Search algorithm.
o Wite code to evaluate a polynomial.
o Write code to add two polynomials
o Write a program to add two long positive numbers (each represented by linked lists).
o How do you compare floating point numbers?
o What's a good way to implement complex numbers in C?
o How can I display a percentage-done indication on the screen?
o Write a program to check if a given year is a leap year or not?
o Is there something we can do in C but not in C++?
o How to swap the two nibbles in a byte ?
o How to scan a string till we hit a new line using scanf()?
o Write pseudocode to compare versions (like 115.10.1 vs 115.11.5).
o How do you get the line numbers in C?
o How to fast multiply a number by 7?
o Write a simple piece of code to split a string at equal intervals
o Is there a way to multiply matrices in lesser than o(n^3) time complexity?
o How do you find out if a machine is 32 bit or 64 bit?
o Write a program to have the output go two places at once (to the screen and to a file also)
o Write code to round numbers
o How can we sum the digits of a given number in single statement?
o Given two strings A and B, how would you find out if the characters in B were a subset of the characters in A?
o Write a program to merge two arrays in sorted order, so that if an integer is in both the arrays, it gets added into the final array only once. *
o Write a program to check if the stack grows up or down
o How to add two numbers without using the plus operator?
o How to generate prime numbers? How to generate the next prime after a given prime?
o Write a program to print numbers from 1 to 100 without using loops!
o Write your own trim() or squeeze() function to remove the spaces from a string.
o Write your own random number generator function in C.*
o Write your own sqrt() function in C*
• Trees Programs
o Write a C program to find the depth or height of a tree.
o Write a C program to determine the number of elements (or size) in a tree.
o Write a C program to delete a tree (i.e, free up its nodes)
o Write C code to determine if two trees are identical
o Write a C program to find the mininum value in a binary search tree.
o Write a C program to compute the maximum depth in a tree?
o Write a C program to create a mirror copy of a tree (left nodes become right and right nodes become left)!
o Write C code to return a pointer to the nth node of an inorder traversal of a BST.
o Write C code to implement the preorder(), inorder() and postorder() traversals. Whats their time complexities?
o Write a C program to create a copy of a tree
o Write C code to check if a given binary tree is a binary search tree or not?
o Write C code to implement level order traversal of a tree.
o Write a C program to delete a node from a Binary Search Tree?
o Write C code to search for a value in a binary search tree (BST).
o Write C code to count the number of leaves in a tree
o Write C code for iterative preorder, inorder and postorder tree traversals
o Can you construct a tree using postorder and preorder traversal?
o Construct a tree given its inorder and preorder traversal strings. Similarly construct a tree given its inorder and post order traversal strings.
o Find the closest ancestor of two nodes in a tree.
o Given an expression tree, evaluate the expression and obtain a paranthesized form of the expression.
o How do you convert a tree into an array?
o What is an AVL tree?
o How many different trees can be constructed using n nodes?
o A full N-ary tree has M non-leaf nodes, how many leaf nodes does it have?
o Implement Breadth First Search (BFS) and Depth First Search (DFS)
o Write pseudocode to add a new node to a Binary Search Tree (BST)
o What is a threaded binary tree?
• Bit Fiddling Programs
o Write a C program to count bits set in an integer?
o What purpose do the bitwise and, or, xor and the shift operators serve?
o How to reverse the bits in an interger?
o Check if the 20th bit of a 32 bit integer is on or off?
o How to reverse the odd bits of an integer?
o How would you count the number of bits set in a floating point number?*
• Sorting Techniques Programs
o What is heap sort?
o What is the difference between Merge Sort and Quick sort?
o Give pseudocode for the mergesort algorithm
o Implement the bubble sort algorithm. How can it be improved? Write the code for selection sort, quick sort, insertion sort.
o How can I sort things that are too large to bring into memory?
• C Pointers Programs
o What does *p++ do? Does it increment p or the value pointed by p?
o What is a NULL pointer? How is it different from an unitialized pointer? How is a NULL pointer defined?
o What is a null pointer assignment error?
o Does an array always get converted to a pointer? What is the difference between arr and &arr? How does one declare a pointer to an entire array?
o Is the cast to malloc() required at all?
o What does malloc() , calloc(), realloc(), free() do? What are the common problems with malloc()? Is there a way to find out how much memory a pointer was allocated?
o What's the difference between const char *p, char * const p and const char * const p?
o What is a void pointer? Why can't we perform arithmetic on a void * pointer?
o What do Segmentation fault, access violation, core dump and Bus error mean?
o What is the difference between an array of pointers and a pointer to an array?
o What is a memory leak?
o What are brk() and sbrk() used for? How are they different from malloc()?
o What is a dangling pointer? What are reference counters with respect to pointers?
o What do pointers contain?
o Is *(*(p+i)+j) is equivalent to p[i][j]? Is num[i] == i[num] == *(num + i) == *(i + num)?
o What operations are valid on pointers? When does one get the Illegal use of pointer in function error?
o What are near, far and huge pointers?
o What is the difference between malloc() and calloc()?
o Why is sizeof() an operator and not a function?
o What is an opaque pointer?
o What are the common causes of pointer bugs?
• C Functions Programs
o How to declare a pointer to a function?
o Does extern in a function declaration mean anything?
o How can I return multiple values from a function?
o Does C support function overloading?
o What is the purpose of a function prototype?
o What are inline functions?
o How to declare an array of N pointers to functions returning pointers to functions returning pointers to characters?
o Can we declare a function that can return a pointer to a function of the same type?
o How can I write a function that takes a variable number of arguments? What are the limitations with this? What is vprintf()?
o With respect to function parameter passing, what is the difference between call-by-value and call-by-reference? Which method does C use?
o If I have the name of a function in the form of a string, how can I invoke that function?
o What does the error, invalid redeclaration of a function mean?
o How can I pass the variable argument list passed to one function to another function.
o How do I pass a variable number of function pointers to a variable argument (va_arg) function?
o Will C allow passing more or less arguments than required to a function.
• C Statements Programs
o Whats short-circuiting in C expressions?
o Whats wrong with the expression a[i]=i++; ? Whats a sequence point?
o Does the ?: (ternary operator) return a lvalue? How can I assign a value to the output of the ternary operator?
o Is 5[array] the same as array[5]?
o What are #pragmas?
o What is the difference between if(0 == x) and if(x == 0)?
o Should we use goto or not?
o Is ++i really faster than i = i + 1?
o What do lvalue and rvalue mean?
o What does the term cast refer to? Why is it used?
o What is the difference between a statement and a block?
o Can comments be nested in C?
o What is type checking?
o Why can't you nest structure definitions?
o What is a forward reference?
o What is the difference between the & and && operators and the | and || operators?
o Is C case sensitive (ie: does C differentiate between upper and lower case letters)?
o Can goto be used to jump across functions?
o Whats wrong with #define myptr int *?
o What purpose do #if, #else, #elif, #endif, #ifdef, #ifndef serve?
o Can we use variables inside a switch statement? Can we use floating point numbers? Can we use expressions?
o What is more efficient? A switch() or an if() else()?
o What is the difference between a deep copy and a shallow copy?
o What is operator precedence?*
• C Arrays Programs
o How to write functions which accept two-dimensional arrays when the width is not known before hand?
o Is char a[3] = "abc"; legal? What does it mean?
o If a is an array, is a++ valid?
o How can we find out the length of an array dynamically in C?
• C Variables Programs
o What is the difference between the declaration and the definition of a variable?
o Do Global variables start out as zero?
o Does C have boolean variable type?
o Where may variables be defined in C?
o To what does the term storage class refer? What are auto, static, extern, volatile, const classes?
o What does the typedef keyword do?
o What is the difference between constants defined through #define and the constant keyword?
o What are Trigraph characters?
o How are floating point numbers stored? Whats the IEEE format?
o When should the register modifier be used?
o When should a type cast be used?
• C Structures Programs
o Can structures be assigned to variables and passed to and from functions?
o Can we directly compare two structures using the == operator?
o Can we pass constant values to functions which accept structure arguments?
o How does one use fread() and fwrite()? Can we read/write structures to/from files?
o Why do structures get padded? Why does sizeof() return a larger size?
o Can we determine the offset of a field within a structure and directly access that element?
o What are bit fields in structures?
o What is a union? Where does one use unions? What are the limitations of unions?
• C Macros Programs
o How should we write a multi-statement macro?
o How can I write a macro which takes a variable number of arguments?
o What is the token pasting operator and stringizing operator in C?
o Define a macro called SQR which squares a number.
• C Headers Programs
o What should go in header files? How to prevent a header file being included twice? Whats wrong with including more headers?
o Is there a limit on the number of characters in the name of a header file?
o Is it acceptable to declare/define a variable in a C header?
• C File operations Programs
o How do stat(), fstat(), vstat() work? How to check whether a file exists?
o How can I insert or delete a line (or record) in the middle of a file?
o How can I recover the file name using its file descriptor?
o How can I delete a file? How do I copy files? How can I read a directory in a C program?
o Whats the use of fopen(), fclose(), fprintf(), getc(), putc(), getw(), putw(), fscanf(), feof(), ftell(), fseek(), rewind(), fread(), fwrite(), fgets(), fputs(), freopen(), fflush(), ungetc()?
o How to check if a file is a binary file or an ascii file?
• C Declarations and Definitions Programs
o What is the difference between char *a and char a[]?
o How can I declare an array with only one element and still access elements beyond the first element (in a valid fashion)?
o What is the difference between enumeration variables and the preprocessor #defines?
• C Functions - built-in Programs
o Whats the difference between gets() and fgets()? Whats the correct way to use fgets() when reading a file?
o How can I have a variable field width with printf?
o How can I specify a variable width in a scanf() format string?
o How can I convert numbers to strings (the opposite of atoi)?
o Why should one use strncpy() and not strcpy()? What are the problems with strncpy()?
o How does the function strtok() work?
o Why do we get the floating point formats not linked error?
o Why do some people put void cast before each call to printf()?
o What is assert() and when would I use it?
o What do memcpy(), memchr(), memcmp(), memset(), strdup(), strncat(), strcmp(), strncmp(), strcpy(), strncpy(), strlen(), strchr(), strchr(), strpbrk(), strspn(), strcspn(), strtok() do?
o What does alloca() do?
o Can you compare two strings like string1==string2? Why do we need strcmp()?
o What does printf() return?
o What do setjmp() and longjump() functions do?
• C Functions - The main function Programs
o Whats the prototype of main()? Can main() return a structure?
o Is exit(status) equivalent to returning the same status from main()?
o Can main() be called recursively?
o How to print the arguments recieved by main()?
• OS Concepts
o What do the system calls fork(), vfork(), exec(), wait(), waitpid() do? Whats a Zombie process? Whats the difference between fork() and vfork()?
o How does freopen() work? *
o What are threads? What is a lightweight process? What is a heavyweight process? How different is a thread from a process? *
o How are signals handled? *
o What is a deadlock? *
o What are semaphores? *
o What is meant by context switching in an OS?*
o What is Belady's anomaly?
o What is thrashing?*
o What are short-, long- and medium-term scheduling?
o What are turnaround time and response time?
o What is the Translation Lookaside Buffer (TLB)?
o What is cycle stealing?
o What is a reentrant program?
o When is a system in safe state?
o What is busy waiting?
o What is pages replacement? What are local and global page replacements?*
o What is meant by latency, transfer and seek time with respect to disk I/O?
o What are monitors? How are they different from semaphores?*
o In the context of memory management, what are placement and replacement algorithms?
o What is paging? What are demand- and pre-paging?*
o What is mounting?
o What do you mean by dispatch latency?
o What is multi-processing? What is multi-tasking? What is multi-threading? What is multi-programming?*
o What is compaction?
o What is memory-mapped I/O? How is it different frim I/O mapped I/O?
o List out some reasons for process termination.
• General Concepts Programs
o What is the difference between statically linked libraries and dynamically linked libraries (dll)?
o What are the most common causes of bugs in C?
o What is hashing?
o What do you mean by Predefined?
o What is data structure?
o What are the time complexities of some famous algorithms?
o What is row major and column major form of storage in matrices?
o Explain the BigOh notation.
o Give the most important types of algorithms.
o What is marshalling and demarshalling?
o What is the difference between the stack and the heap? Where are the different types of variables of a program stored in memory?
o Describe the memory map of a C program.
o What is infix, prefix, postfix? How can you convert from one representation to another? How do you evaluate these expressions?
o How can we detect and prevent integer overflow and underflow?*
• Compiling and Linking Programs
o How to list all the predefined identifiers?
o How the compiler make difference between C and C++?
o What are the general steps in compilation?
o What are the different types of linkages?
o What do you mean by scope and duration?
o What are makefiles? Why are they used?*
C Programs with Solutions. Example for OOP CPrograms. Basic C Programs. Free C Programs. C Interview Questions