Compare first n characters using strncmp() Dry Run in C

Compare first n characters using strncmp() is an interactive C dry run visualizer from the String Functions 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.

Compare first n characters using strncmp() Program Code

#include <stdio.h>
#include <string.h>
int main() {
    char str1[] = "Programming";
    char str2[] = "Programmer";
    int n = 7;
    
    int result = strncmp(str1, str2, n);
    
    printf("First %d characters:\n", n);
    printf("'%s' vs '%s' = %d\n", str1, str2, result);
    
    if(result == 0)
        printf("First %d characters are EQUAL\n", n);
    else
        printf("First %d characters are DIFFERENT\n", n);
    
    return 0;
}

View the complete String Functions programs page.

Program Console Compare first n characters using strncmp() Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.