![]() |
VOOZH | about |
C programming isn't just about printf() and for loops. For technical interviews, especially in system-level, embedded, or product-based roles, you're expected to master the language’s advanced concepts: low-level memory operations, file access, type definitions, and even how programs interact with the OS.
Recursion is the process of making the function call itself directly or indirectly. A recursive function solves a particular problem by calling a copy of itself and solving smaller subproblems that sum up the original problems. Recursion helps to reduce the length of code and make it more understandable. The recursive function uses a LIFO ( Last In First Out ) structure like a stack. Every recursive call in the program requires extra space in the stack memory.
👁 Factorial of a NumberFor more information, refer to the article - Recursion
Stack overflow occurs when too many recursive calls exceed the function call stack limit. Avoid by:
Example:
void recurse() {
recurse(); // No base case -> infinite calls -> crash
}
Below is the C program to implement Union:
To read a file line by line, you can use the fgets() function, which reads until a newline character or the specified buffer size is reached. This is useful for processing text files without loading the entire file into memory.
How it works:
You cannot take the address of an r-value like &20 or assign to it directly like 20 = val.
The sleep() function in C suspends execution of the current thread for the specified number of seconds. It takes an unsigned int as an argument. For sub-second delays, use usleep() (microseconds) or nanosleep().
In C, enumerations (or enums) are user-defined data types. Enumerations allow integral constants to be named, which makes a program easier to read and maintain. For example, the days of the week can be defined as an enumeration and can be used anywhere in the program.
enum enumeration_name{constant1, constant2, ... };
2
In the above example, we declared “day” as the variable, and the value of “Wed” is allocated to day, which is 2. So as a result, 2 is printed.
For more information, refer to the article - Enumeration (or enum) in C
Volatile keyword is used to prevent the compiler from optimization because their values can’t be changed by code that is outside the scope of current code at any time. The System always reads the current value of a volatile object from the memory location rather than keeping its value in a temporary register at the point it is requested, even if previous instruction is asked for the value from the same object.
Without volatile, the compiler might optimize the while(flag == 0) loop into an infinite loop, assuming flag never changes, because it thinks no code inside main() changes it.
Fibonacci Series with the help of Recursion: 0 1 1 2 3 5 8 Fibonacci Series without Using Recursion: 0 1 1 2 3 5 8
| Source Code | Object Code |
|---|---|
| Source code is generated by the programmer. | object code is generated by a compiler or another translator. |
| High-level code which is human-understandable. | Low-level code is not human-understandable. |
| Source code can be easily modified and contains less number of statements than object code. | Object code cannot be modified and contains more statements than source code. |
| Source code can be changed over time and is not system specific. | Object code can be modified and is system specific. |
| Source code is less close to the machine and is input to the compiler or any other translator. | Object code is more close to the machine and is the output of the compiler or any other translator. |
| Language translators like compilers, assemblers, and interpreters are used to translate source code to object code. | Object code is machine code so it does not require any translation. |
Explanation:
Modifiers are keywords that are used to change the meaning of basic data types in C language. They specify the amount of memory that is to be allocated to the variable. There are five data type modifiers in the C programming language:
Factorial of 5 is 120
An Armstrong number (also called a narcissistic number) is a number where the sum of its digits raised to the power of the number of digits equals the number itself.
For example: 153 is an Armstrong number because:
13+53+33=1+125+27=1531^3 + 5^3 + 3^3 = 1 + 125 + 27 = 15313+53+33=1+125+27=153
Steps:
To reverse a number:
This way, digits are added in reverse order to rev.
In C programming Basic File Handling Techniques provide the basic functionalities that programmers can perform against the system.
A circular linked list is one where the last node points back to the first node, forming a loop. To check if a linked list is circular:
Alternatively, Floyd’s Cycle Detection Algorithm (Tortoise and Hare) can be used to detect loops more efficiently.
For more information, refer to the article - Circular Linked List
To merge two sorted linked lists into a single sorted list:
Merged Linked List is: 2 3 5 10 15 20
fread() is used for binary file reading, and it reads raw bytes.
fread(buffer, sizeof(char), 100, fp); // Binary
fscanf(fp, "%s", buffer); // Text
Use "a" mode in fopen():
FILE *fp = fopen("data.txt", "a");
In C programming, typedef is a keyword that defines an alias for an existing type. Whether it is an integer variable, function parameter, or structure declaration, typedef will shorten the name.
Syntax:
typedef <existing-type> <alias-name>
In C, command-line arguments allow you to pass values (inputs) to the main() function when a program is run from the command line or terminal.
The main() function has two special parameters:
int main(int argc, char *argv[])
If the executable is named a.out, run it like this in terminal:
./a.out hello world 123