How to Debug C Code in a Visual Studio

Feb. 9, 2017 | smlee36 | #seneca, #c, #beginner, #visualstudio, #debug, #Abdi

This is an ultra simple tutorial for debugging c program in a Visual Studio.

TOC


Case Study

Sample Program

// An ultra simple debugging example

#include <stdio.h>

int main() {
    
    int num;

    printf("Enter your number (1-10): ");
    scanf("%d", &num);

    while (num < 1 || 10 < num) {
        printf("Input number should be 1 - 10.");

        printf("Enter your number again (1-10): ");


    }

    printf("Your number is %d.\n", num);


    return 0;
}

image

image

Debug the Program

Marking break points

image

ddimage

scanf("%d", &num);

As described above, developer can see the exact position of compiler in progress.