Search student by ID (Linear Search) Dry Run in C

Search student by ID (Linear Search) is an interactive C dry run visualizer from the Structures Arrays programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Search student by ID (Linear Search) Program Code

#include <stdio.h>

struct Student {
    int roll;
    char name[40];
    float marks;
};

int searchByRoll(struct Student s[], int n, int targetRoll) {
    for(int i = 0; i < n; i++) {
        if(s[i].roll == targetRoll) {
            return i;  // Found at index i
        }
    }
    return -1;  // Not found
}

int main() {
    struct Student students[50];
    int n, searchRoll;
    
    printf("Enter number of students: ");
    scanf("%d", &n);
    
    for(int i = 0; i < n; i++) {
        printf("\nStudent %d:\n", i+1);
        printf("Roll: "); scanf("%d", &students[i].roll);
        printf("Name: "); scanf(" %[^\n]", students[i].name);
        printf("Marks: "); scanf("%f", &students[i].marks);
    }
    
    printf("\nEnter Roll Number to search: ");
    scanf("%d", &searchRoll);
    
    int index = searchByRoll(students, n, searchRoll);
    
    if(index != -1) {
        printf("\n========== STUDENT FOUND ==========\n");
        printf("Roll No: %d\n", students[index].roll);
        printf("Name: %s\n", students[index].name);
        printf("Marks: %.2f\n", students[index].marks);
    } else {
        printf("\nStudent with Roll No %d NOT FOUND!\n", searchRoll);
    }
    
    return 0;
}

View the complete Structures Arrays programs page.

Program Console Search student by ID (Linear Search) Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.