EE232: Data Structures Laboratory Experiment No: 1
Introduction to MS Visual Studio
Objective:
The objective of this LAB is to familiarize the students with the working environment of MS Visual
Studio. Two simple programming examples will be discussed in this lab manual depicting the compilation
and debugging features of MS Visual Studio.
Introduction:
MS Visual Studio is an integrated development environment (IDE) which is used to create different
Windows based applications, web-sites and web services. It is a very powerful IDE supporting a wide
variety of languages namely C, C++, C# and Visual C++. In this lab, this IDE will be used for different
types of data structures in C language.
Below are mentioned two examples to get started.
Example 1: Compiling a Program:
1. From the main menu select File -> New -> Project
2. In the New Project window:
Under Installed Templates, select Visual C++, select Win32 Console Application
Name your project, and specify a location for your project directory
Click 'OK', then 'next'
EE232: Data Structures Laboratory Experiment No: 1
3. In the Application Wizard:
Select Next.
A new dialog box appears. Select “Console Application” and uncheck “Precompiled Header”.
Select Finish.
EE232: Data Structures Laboratory Experiment No: 1
4. Open Solution Explorer from the standard Toolbar or use shortcut (Ctrl+Alt+L)
5. Right Click Source Files and Select Add->New Item,
6. Select Code, and give the file a name
The default here will be a file with a *.cpp extension (for a C++ file). After creating the file, save
it as a *.c file.
EE232: Data Structures Laboratory Experiment No: 1
7. Enter the following code in “sample_program.c” file:
#include<stdio.h>
int main (void)
{
printf("Introduction to MS Visual Studio\n");
return 0;
}
To compile and run:
1. Press the green play button on Standard Toolbar or F5 to compile the program.
2. By default, you will be running in debug mode and it will run your code and bring up the
command window.
3. To prevent the command window from closing as soon as the program finishes execution, add the
following line to the code after the printf statement:
getchar(). This library function waits for any input key, and will therefore keep your console
window open until a key is pressed.
4. Alternatively, you can compile the program and stop the console from closing after compilation
using Ctrl+F5.
Example 2: Debugging a Program:
Debugging is a very useful feature in IDE’s. It gives a lot of flexibility to the programmer to find various
semantic errors in the code. It makes the cumbersome job of writing an error free piece of code a lot
easier especially for beginners.
1. Write the following Code in a new c file and name it as sample_debug_program.c
#include<stdio.h>
int main (void)
{
int i,j,sum=0;
for (i=0; i<2; i++)
{
for (j=0; j<2; j++)
{
sum=i+j;
printf("Sum = %d\n", sum);
}
}
return 0;
}
EE232: Data Structures Laboratory Experiment No: 1
2. You will have two source files now under the Source Files.
3. Right click sample_program.c.
4. Property Pages Dialog Box will appear. In the option named Exclude from Build, select Yes.
This file will not be compiled now (we have to compile the new program and two different
programs cannot be compiled simultaneously).
5. To use
Debugger, we need to add to a breakpoint in our program. Breakpoint means the point where
the programmer wants to intentionally stop the compiler to monitor the values of certain
variables/flags.
6. In the above program, add a breakpoint on the variable “Sum”. Right click on “Sum”-
>Breakpoint->Insert Breakpoint.
EE232: Data Structures Laboratory Experiment No: 1
7. From Menu Bar, select Debug->Start Debugging
8. You can easily see the values of different variables like i, j and sum
9. To move onto the next instruction, Press F11. To stepover the “printf” instruction, press F11.
10. Press F10 repeatedly and you will observe the values of i, j and sum will keep updating.