c
c
Fundamentals of C
Copy
Download
Real-World Application:
text
Copy
Download
#include <stdio.h>
int main() {
printf("Account Details:\n");
return 0;
text
Copy
Download
+-------------+------------+-------+
+-------------+------------+-------+
| age | 0x7ffe.. | 25 |
+-------------+------------+-------+
Interview Questions (Microsoft)
Copy
Download
int a = 10, b = 3;
// Arithmetic
int sum = a + b; // 13
int mod = a % b; // 1
// Bitwise
Copy
Download
#include <stdio.h>
int main() {
return 0;
text
Copy
Download
1. () [] -> .
3. * / %
4. + -
5. << >>
...
Copy
Download
a = a + b;
b = a - b;
a = a - b;
4. Control Flow
Copy
Download
#include <stdio.h>
int main() {
printf("Loan Approved");
} else {
printf("Not Eligible");
return 0;
Copy
Download
switch(operator) {
Flowchart Diagram
text
Copy
Download
Copy
Download
// Function declaration
return a + b;
// Function call
Real-World Example:
Payment processing function in an e-commerce system:
Copy
Download
Memory Diagram:
text
Copy
Download
[Stack Frame]
+-------------------+
| Return Address |
| Parameters (a, b) |
| Local Variables |
+-------------------+
Copy
Download
Pass by Reference
Copy
Download
Real-World Example:
Swapping sensor readings in embedded systems:
Copy
Download
*a = *b;
*b = temp;
5.3 Recursion
Copy
Download
int factorial(int n) {
if (n <= 1) return 1;
}
Execution Diagram:
text
Copy
Download
factorial(3)
→ 3 * factorial(2)
→ 2 * factorial(1)
→ 1 (base case)
Copy
Download
// Recursive
int fib(int n) {
if (n <= 1) return n;
// Iterative
int fib(int n) {
int a = 0, b = 1, c;
c = a + b;
a = b;
b = c;
return b;
Copy
Download
// Matrix multiplication
Memory Layout:
text
Copy
Download
Row-Major Order:
Copy
Download
Pointer-Array Relationship:
Copy
Download
Copy
Download
struct Address {
char city[20];
int pin;
};
struct Employee {
int id;
};
text
Copy
Download
struct Example {
char c; // 1 byte
// 3 bytes padding
int i; // 4 bytes
c
Copy
Download
struct Packet {
uint16_t src_port;
uint16_t dest_port;
uint32_t seq_num;
char data[100];
};
9. File Handling
Copy
Download
// Random access
text
Copy
Download
File Position
10. Dynamic Memory Allocation
Copy
Download
char memory_pool[POOL_SIZE];
return NULL;
pool_ptr += size;
return block;
text
Copy
Download
Copy
Download
Copy
Download
init();
2. "Implement atoi()"
Copy
Download
int res = 0;
return res;
Company-Specific Problems
Complete Appendix
A. Standard Library Cheat Sheet
Copy
Download
// String
// Math
// Memory
B. Compilation Flags
sh
Copy
Download
sh
Copy
Download
break main
watch variable
backtrace
print *(array@10)
Copy
Download
// Set bit
num |= (1 << position);
// Clear bit
// Toggle bit
// Check bit
Endianness Check:
Copy
Download
int x = 1;
if(*(char*)&x == 1) {
printf("Little Endian");
} else {
printf("Big Endian");
Real-World Example:
Device register configuration (Embedded Systems):
Copy
Download
Copy
Download
int count_set_bits(int num) {
int count = 0;
while(num) {
num >>= 1;
return count;
while(num) {
count++;
Standard Techniques
Copy
Download
if(fp == NULL) {
perror("Error");
exit(EXIT_FAILURE);
// Assertions
Copy
Download
if(!out) {
fclose(in);
/* error handling */
char buffer[4096];
size_t bytes;
/* error handling */
fclose(in);
fclose(out);
Copy
Download
if(b == 0) {
return -1;
}
return -1;
*result = a / b;
return 0;
Key Libraries
Copy
Download
// math.h
// time.h
// stdlib.h
Copy
Download
pass[i] = charset[key];
pass[length] = '\0';
return pass;
Memory Management
Pointers
Strings
Copy
Download
while((*dest++ = *src++));
return ret;
Bit Manipulation
Copy
Download
a ^= b; b ^= a; a ^= b;
Copy
Download
Data Structures
Copy
Download
while(head) {
next = head->next;
head->next = prev;
prev = head;
head = next;
return prev;
Multithreading
Advanced Concepts
Tricky Questions
Real-World Problems
Copy
Download
Copy
Download
char line[256];
// Process line
Library Functions
19. Apple: Implement memmove().
Copy
Download
char *d = dest;
if(d < s) {
} else {
char *lastd = d + n - 1;
return dest;
System Programming