You are on page 1of 11

C Language Programming

Lesson 2:
C Language Overview-Part1

Prepared by:
Prof. Marienel N. Velasco

Unit
Pg. 1
I’m going to talk about

vIntroduction to C

vHow to Write and Run a C Program?

vExplaining the Code

vPractice Exercise on C

Unit
Pg. 2
Introduction to C

Ken Thompson
The developer of UNIX. • C is a general-purpose programming language developed by
B Dennis Ritchie at Bell Laboratories in 1972.
An assembler and a
language used by Ken • C was first used as the system language for the UNIX OS
Thompson to produced
initial versions of UNIX in
1970. • C evolved from B and BCPL.
BCPL
Language developed by • ANSI C or standard C, is a mature general-purpose language
Martin Richard in 1967 that is widely available on many machines and in many
as a typeless systems operating systems.
programming language.
ANSI
American National
• ANSI C, is one of the chief industrial programming
Standard Institute languages of the world, and it is commonly found in collages
C++ and universities everywhere.
An object-oriented
programming language. • ANSI C, is the foundation for C++ Unit
Pg. 3
How to write and run a C program?

Compiler STEPS:
translate source
code to object code
1. Find a Compiler for Windows user use
that is executable. (MinGW, GCC or Xcode) or IDE (Dev C++).
Operating System For Mobile phone user use Cxxdroid app.
manages machine
resources, provides
software for the 2. Type the codes in a text editor (notepad ++)
user, and act as or the Dev C++
interface between
the user and the
hardware. 3. Save your file into .c extension.

4. Compile and Run your program.


Unit
Pg. 4
Let’s get started!

APPLICATIONS USED
Program#1:
DEV C++
• This program prints on the screen the phrase “from sea to
shining C”. Below is the complete program:

• We will save this program using sea1.c as its file name.


Unit
Pg. 5
Let’s analyze the code

Function
A collection of
commands that “do • # include line causes the preprocessor to include a copy of the
something” header file stdio.h at this point in the code.
• The angle brackets around <stdio.h> indicate that the file is to be
found in the usual place, which is system dependent.

• This line tells the compiler that there is a function named main, and
that the function returns an integer.
• The keyword void indicates to the compiler that this function takes no
arguments.

• “Curly Braces” signal the beginning and end of functions and other
code blocks.

Unit
Pg. 6
Let’s analyze the code cont.

• The printf function is the standard C way of displaying output on the


screen.

• String in C is a series of characters surrounded by double quotes.


• This string is an argument to the function printf(), and it controls what
gets printed.
• \n represents a single character called newline.

• This is a statement. Many statements in C ends with a semicolon.

• The return statement returns a value from main to operating system.


• This return value is important as it can be used to tell the OS whether
our program succeeded or not.
• A return value of 0 means success.
Unit
Pg. 7
Let’s try another one!

APPLICATIONS USED
Program#2:
DEV C++ • This program prints the same output as program #1, but
the phrase will printout in three lines.

• We will save this program using sea2.c as its file name.


Unit
Pg. 8
Let’s try again!

APPLICATIONS USED
Program#3:
DEV C++ • This program is another variation of the two programs, one
that will box the phrase in a rectangle of asterisk.

• We will save this program using sea3.c as its file name.


Unit
Pg. 9
Again for the last time!

APPLICATIONS USED
Program#4:
DEV C++ • This program uses getchar() function which wait the user to
hit enter thus prevents the window from closing.

• Including the above line gives you time to see the program run.

• We will save this program using sea4.c as its file name.


Unit
Pg. 10
That’s all folks!

Thank you for listening!

Unit
Pg. 12

You might also like