Course No: EE 1222
Course Titles: Sessional on Computer
Programming and Fundamentals
Lecture: Introduction to C programming
Md. Sajjad Hossain
Lecturer, Department of EEE
Department of EEE,KUET
C Introduction
What is C?
C is a general-purpose programming language created by Dennis
Ritchie at the Bell Laboratories in 1972.
It is a very popular language, despite being old. The main reason for
its popularity is because it is a fundamental language in the field of
computer science.
C is strongly associated with UNIX, as it was developed to write the
UNIX operating system.
Department of EEE,KUET
C Introduction
Why Learn C?
It is one of the most popular programming languages in the world
If you know C, you will have no problem learning other popular
programming languages such as Java, Python, C++, C#, etc, as the
syntax is similar
If you know C, you will understand how computer memory works
C is very fast, compared to other programming languages,
like Java and Python
C is very versatile; it can be used in both applications and
technologies
Department of EEE,KUET
Get Started With C
Install C
If you want to run C on your own computer, you need two things:
A text editor, like Notepad, to write C code
A compiler, like GCC, to translate the C code into a language that the
computer will understand
Install IDE
An IDE (Integrated Development Environment) is used to edit AND compile
the code. Popular IDE's include Code::Blocks, Eclipse, and Visual Studio.
These are all free, and they can be used to both edit and debug C code.
Note: Web-based IDE's can work as well, but functionality is limited.
We will use Code::Blocks in our tutorial, which we believe is a good place
to start.
Department of EEE,KUET
Get Started With C
You can find the latest version of Codeblocks
at http://www.codeblocks.org/. Download
the mingw-setup.exe file, which will install the text
editor with a compiler.
Department of EEE,KUET
Get Started With C
Let's create our first C file.
Open Codeblocks and go to File > New > Empty File.
Write the following C code and save the file
as myfirstprogram.c (File > Save File as):
Department of EEE,KUET
Get Started With C
Department of EEE,KUET
Get Started With C
Then, go to Build > Build and Run to run (execute) the program
C Syntax
Department of EEE,KUET
Get Started With C
C Syntax
Line 1: #include <stdio.h> is a header file library that lets us work with input
and output functions, such as printf() (used in line 4). Header files add
functionality to C programs.
Line 2: A blank line. C ignores white space. But we use it to make the code more readable.
Line 3: Another thing that always appear in a C program is main(). This is called
a function. Any code inside its curly brackets {} will be executed.
Line 4: printf() is a function used to output/print text to the screen. In our
example, it will output "Hello World!".
Line 5: return 0 ends the main() function.
Line 6: Do not forget to add the closing curly
Department bracket } to actually end the main
of EEE,KUET
Get Started With C
C Statements
A computer program is a list of "instructions" to be "executed" by a computer.
In a programming language, these programming instructions are called statements.
The following statement "instructs" the compiler to print the text "Hello World" to the
screen:
It is important that you end the statement with a semicolon ;
If you forget the semicolon (;), an error will occur and the program will not run:
Department of EEE,KUET
Get Started With C
C Output
To output values or print text in C, you can use the printf() function:
When you are working with text, it must be wrapped inside double quotations
marks "".
Department of EEE,KUET
Get Started With C
C New Lines
Department of EEE,KUET
Get Started With C
C Comments
Comments can be used to explain code, and to make it more readable. It
can also be used to prevent execution when testing alternative code.
Comments can be singled-lined or multi-lined.
Single Line
Comment
Multiple Line
Comment
Department of EEE,KUET
Get Started With C
Thank you
Department of EEE,KUET