PF - 24 (Lab-1)
PF - 24 (Lab-1)
PF - 24 (Lab-1)
Practical # 01
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:
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.
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.
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