Basic Concepts
1. Compiler vs. Interpreter: A compiler translates the entire source code into machine code
before execution, while an interpreter translates code line-by-line during execution.
2. Structure of a C Program: A basic C program typically includes preprocessor directives,
function prototypes, the main() function, and can include other functions.
3. Variables and Constants: Variables are storage locations that can change during execution;
constants are fixed values that cannot change.
4. Header File Purpose: Header files contain declarations for functions and macros, allowing for
modular programming and code reuse.
5. Defining a Macro: Use #define to define a macro. For example: #define PI 3.14.
Data Types and Operators
6. Data Types in C: Common types include int, float, double, char, and derived types like arrays
and structures.
7. Signed vs. Unsigned Integers: Signed integers can represent both positive and negative
values, while unsigned integers only represent non-negative values.
8. Float vs. Double: float has single precision (usually 32 bits), while double has double
precision (usually 64 bits).
9. Arithmetic Operators: Includes +, -, *, /, and %.
10. Precedence and Associativity: Operator precedence determines the order of operations;
associativity determines the direction of evaluation (left-to-right or right-to-left).
Control Structures
11. if-else Syntax:
Copy code
if (condition) {
// code if true
} else {
// code if false
12. Switch Statement: A switch statement evaluates an expression and executes code blocks
based on matching case labels.
13. While vs. Do-While: A while loop checks the condition before executing the loop body; a do-
while loop executes the body at least once before checking the condition.
14. For Loop:
c
Copy code
for (initialization; condition; increment) {
// loop body
15. Break and Continue: break exits the loop, while continue skips to the next iteration of the
loop.
Functions
16. Functions: Functions are blocks of code that perform specific tasks and can be reused
throughout the program.
17. Call by Value vs. Call by Reference: Call by value passes a copy of the variable; call by
reference passes a reference (pointer) to the variable.
18. Recursive Function: A function that calls itself. Example:
Copy code
int factorial(int n) {
return n == 0 ? 1 : n * factorial(n - 1);
19. Passing Arrays: Arrays are passed to functions as pointers. Example: void func(int arr[]).
20. Purpose of void: Used to indicate a function does not return a value.
Arrays
21. Arrays in C: Arrays are collections of elements of the same type. They are declared with a
type and size, e.g., int arr[10];.
22. Initializing an Array: You can initialize during declaration: int arr[3] = {1, 2, 3};.
23. Passing an Array: Arrays are passed by reference; use the array name as a parameter.
24. Matrix Multiplication: Implement using nested loops to multiply corresponding elements.
25. Searching in an Array: Use a loop to iterate through the array to find the element.
Pointers
26. Pointer: A pointer is a variable that stores the memory address of another variable.
27. Declaring a Pointer: int *ptr; initializes a pointer to an integer.
28. Pointer Arithmetic: You can perform arithmetic operations (e.g., ptr++) to navigate through
memory.
29. Passing a Pointer: Similar to passing an array, you can pass a pointer to a function to modify
the original variable.
30. Pointer vs. Array: A pointer holds an address, while an array is a fixed-size collection of
elements.
Strings
31. Declaring a String: A string can be declared as a character array: char str[10];.
32. String Functions: Functions like strcpy and strcmp manipulate strings by copying and
comparing them, respectively.
33. Reversing a String: Use a loop to swap characters from both ends towards the center.
34. Checking Palindrome: Compare characters from both ends towards the center.
35. String vs. Character Array: A string is a character array terminated by a null character (\0).
Structures and Unions
36. Structure: A structure is a user-defined data type that groups related variables.
37. Declaring a Structure:
Copy code
struct Person {
char name[50];
int age;
};
38. Structure vs. Union: Structures allocate memory for all members, while unions share the
same memory location among members.
39. Initializing a Structure: You can initialize with an aggregate initializer: struct Person p =
{"Alice", 30};.
40. Passing a Structure: Pass by value or by reference using pointers.
File Handling
41. Opening a File: Use fopen(), e.g., FILE *fp = fopen("file.txt", "r");.
42. File Modes: Common modes include "r" (read), "w" (write), "a" (append).
43. Writing Data: Use fprintf() or fputs().
44. Reading Data: Use fscanf() or fgets().
45. fgetc() and fputc(): These functions read and write a single character from/to a file.
Dynamic Memory Allocation
46. Dynamic Memory Allocation: Allocates memory during runtime using functions like malloc()
and calloc().
47. malloc() and calloc(): malloc() allocates uninitialized memory; calloc() allocates initialized
memory.
48. free(): Releases dynamically allocated memory to prevent memory leaks.
49. Dynamically Allocate 2D Array: Use pointers to pointers or an array of pointers.
50. Memory Leaks: Occur when allocated memory is not freed. Prevent by always calling free().
Preprocessors and Macros
51. Preprocessors: They process directives before compilation (e.g., #include, #define).
52. #define Directive: Used to define macros or constants.
53. Conditional Compilation: Use #ifdef, #ifndef, etc., to include/exclude code based on
conditions.
54. Macros: Defined with #define; they replace code before compilation.
55. Macros vs. Functions: Macros are expanded inline, while functions have overhead due to
calls.
Storage Classes
56. Storage Classes: Include auto, static, extern, and register.
57. Auto vs. Static: auto is the default storage class with block scope; static retains value across
function calls.
58. Extern Variable: Declares a variable defined in another file or scope.
59. Register Storage Class: Suggests that the variable be stored in CPU registers for faster access.
60. Scope and Lifetime: Varies by storage class, affecting visibility and duration of variable
existence.
Linked Lists
61. Linked List: A data structure consisting of nodes where each node points to the next.
62. Singly Linked List Implementation: Consists of a struct for nodes with a value and a pointer
to the next node.
63. Array vs. Linked List: Arrays have fixed size and random access; linked lists are dynamic and
use sequential access.
64. Inserting a Node: Adjust pointers to include the new node.
65. Deleting a Node: Adjust pointers to exclude the node from the list.
Miscellaneous
66. Segmentation Fault: Occurs when accessing memory that is not allocated or allowed.
67. == vs. =: == checks equality, while = is an assignment operator.
68. Switch vs. If-Else: switch is cleaner for multiple discrete values; if-else is more flexible for
conditions.
69. Enumerations: A user-defined type that consists of named integer constants.
70. Command-Line Arguments: Arguments passed to the program via the command line,
accessible via argc (argument count) and argv (argument vector).