Purbanchal University BIT

Study Notes &
Important Topics

High-frequency exam topics, verified code algorithms, key formulas, and theory questions organized by semester.

Select Semester

8 Semesters Available

Semester 1 Subjects2

Semester 1

Programming in C

2 Code Topics3 Theory FAQs
1

Pointers, Dynamic Memory & Memory Addresses

Very High Priority

Core Concepts & Exam Keys

  • Pointer stores hexadecimal address of another variable (* dereference, & address-of)
  • Dynamic allocation via malloc(), calloc(), realloc(), and free() in <stdlib.h>
  • Dangling pointers occur when referencing deallocated heap memory
  • Pointer arithmetic: ptr + 1 advances by sizeof(data_type) bytes
Executable Algorithm
#include <stdio.h>
#include <stdlib.h>

int main() {
    int *arr = (int *)malloc(5 * sizeof(int));
    if (!arr) return 1;
    for(int i = 0; i < 5; i++) *(arr + i) = (i + 1) * 10;
    for(int i = 0; i < 5; i++) printf("%d ", *(arr + i));
    free(arr);
    return 0;
}

Mathematical Formulation

Time Complexity: O(1) allocation, O(n) traversal. Space: O(n) on heap.
2

Structures, Unions & Bit-Fields

High Priority

Core Concepts & Exam Keys

  • Structure members each have their own memory; union members share the largest member's memory
  • struct size is affected by byte padding and memory alignment
  • Access members using dot operator (.) for values and arrow operator (->) for pointers
Executable Algorithm
#include <stdio.h>

struct Student {
    int id;
    char name[30];
    float gpa;
};

int main() {
    struct Student s1 = {101, "Aarav Sharma", 3.85};
    struct Student *ptr = &s1;
    printf("Student: %s, GPA: %.2f\n", ptr->name, ptr->gpa);
    return 0;
}

Mathematical Formulation

sizeof(union) = max(sizeof(member)), sizeof(struct) >= sum(sizeof(member))