PF - 24 (Lab-1)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

QUAID-E-AWAM UNIVERSITY OF SOFTWARE ENGINEERING, SCIENCE & TECHNOLOGY NAWABSHAH

DEPARTMENT OF SOFTWARE ENGINEERING


PROGRAMMING FUNDAMENTALS

Practical # 01

Objective: To become familiar with installation and understanding of


Dev C++ IDE.

Introduction: C is a general-purpose programming language that has been widely used for
system and application software development. In this practical, students will learn how to
install and set up Dev C++, an Integrated Development Environment (IDE) that
simplifies C programming, compilation, and debugging. By the end of this session,
students will also understand how to write and execute their first C program, the classic
"Hello, World!" which introduces the basic syntax of the C language.
Integrated Development Environment (IDE):
An Integrated Development Environment is a software application that provides tools for
software development, including:

 Text Editor: To write and edit the code.


 Compiler: To translate the written code into machine code.
 Debugger: To help find and fix errors in the code.
 Other Tools: Features like auto-completion, project management, and syntax
highlighting.

Dev C++ is one such popular IDE for C/C++ programming. It integrates a GCC compiler
and provides a user-friendly interface to develop and execute C programs easily.
Steps for Installing Dev C++:

 Download the Dev C++ installer from a trusted source (e.g., SourceForge).
 Run the installer and follow the instructions to install the software.
 Once installed, open Dev C++ and familiarize yourself with the interface, which
includes the menu bar, toolbar, text editor, and console window.

Step:1 Download Dev/C++


Download the DevC++ from the given website: https://www.bloodshed.net/
QUAID-E-AWAM UNIVERSITY OF SOFTWARE ENGINEERING, SCIENCE & TECHNOLOGY NAWABSHAH
DEPARTMENT OF SOFTWARE ENGINEERING
PROGRAMMING FUNDAMENTALS

Step 2: Install Dev/C++


1. Open the file
When the file is done downloading, locate the downloaded file and open the executable
file (devcpp- 4.9.9.2_setup.exe).
2. Instal Dev/C++
After you open the executable file, you will be ran through an installation set-up.
You can choose where to store the program files, but use the default
settings for everything else.
QUAID-E-AWAM UNIVERSITY OF SOFTWARE ENGINEERING, SCIENCE & TECHNOLOGY NAWABSHAH
DEPARTMENT OF SOFTWARE ENGINEERING
PROGRAMMING FUNDAMENTALS

At the end of the installation, you can leave the box that says Run Dev-C ++ 5
beta 9 release (4.9.9.2) selected as shown in the figure so the program will open.

Step 3: Create First Project


1. Run Dev/C++
Go to Start Menu > All Programs > Bloodshed Dev-C++ > Dev-C++. This should start
the program.
2. Create a New Source File
If you are prompted with a set up window, use all the default settings. Once the
program opens, you need to create a new source file so you can start writing your first
program. To do this select File > New > Source File. The path is shown in the figure
above. This will open up an area where you be able to type out your code.
QUAID-E-AWAM UNIVERSITY OF SOFTWARE ENGINEERING, SCIENCE & TECHNOLOGY NAWABSHAH
DEPARTMENT OF SOFTWARE ENGINEERING
PROGRAMMING FUNDAMENTALS

Step 4: Write Your Program


Here we will write the first simple program to simply have the computer say display text to
the console.
Write the following code in the editor.
QUAID-E-AWAM UNIVERSITY OF SOFTWARE ENGINEERING, SCIENCE & TECHNOLOGY NAWABSHAH
DEPARTMENT OF SOFTWARE ENGINEERING
PROGRAMMING FUNDAMENTALS

Compiling and Running the Program:

 After writing the program in the text editor of Dev C++, save the file with a .c
extension.
 Click on the "Compile & Run" button to compile the code.
 If there are no syntax errors, the compiled code will execute and display the output
("Hello, World!") in the console window.
Explanation of the Code:
 #include <stdio.h>: This is a preprocessor directive that tells the compiler to include
the Standard Input Output library, which contains functions like printf().
 int main() { ... }: The main function is the starting point of every C program. The
code inside the main function is executed when the program runs.
 printf("Hello, World!\n"); : This function prints the message "Hello, World!" to the
console. The \n at the end adds a newline after printing the text.
 return 0; : This statement indicates that the program has executed successfully.

Conclusion:

By completing this practical, students become familiar with the Dev C++ IDE, its
interface, and how to write a basic C program. The "Hello, World!" example serves as
a foundation for understanding how C programs are structured and executed, and it
prepares students for more complex programming tasks in future practicals.
Exercise Questions:
1. What will happen if you miss a semicolon at the end of the printf() statement? Test
this by removing the semicolon and observing the error message.
2. What error message do you receive if you forget to include the #include <stdio.h>
line? Explain why this error occurs.
3. Modify the "Hello, World!" program to print your name and age on separate lines.
4. Explore other libraries in C. Replace #include <stdio.h> with #include <math.h> and
see what happens. What is the purpose of the <math.h> library in C?
5. What error message do you receive if you misspell main() as Main() in the program
QUAID-E-AWAM UNIVERSITY OF SOFTWARE ENGINEERING, SCIENCE & TECHNOLOGY NAWABSHAH
DEPARTMENT OF SOFTWARE ENGINEERING
PROGRAMMING FUNDAMENTALS

6. Why is it important to use correct case in C?


7. What happens if you forget to close a curly brace (}) in the main() function? Test it
and describe the error message.
8. Remove the closing double quote in the printf() statement and observe the error
message. What does it mean, and how would you fix it?
QUAID-E-AWAM UNIVERSITY OF SOFTWARE ENGINEERING, SCIENCE & TECHNOLOGY NAWABSHAH
DEPARTMENT OF SOFTWARE ENGINEERING
PROGRAMMING FUNDAMENTALS

Course: Programming Fundamentals Course Code


Student Name: Roll No:
Semester-Year: Date:

You might also like